diff options
author | Joe Hunkeler <jhunkeler@gmail.com> | 2015-09-23 22:40:26 -0400 |
---|---|---|
committer | Joe Hunkeler <jhunkeler@gmail.com> | 2015-09-23 22:40:26 -0400 |
commit | 26b037391211c5b7283c9ecc60f956caefd29974 (patch) | |
tree | d052581b1b8b9ed1e182082c465217887390c9e1 /prog3.asm | |
parent | 59c2f332dcbf4977d6abb0fe4de47e29204996a1 (diff) | |
download | asmfun-26b037391211c5b7283c9ecc60f956caefd29974.tar.gz |
commented
Diffstat (limited to 'prog3.asm')
-rw-r--r-- | prog3.asm | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/prog3.asm b/prog3.asm new file mode 100644 index 0000000..f5c0b7e --- /dev/null +++ b/prog3.asm @@ -0,0 +1,61 @@ +;playing with the stack + +section .data +arg db 255 + +section .text +global _start + +uhh: + ; save stack + push ebp + ; create local stack + mov ebp, esp + ; create "local" variable(s) by subtracting the stack by X bytes + sub ebp, 4 + + ; first argument is 3 dwords (4 bytes * 3) in... + ; copy first argument to eax + mov eax, [ebp+12] + + ; mov eax (first arg) into local stack variable + mov [ebp-4], eax + ; clear eax + mov eax, 0 + + ; mov local variable into ebx + mov ebx, [ebp-4] + + ; reset stack pointer + ; aka, giveth back what we taketh away + add ebp, 4 + + ; restore stack + mov esp, ebp + pop ebp + ret + +_start: + ; save stack + push ebp + mov ebp, esp + + ; push value of 'arg' to the stack from ebx + mov ebx, [arg] + push ebx + ; clear ebx + mov ebx, 0 + + call uhh + + ; restore ebx (because I can.) should be value of 'arg' + pop ebx + + ; restore stack + mov esp, ebp + pop ebp + + ; exit program, ebx is return value + mov eax, 1 + int 80h + ret |