Advertisement
Guest User

asm

a guest
Mar 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Simple example demonstrating basic program format and layout.
  2. ; Ed Jorgensen
  3. ; July 18, 2014
  4. ; ************************************************************
  5. ; Some basic data declarations
  6. section .data
  7. ; -----
  8. ; Define constants
  9. EXIT_SUCCESS equ 0 ; successful operation
  10. SYS_exit equ 60 ; call code for terminate
  11. ; -----
  12. ; Byte (8-bit) variable declarations
  13. bVar1 db 17
  14. bVar2 db 9
  15. bResult db 0
  16. ; -----
  17. ; Word (16-bit) variable declarations
  18. wVar1 dw 17000
  19. wVar2 dw 9000
  20. wResult dw 0
  21. ; -----
  22. ; Double-word (32-bit) variable declarations
  23. dVar1 dd 17000000
  24. dVar2 dd 9000000
  25. dResult dd 0
  26. ; -----
  27. ; Quad-word (64-bit) variable declarations
  28. qVar1 dq 170000000
  29. qVar2 dq 90000000
  30. qResult dq 0
  31. ; ************************************************************
  32. ; Code Section
  33. section .text
  34. global _start
  35. _start:
  36. ; Performs a series of very basic addition operations
  37. ; to demonstrate basic program format.
  38. ; ----------
  39. ; Byte example
  40. ; bResult = bVar1 + bVar2
  41.  mov al, byte [bVar1]
  42.  add al, byte [bVar2]
  43.  mov byte [bResult], al
  44. ; ----------
  45. ; Word example
  46. ; wResult = wVar1 + wVar2
  47.  mov ax, word [wVar1]
  48.  add ax, word [wVar2]
  49.  mov word [wResult], ax
  50. ; ----------
  51. ; Double-word example
  52. ; dResult = dVar1 + dVar2
  53.  mov eax, dword [dVar1]
  54.  add eax, dword [dVar2]
  55.  mov dword [dResult], eax
  56. ; ----------
  57. ; Quad-word example
  58. ; qResult = qVar1 + qVar2
  59.  mov rax, qword [qVar1]
  60.  add rax, qword [qVar2]
  61.  mov qword [qResult], rax
  62. ; ************************************************************
  63. ; Done, terminate program.
  64. last:
  65.  mov rax, SYS_exit ; Call code for exit
  66.  mov rdi, EXIT_SUCCESS ; Exit program with success
  67.  syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement