1 / 16

Computer Architecture and Assembly Languages

Computer Architecture and Assembly Languages. Course’s web site: www.cs.bgu.ac.il/~arch121 Teaching Assistant: Or Peri Office Hours: Thursday 14-16 @ 37/-108 E-mail: perio at cs …. Why Assembly?. Efficiency Accessibility to system hardware Space efficiency

thanh
Download Presentation

Computer Architecture and Assembly Languages

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Architecture and Assembly Languages Course’s web site: www.cs.bgu.ac.il/~arch121 Teaching Assistant: Or Peri Office Hours: Thursday 14-16 @ 37/-108 E-mail: perio at cs…

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

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

  4. 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: http://www.realtech-vr.com/nasm/ for more information

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

  6. To assemble a file, you issue a command of the form > nasm -f <format> <filename> [-o <output>] [ -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.cmyelf.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 Running NASM

  7. For windows • Download NASM for windows from here: http://sourceforge.net/projects/nasm/ • 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.

  8. 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 userName@lace.cs.bgu.ac.il

  9. Labs Linux from home – cont. • Find an open work station here: http://www.cs.bgu.ac.il/facilities/labs.html • Type: >ssh <workstationName> • Congrats! You now have a live console as in the lab. You may compile, link and run your code

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

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

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

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

  14. Debugging • Command-prompt debugger: • gdb • To Launch: >gdb <progName> • To set breakpoints: >breakpoint <label_or_offset> • To run: >run <parameter1> <parameter2> … • Use ‘help’ to get help and master the art of debugging.

  15. 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…

  16. Makefile example 2.Sub-target list #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: rmbij/* obj/*.o 1.Main target 4.List of needed files 3.Sub-target 5.Command to invoke 7.Clean command 6.A special target

More Related