summaryrefslogtreecommitdiff
path: root/ecomp-c/tests/procedure_scoping.easm
blob: 8f6dc6fdfb4cf78c03c84d6b8c31bcb71ccfca09 (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
format binary
use32
org $1000000
jmp __global_0
; CONST N -> integer, 1
; CONST M -> integer, 3
; DECL x -> integer, 1
; DECL y -> array 3 of integer, array 3 of integer = { ... }
; PROC A
__global_A:
push ebp
push esp
pop ebp
; CONST N -> integer, 2
; DECL x -> array 2 of integer, array 2 of integer = { ... }
; DECL y -> array 3 of integer, array 3 of integer = { ... }
; DECL z -> integer, 0
mov eax, 4
sub esp, eax
; LET x[2 ] <- 3 
mov eax, 2
push eax
pop eax
mov ebx, 4
mul ebx
push eax
mov eax, x
pop ebx
add eax, ebx
push eax
mov eax, 3
push eax
pop eax
pop ebx
mov [ebx], eax
; LET z <- 4 
mov eax, 4
push eax
push ebp
pop ebx
mov eax, 4
sub ebx, eax
pop eax
mov [ebx], eax
mov eax, 4
add esp, eax
pop ebp
ret
; PROC B
__global_B:
push ebp
push esp
pop ebp
; LET x <- 1 
mov eax, 1
push eax
pop eax
mov [x], eax
pop ebp
ret
__global_0:
; LET y[0 ] <- 7 
mov eax, 0
push eax
pop eax
mov ebx, 4
mul ebx
push eax
mov eax, y
pop ebx
add eax, ebx
push eax
mov eax, 7
push eax
pop eax
pop ebx
mov [ebx], eax
call __global_A
call __global_B
hlt
y: dd $00000000
dd $00000000
dd $00000000
x: dd $00000001