-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddNumbers.s
175 lines (174 loc) · 3.25 KB
/
AddNumbers.s
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
.data
result: .byte 0
var1: .ascii "\n\n\n\n"
var2: .ascii "\n\n\n\n"
text1: .ascii "Enter Number 1:\n"
text2: .ascii "Enter Number 2:\n"
text3: .ascii "Result:\n"
.text
.globl _start
_start:
mov $4, %eax
mov $1, %ebx
mov $text1, %ecx
mov $16, %edx
int $0x80
xor %ecx, %ecx
mov $3, %eax
mov $0, %ebx
mov $var1, %ecx
mov $4, %edx
int $0x80
xor %ecx, %ecx
mov $4, %eax
mov $1, %ebx
mov $text2, %ecx
mov $16, %edx
int $0x80
xor %ecx, %ecx
mov $3, %eax
mov $0, %ebx
mov $var2, %ecx
mov $4, %edx
int $0x80
xor %ecx, %ecx
mov var2, %eax
push %eax
shl $24, %eax
shr $24, %eax
mov %eax, %ebx
pop %eax
push %eax
shr $8, %eax
cmp $0xa0a0a, %eax
jne no_zeros_added_1
mov %ebx, %edx
mov $0x30, %ebx
mov $0x30, %ecx
pop %eax
jmp continue
no_zeros_added_1:
shl $24, %eax
shr $24, %eax
mov %eax, %ecx
pop %eax
push %eax
shr $16, %eax
cmp $0xa0a, %eax
jne no_zeros_added_2
mov %ecx, %edx
mov %ebx, %ecx
mov $0x30, %ebx
pop %eax
jmp continue
no_zeros_added_2:
shl $24, %eax
shr $24, %eax
mov %eax, %edx
pop %eax
continue:
xor %eax, %eax
sub $0x30, %ebx
sub $0x30, %ecx
sub $0x30, %edx
push %ebx
push %ecx
push %edx
xor %ebx, %ebx
xor %ecx, %ecx
xor %edx, %edx
mov var1, %eax
push %eax
shr $8, %eax
cmp $0xa0a0a, %eax
jne no_zeros_added_3
pop %eax
shl $16, %eax
shr $16, %eax
mov %eax, %edx
xor %eax, %eax
mov %edx, %eax
shl $8, %eax
mov $0x30, %al
shl $8, %eax
mov $0x30, %al
pop %edx
pop %ecx
pop %ebx
jmp start_maths
no_zeros_added_3:
pop %eax
push %eax
shr $16, %eax
cmp $0xa0a, %eax
jne no_zeros_added_4
pop %eax
shl $8, %eax
shr $8, %eax
mov %eax, %edx
xor %eax, %eax
mov %edx, %eax
shl $8, %eax
mov $0x30, %al
pop %edx
pop %ecx
pop %ebx
jmp start_maths
no_zeros_added_4:
pop %eax
pop %edx
pop %ecx
pop %ebx
start_maths:
cmp $0, %edx
jne add_1
cmp $0, %ecx
jne add_10
cmp $0, %ebx
jne add_100
jmp finish
add_1:
add $0x010000, %eax
dec %edx
push %eax
shr $16, %eax
cmp $0x3A, %al
pop %eax
je overflow_1
jmp start_maths
add_10:
add $0x0100, %eax
dec %ecx
push %eax
shr $8, %eax
cmp $0x3A, %al
pop %eax
je overflow_10
jmp start_maths
add_100:
add $0x01, %eax
dec %ebx
jmp start_maths
overflow_1:
sub $0x0A0000, %eax
add $0x0100, %eax
jmp start_maths
overflow_10:
sub $0x0A00, %eax
add $0x01, %eax
jmp start_maths
finish:
mov %eax, result(,1)
mov $4, %eax
mov $1, %ebx
mov $text3, %ecx
mov $8, %edx
int $0x80
mov $4, %eax
mov $1, %ebx
mov $result, %ecx
mov $3, %edx
int $0x80
mov $1, %eax
xor %ebx, %ebx
int $0x80