-
Notifications
You must be signed in to change notification settings - Fork 1
/
add4095.asm
203 lines (162 loc) · 2.05 KB
/
add4095.asm
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
section .text
input:
mov eax,3
mov ebx,1
int 0x80
ret
output:
mov eax,4
mov ebx,1
int 0x80
ret
global _start
_start:
mov ecx,inpmsg
mov edx,linp
call output
mov esi,0
_input1:
mov ecx,data
mov edx,1
call input
mov cl,byte[data]
sub cl,30h
mov byte[digit1+esi],cl
add esi,1
cmp cl,-38
je stop1
jmp _input1
stop1:
sub esi,1
mov byte[digit1+esi],10
sub esi,1
mov dword[n1],esi
mov esi,0
mov ecx,inpmsg
mov edx,linp
call output
mov esi,0
_input:
mov ecx,data
mov edx,1
call input
mov cl,byte[data]
sub cl,30h
mov byte[digit2+esi],cl
add esi,1
cmp cl,-38
je proceed
jmp _input
proceed:
sub esi,1
mov byte[digit2+esi],10
sub esi,1
mov dword[n2],esi
mov ebp,dword[n1]
cmp ebp,esi
jg dig
mov dword[n3],esi
jmp checked
dig:
mov dword[n3],ebp
checked:
mov ecx,dword[n3]
add ecx,1
mov byte[digit3+ecx+1],10
_sum:
cmp ebp,-1
je alzero
jmp alstored
alzero:
add ebp,1
mov byte[digit1+ebp],0
alstored:
mov al,byte[digit1+ebp]
cmp ebp,-1
jle blzero
jmp blstored
blzero:
add esi,1
mov byte[digit2+esi],0
blstored:
mov bl,byte[digit2+esi]
add al,bl
mov bl,byte[carry]
add al,bl
mov byte[carry],0
cmp al,9
jle _storing
sub al,10
mov byte[carry],1
_storing:
mov byte[digit3+ecx],al
sub esi,1
sub ebp,1
sub ecx,1
cmp ecx,-1
jne _sum
mov esi,dword[n3]
cmp esi,50
jle _underlining
mov esi,50
_underlining:
mov ecx,underscore
mov edx,1
call output
sub esi,1
cmp esi,-1
jne _underlining
mov ecx,newline
mov edx,1
call output
mov ecx,newline
mov edx,1
call output
mov ecx,omsg
mov edx,lomsg
call output
mov esi,0
mov ebp,3
spacing:
mov ecx,space
mov edx,1
call output
sub ebp,1
cmp ebp,-1
jne spacing
_output:
mov eax,0
mov al,byte[digit3+esi]
cmp al,10
je stopoutput
add al,30h
mov byte[data],al
mov ecx,data
mov edx,1
call output
add esi,1
jmp _output
stopoutput:
mov ecx,newline
mov edx,1
call output
mov eax,1
mov ebx,0
int 0x80
section .data
carry db 0
n1 dd 0
n2 dd 0
n3 dd 0
newline db 10
data db 30h
underscore db 95
space db 32
inpmsg db "enter the digit",10
linp equ $-inpmsg
omsg db "SUM = ",10
lomsg equ $-omsg
section .bss
digit1 resb 4097
digit2 resb 4097
digit3 resb 4098