From 26b037391211c5b7283c9ecc60f956caefd29974 Mon Sep 17 00:00:00 2001 From: Joe Hunkeler Date: Wed, 23 Sep 2015 22:40:26 -0400 Subject: commented --- prog3.asm | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 prog3.asm (limited to 'prog3.asm') 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 -- cgit