aboutsummaryrefslogtreecommitdiff
path: root/prog3.asm
blob: f5c0b7e4963267ff5f8de080eb6b0cd38361af1b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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