diff options
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 |