-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup.asm
More file actions
284 lines (226 loc) · 4.59 KB
/
Copy pathbackup.asm
File metadata and controls
284 lines (226 loc) · 4.59 KB
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
global _start
;externs
extern _ExitProcess@4
extern _GetStdHandle@4
extern _WriteConsoleA@20
section .data
lineBreak: dd 0xa ;constant line break
printTemp: dd "0" ;for printing digits
;msg1
msg1: dd "Hello, World"
msg1Len: equ $-msg1
;msg2
msg2: dd "hehehe"
msg2Len: equ $-msg2
temp: dd 0
numberPrintIterations: dd 0
numberPrintString: times 10 dd 0
;printing stuff
handle: dd 0
written: dd 0
section .text
;exits from the program
exit:
; ExitProcess(0)
push dword 0
call _ExitProcess@4
;prints *ecx with length edx
print:
; handle = GetStdHandle(-11)
push -11
call _GetStdHandle@4
mov [handle], eax
; WriteConsole(handle, &msg[0], length, &written, 0)
push 0
push written ;chars written
push edx ;length
push ecx ;message location
push dword [handle]
call _WriteConsoleA@20
ret
;prints a line break
printLineBreak:
mov edx, 1 ;length of 1
mov ecx, lineBreak ;\n
call print
ret
;prints the digit stored in ecx
printDigit:
mov edx, [printTemp]
add edx, ecx
mov [printTemp], edx
mov ecx, printTemp
mov edx, 1
call print
mov dword [printTemp], "0" ;clear it for next time
ret
;prints the integer stored in ecx
printInt:
; if(ecx == 0) {
; print("0");
; }
;
; temp = ecx;
;
; void recur() {
; divided = Math.floor(temp / 10);
; remainder = temp % 10;
;
; temp = divided;
;
; numberPrintString[9 - numberPrintIterations] = remainder;
;
; numberPrintIterations++;
;
; if(temp > 0) recur();
; }
;
;
; i = 0;
;
; void loop() {
; ecx = numberPrintString[i];
;
; if(foundFirstDigit == false) {
; if(digit != 0) {
; foundFirstDigit = true;
; } else {
; continue;
; }
; }
;
; print(ecx);
;
; i++;
; if(i < 10) loop();
; }
; if(ecx == 0) {
; printDigit(ecx);
; }
if1:
cmp ecx, 0
jne else1
call printDigit
ret
else1:
; temp = ecx
mov [temp], ecx
recur:
; divided = Math.floor(temp / 10)
; remainder = temp % 10
mov edx, 0 ;clear edx so division isnt weird
mov eax, [temp] ;num to divide
mov ebx, 10 ;what to divide it by
div ebx ;divide it
; temp = divided
mov [temp], eax
; numberPrintString[9 - numberPrintIterations] = remainder;
; *( &numberPrintString + 9 - numberPrintIterations ) = remainder;
;0000000000
;0000000007
;0000000037
;0000000137
mov ecx, numberPrintString+9
mov ebx, [numberPrintIterations]
sub ecx, ebx
mov [ecx], dl
; numberPrintIterations++;
mov eax, [numberPrintIterations]
inc eax
mov [numberPrintIterations], eax
; if(temp > 0) recur();
mov eax, [temp]
cmp eax, 0
jg recur
;
; i = 0;
mov ebx, 0
mov eax, 0
loop:
; ecx = numberPrintString[i];
; ecx = *( &numberPrintString + i );
mov ecx, numberPrintString
add ecx, ebx
mov ecx, [ecx]
; if(foundFirstDigit == false) {
; if(digit != 0) {
; foundFirstDigit = true;
; } else {
; continue;
; }
; }
if2: ;if(foundFirstDigit == false)
cmp al, 0
jne else2
if3: ;if(digit != 0)
cmp cl, 0
je else3
mov eax, 1
else3: ;else
cmp cl, 0
jne else2
jmp continue
else2: ;else
; print(ecx);
call printDigit
continue:
; i++;
inc ebx
; if(i < 10) loop();
cmp ebx, 10
jl loop
;
;cleaning up
mov dword [numberPrintIterations], 0
mov dword [numberPrintString+0], 0
mov dword [numberPrintString+1], 0
mov dword [numberPrintString+2], 0
mov dword [numberPrintString+3], 0
mov dword [numberPrintString+4], 0
mov dword [numberPrintString+5], 0
mov dword [numberPrintString+6], 0
mov dword [numberPrintString+7], 0
mov dword [numberPrintString+8], 0
mov dword [numberPrintString+9], 0
ret
printStuff:
mov ecx, [esp+4]
call printInt
call printLineBreak
mov ecx, [esp+8]
call printInt
call printLineBreak
mov ecx, [esp+12]
call printInt
call printLineBreak
ret
;entry
_start:
push 34
push 23
push 12
call printStuff
;print msg1
mov edx, msg1Len
mov ecx, msg1
call print
call printLineBreak
push 67
push 56
push 45
call printStuff
;print msg2
mov edx, msg2Len
mov ecx, msg2
call print
call printLineBreak
;print the num
mov ecx, 10000
call printInt
call printLineBreak
push 90
push 89
push 78
call printStuff
;exit
call exit