1 / 17

Introduction to Assembly Programming using NASM

Introduction to Assembly Programming using NASM. Working Environment. CPU – Core 2 Duo, 64bit with 2.3 GHz clock frequency OS – Ubuntu 12.04, 64bit Other tools to be used Editor – gedit , a GNU editor Assembler – NASM ( Netwide Assembler ) LINKER – LD , a GNU linker.

vine
Download Presentation

Introduction to Assembly Programming using NASM

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. Introduction to Assembly Programming using NASM

  2. Working Environment • CPU – Core 2 Duo, 64bit with 2.3 GHz clock frequency • OS – Ubuntu 12.04, 64bit Other tools to be used • Editor – gedit, a GNU editor • Assembler – NASM (Netwide Assembler) • LINKER – LD , a GNU linker

  3. NASM - The Netwide Assembler • an 80x86 and x86-64 assembler designed for portability and modularity • supports a range of object file formats - a.out, ELF, COFF, OBJ, WIN32, WIN64, etc. • Default format - binary

  4. Ld – GNU Linker • can read, combine and write object files in many different formats such as COFF, ELF, etc. • Different formats may be linked together to produce any available kind of object file. • Elf – executable & linkable file format of object file & executable file – supported by linux

  5. Commands • To assemble nasm–f elf -o hello.o hello.nasm • To link ld –o hello hello.o • To execute - ./hello

  6. Linux System call – 32bit execution Using INT 80h • SYS_Write • Sys_Read • Sys_Exit

  7. Sys_write call - Write characters to std_out device Call with EAX = 4 ; function number EBX = 1 ; file descriptor for std_out ECX = Address of memory variable EDX = Count of bytes to display Returns Nothing

  8. Sys_Read call - To read characters from std_in devices Call with EAX = 3 ; function number EBX = 0 ; file descriptor for std-in ECX = Address of memory variable EDX = Maximum Count of bytes to display Returns In EAX Register = actual bytes read

  9. Sys_exit call - Terminate current process and transfer control back to OS Call with EAX = 1 ; function number EBX = 0 ; for zero error return code Returns Nothing

  10. Structure of assembly program section .data ; initialiseddata declaration section .bss ;uninitialized data declaration section .text global _start _start: ;code

  11. ".bss" stands for "block starting symbol".

  12. Fundamental data types b Byte 8bits 1byte w Word16bits 2 bytes d Double Word 32bits 4bytes q QuadWord64bits 8bytes

  13. NASM Syntax Vs ‘386

  14. SYS_WRITE call (64bit) Write characters to std_out device • movrax, 1 ; function number for sys_write • movrdi, 1 ; fille descriptor id for std_out ;device • movrsi, msg ; address of the variable • movrdx, msglen ; count of bytes to display • syscall ; system call

  15. SYS_READ call (64bit) sys_read call to accept the number • movrax, 0 ; function number for sys_read • movrdi, 0 ; file descriptor ID for std_in device • movrsi, arr ;address of variable used to ;store data • movrdx, 8 ; maximum bytes to read • syscall

  16. SYS_EXIT call (64bit) • movrax, 60 ; function number for sys_exit • movrdi, 0 ; return code for zero error • syscall

  17. Assignments • To accept username, display the same. Also display the length. • To accept username, display the same. Also display the length. (Using macro) • To accept 5, 32bit numbers. Store them in an array. Display the same. • To accept 5, 64bit numbers. Store them in an array. Display the same. (64bit execution) • To add 5, 32bit numbers stored in an array (using procedure)

More Related