alaestor

return example ASM

Feb 25th, 2021 (edited)
275
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. addThree:
  2.         push    rbp
  3.         mov     rbp, rsp
  4.         mov     DWORD PTR [rbp-4], edi
  5.         mov     eax, DWORD PTR [rbp-4]
  6.         add     eax, 3
  7.         pop     rbp
  8.         ret
  9. main:
  10.         push    rbp
  11.         mov     rbp, rsp
  12.         sub     rsp, 16
  13.         mov     DWORD PTR [rbp-4], 0
  14.         mov     edi, 2
  15.         call    addThree
  16.         mov     DWORD PTR [rbp-4], eax
  17.         add     DWORD PTR [rbp-4], 5
  18.         mov     eax, 0
  19.         leave
  20.         ret
  21.  
  22.  
  23. ;Line 9 is where the program begins.
  24. ;Line 10, 11, and 12 are just some setup.
  25. ;Line 13 is where it initializes "n" to be zero.
  26. ;Line 14 moves the integer "2" into the register "edi".
  27. ;Line 15 calls "addThree" and the program jumps to executing from line 2.
  28. ;Lines 2 and 3 are just some setup.
  29. ;Lines 4 and 5 are just moving the value from the edi register into the eax register (the value being the integer "2").
  30. ;Line 6 then performs an addition operation (value of eax+2) which stores the resulting value in the eax register.
  31. ;Line 7 does some cleanup, and then line 8 returns. Now the program jumps down to line 16, right after the call to addThree.
  32. ;Line 16 moves the value from eax to somewhere in memory.
  33. ;Line 17 performs an addition operation which adds 5 to the value that was returned from addThree.
  34. ;Line 18 sets up the zero for the return code, then finally...
  35. ;Lines 19 and 20 is the conclusion of our program: termination.
RAW Paste Data