Computer Architecture and Assembly Languages Course’s web site: Teaching Assistant: Or Peri Office Hours: Thursday 37/-108.

Slides:



Advertisements
Similar presentations
Assembly 01. Outline Binary vs. Text Files Compiler vs. Assembler Mnemonic Assembly Process Development Process Debugging Example 1 this analogy will.
Advertisements

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 The CS-220 Development Environment.
Memory Image of Running Programs Executable file on disk, running program in memory, activation record, C-style and Pascal-style parameter passing.
Practical Session 3. The Stack The stack is an area in memory that its purpose is to provide a space for temporary storage of addresses and data items.
1 Homework Reading –PAL, pp , Machine Projects –Finish mp2warmup Questions? –Start mp2 as soon as possible Labs –Continue labs with your.
Position Independent Code self sufficiency of combining program.
Practical Session 8 Computer Architecture and Assembly Language.
C Prog. To Object Code text text binary binary Code in files p1.c p2.c
Intro. to Game Programming Want to program a game?
1 Agenda Administration Background Our first C program Working environment Exercise Memory and Variables.
Chapter 2: Operating-System Structures. 2.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 2: Operating-System Structures Operating.
Practical Session 4. Labels Definition - advanced label: (pseudo) instruction operands ; comment valid characters in labels are: letters, numbers, _,
Developing C/C++ applications with the Eclipse CDT David Gallardo.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
Programming With C.
Lecture-1 Compilation process
System Programming - LAB 1 Programming Environments.
Recitation 6 – 2/26/01 Outline Linking Exam Review –Topics Covered –Your Questions Shaheen Gandhi Office Hours: Wednesday.
N from what language did C++ originate? n what’s input, output device? n what’s main memory, memory location, memory address? n what’s a program, data?
Computer Architecture and Assembly Language. Byte structure : a byte has 8 bits MSB (Most Significant Bit) LSB (Least Significant Bit) Data Representation.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 3 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Lec 4Systems Architecture1 Systems Architecture Lecture 4: Compilers, Assemblers, Linkers & Loaders Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan.
Practical Session 4 Computer Architecture and Assembly Language.
1 CS503: Operating Systems Spring 2014 Part 0: Program Structure Dongyan Xu Department of Computer Science Purdue University.
The Development Process Compilation. Compilation - Dr. Craig A. Struble 2 Programming Process Problem Solving Phase We will spend significant time on.
CS429 Computer Architecture Topics Simple C program Basic structure, functions, separate files Compilation Phases, options Assembler GNU style, byte ordering,
Computer Architecture and Assembly Language
Practical Session 4. GNU Linker Links object files together Used as the last step in the compilation We will use ld to link together compiled assembly.
1 Linking. 2 Outline What is linking and why linking Complier driver Static linking Symbols & Symbol Table Suggested reading: 7.1~7.5.
CS252: Systems Programming Ninghui Li Based on Slides by Gustavo Rodriguez-Rivera Topic 2: Program Structure and Using GDB.
Practical Session 8. Position Independent Code- self sufficiency of combining program Position Independent Code (PIC) program has everything it needs.
Linking I Topics Assembly and symbol resolution Static linking Systems I.
OUTLINE 2 Pre-requisite Bomb! Pre-requisite Bomb! 3.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Sung-Dong Kim Dept. of Computer Engineering, Hansung University Chapter 3 Programming Tools.
NASM ASSEMBLER & COMPILE WITH GCC 어셈러브 refered to ‘PC Assembly Language’ by Paul A. Carter
1 CS 192 Lecture 4 Winter 2003 December 8-9, 2003 Dr. Shafay Shamail.
Practical Session 3.
Lecture 3 Translation.
Precept I : Lab Environment, Unix, Bash, Emacs
Computer System Laboratory
Computer Architecture and Assembly Language
Static and dynamic analysis of binaries
Computer Architecture and Assembly Language
Microprocessor and Assembly Language
Debugging with gdb gdb is the GNU debugger on our CS machines.
Homework Reading Machine Projects Labs PAL, pp ,
Computer Architecture and Assembly Language
Writing a Useful Program With NASM
Program Execution in Linux
Computer Architecture and Assembly Language
C Prog. To Object Code text text binary binary Code in files p1.c p2.c
CSCE 206 Lab Structured Programming in C
Assembly Language Programming II: C Compiler Calling Sequences
Getting Started: Developing Code with Cloud9
Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan
University of Gujrat Department of Computer Science
Program Execution in Linux
Appendix F C Programming Environment on UNIX Systems
Video Notes.
Preparation for Assignment 2
CSCE 206 Lab Structured Programming in C
Warmup Write a function to add two integer parameters and return the result.
System Programming By Prof.Naveed Zishan.
Debugging.
Computer Architecture and System Programming Laboratory
Computer Architecture and Assembly Language
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Presentation transcript:

Computer Architecture and Assembly Languages Course’s web site: Teaching Assistant: Or Peri Office Hours: Thursday 37/ perio at cs…

Why Assembly? Efficiency Accessibility to system hardware Space efficiency Discovering “the missing link” ( good education )

From code to Process High-level language code (C,C++…) Assembly code Binary Object file(s) Executable (app) A running process compiler Linker Loader

NASM An Intel 80x86 assembly compiler Natively for Linux – Your assignments will be checked on labs’ linux Available also for Windows – You may start here: vr.com/nasm/ for more informationhttp:// vr.com/nasm/

How to? To write a code all you need is a text editor. Assembly files ends with.s Use NASM to compile those into.obj files Use a linker (ld or C’s gcc) to link compiled files into runnable files. Execute

Running NASM To assemble a file, you issue a command of the form > nasm -f [-o ] [ -l listing] Example: > nasm -f elf mytry.s -o myelf.o It would create myelf.o file that has elf format (executable and linkable format). We use main.c file (that is written in C language) to start our program, and sometimes also for input / output from a user. So to compile main.c with our assembly file we should execute the following command: > gcc –m32 main.c myelf.o -o myexe.out The -m32 option is being used to comply with 32-bit environment It would create executable file myexe.out. In order to run it you should write its name on the command line: > myexe.out

For windows Download NASM for windows from here: Install it and add the path for nasm.exe to the PATH variable. NOTE! Your code will be tested under linux, you must check compatibility before submission.

Labs Linux from home (win) Download putty Connect to one of the university’s servers (lace/tapuz) From your home linux you may simply open a terminal and type: >ssh

Labs Linux from home – cont. Find an open work station here: Type: >ssh Congrats! You now have a live console as in the lab. You may compile, link and run your code

hellowWorld.c #include Int main(){ printf(“hellow world!\n”); }

hellowWorld.s extern printf global main section.text hello: db "hellow world!",10,0 main: push hello call printf pop eax ret

printArgCnt.c #include int main(int argc, char* argv[]){ printArgc(argc); } An example program (mixed c and assembly code). This one will print the amount of parameters received from invoker

printArgCnt.s extern printf global printArgc section.text toPrint: db "%d",10,0 printArgc: push ebp mov ebp,esp mov eax, [ebp+8] dec eax push eax push toPrint call printf add esp,8 mov esp,ebp pop ebp ret

Debugging Command-prompt debugger: – gdb To Launch: >gdb To set breakpoints: >breakpoint To run: >run … – Use ‘help’ to get help and master the art of debugging.

Debugging Using Eclipse: – Install cdt plugin (labs have it installed) – Project has to be a C project – Build preferences has to be altered so that auto makefile generation is off. – You need to write your own makefile – Upon debugging, user can view the registers, memory addresses as requested etc…

Makefile example #macro examples: ASM:=nasm ASM_FLAGS:=-f elf -g all: example1 example1:obj/neededFile1.o obj/neededFile2.o gcc -m32 obj/neededFile1.o obj/neededFile2.o -o bin/binaryFileName neededFile1.o : asmFile1.s $(ASM) $(ASM_FLAGS) asmFile1.s -o neededFile1.o neededFile2.o : asmFile2.s $(ASM) $(ASM_FLAGS) asmFile2.s -o neededFile2.o clean: rm bij/* obj/*.o 1.Main target 2.Sub-target list 3.Sub-target 4.List of needed files 5.Command to invoke 6.A special target 7.Clean command

Basic Terminology Basic data unit - 1/0 (true/false)Bit 8 bitsByte 16 bits2 BytesWord 32 bits2 Words (4-byte)Dword Byte structure : MSB (most significant bit) LSB (least significant bit)