-
Notifications
You must be signed in to change notification settings - Fork 0
/
asumr.ys
53 lines (49 loc) · 1.27 KB
/
asumr.ys
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
# Execution begins at address 0
.pos 0
init:
irmovl Stack, %esp # Set up Stack pointer
irmovl Stack, %ebp # Set up base pointer
jmp Main # Execute main program
# Array of 4 elements
.align 4
array:
.long 0xd
.long 0xc0
.long 0xb00
.long 0xa000
Main:
irmovl $4, %eax
pushl %eax # Push 4
irmovl array, %edx
pushl %edx # Push array
call rSum # Sum(array, 4)
halt
# int Sum(int *Start, int Count)
rSum:
pushl %ebp
rrmovl %esp, %ebp
pushl %ebx # Save value of %ebx
mrmovl 8(%ebp), %ebx # Get Start
mrmovl 12(%ebp), %eax # Get Count
andl %eax, %eax # Test value of Count
jle L38 # If <= 0, goto zreturn
irmovl $-1, %edx
addl %edx, %eax # Count--
pushl %eax # Push Count
irmovl $4, %edx
rrmovl %ebx, %eax
addl %edx, %eax
pushl %eax # Push Start+1
call rSum # Sum(Start+1, Count-1)
mrmovl (%ebx), %edx
addl %edx, %eax # Add *Start
jmp L39 # goto done
L38:
xorl %eax,%eax # zreturn:
L39:
mrmovl -4(%ebp), %ebx # done: Restore %ebx
rrmovl %ebp, %esp # Deallocate stack frame
popl %ebp # Restore %ebp
ret
.pos 0x400
Stack: # The stack goes here