-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx3.asm
More file actions
105 lines (90 loc) · 1.62 KB
/
Ex3.asm
File metadata and controls
105 lines (90 loc) · 1.62 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
global _start
section .data
msg db "ngu si", 0xa
len equ $ -msg
newline db 0xa, 0xd
lennewline equ $ -newline
section .bss
root resb 10000
string resb 10000
index resb 20
section .text
_start:
input:
MOV edx, 10000
MOV ecx, root
MOV eax, 3
MOV ebx, 0
int 80h
MOV edx, 10000
MOV ecx, string
MOV eax, 3
MOV ebx, 0
int 80h
find_index:
MOV esi, root
MOV edi, 0
MOV eax, esi
jmp loop_1
loop_0:
inc esi
inc edi
cmp byte[esi], 0xa
je exit
MOV eax, esi
loop_1:
xor edx, edx
MOV edx, string
next_digit:
MOV bl, byte[eax]
cmp byte[edx], bl
je next_digit_string
inc eax
cmp byte[eax], 0xa
je exit
jmp loop_0
done:
itoa:
MOV eax, edi
; ADD eax, 48
; MOV [index], eax
lea ecx, [index]
ADD ecx, 10
MOV byte[ecx], 0
MOV ebx, 10
.next_digit:
xor edx, edx
div ebx
ADD dl, 48
dec ecx
MOV byte[ecx], dl
test eax, eax
jnz .next_digit
MOV eax, ecx
print:
MOV ecx, eax
MOV edx, 10
MOV eax, 4
MOV ebx, 1
int 80h
MOV ecx, newline
MOV edx, lennewline
MOV eax, 4
MOV ebx, 1
int 80h
jmp loop_0
next_digit_string:
inc eax
inc edx
cmp byte[edx], 0xa
je done
jmp next_digit
exit:
xor ebx, ebx
MOV eax, 1
int 80h
; MOV edx, len
; MOV ecx, msg
; MOV eax, 4
; MOV ebx, 1
; int 80h