-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.asm
172 lines (134 loc) · 2.47 KB
/
test.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
section .data
message: db "Enter numbers : "
message_length: equ $-message
section .bss
i: resw 1 ;临时计数变量
digit: resb 1 ;输入输出时的缓存数字
temp: resd 1
count: resb 1 ;输入的参数个数
address: resd 1 ;地址存放
isInsert: resb 1 ;是否插入numbers
numbers: resb 30 ;输入的参数
result: resd 30 ;生成的结果
section .text
global main
main:
;Printing prompt message
mov eax, 4
mov ebx, 1
mov ecx, message
mov edx, message_length
int 80h
JMP getInput
exit:
mov eax, 1
mov ebx, 0
int 80h
fibo: ;所求为第x项,x在dx中,值放在ebx地址中
mov eax,1
mov dword[temp],1
CMP dx,2
JNA fiboEND
mov word[i],2
fiboLoop:
mov ecx,dword[temp]
add dword[temp],eax
mov eax,ecx
inc word[i]
CMP dx,word[i]
JA fiboLoop
fiboEND:
mov eax,dword[temp]
mov dword[ebx],eax
JMP operateEND
getInput:
mov ebx,result
mov byte[isInsert],0
mov byte[count],0
mov byte[temp],0
push ebx
JMP getint
inNextJ1:
;CMP byte[digit],13
;JE getInputEND
CMP byte[isInsert],0
JE continueIN
pop ebx ;弹出result地址
movzx dx,byte[temp]
JMP fibo
operateEND:
add ebx,4
inc byte[count]
push ebx
mov byte[isInsert],0
continueIN:
CMP byte[digit],10
JE getInputEND
mov byte[temp],0
getint:
;Reding the digit
mov eax, 3
mov ebx, 0
mov ecx, digit
mov edx, 1
int 80h
;判断输入是否为数字,如果不是,如果为回车结束输入,如果为其他返回上一层
CMP byte[digit],30h
JB inNextJ1
CMP byte[digit],3Ah
JNB inNextJ1
;Calculating the number from digits
sub byte[digit], 30h
mov al, byte[temp]
mov bl, 10
mul bl
movzx bx, byte[digit]
add ax, bx
mov byte[temp], al
mov byte[isInsert],1
JMP getint
getInputEND:
JMP print
print:
mov ebx,result
outLoop:
mov eax,dword[ebx]
mov dword[temp],eax
push ebx
mov byte[i],0
outint:
mov eax,dword[temp]
mov ebx,10
mov edx,0
div ebx
mov dword[temp],eax
mov byte[digit],dl
add byte[digit],30h
movzx ax,byte[digit]
push ax
inc byte[i]
CMP dword[temp],0 ;如果temp大于0,继续除10
JA outint
output:
pop ax
mov byte[digit],al
mov eax, 4
mov ebx, 1
mov ecx, digit
mov edx, 1
int 80h
dec byte[i]
CMP byte[i],0
JA output
mov byte[digit],10
mov eax, 4
mov ebx, 1
mov ecx, digit
mov edx, 1
int 80h
pop ebx
add ebx,4
sub byte[count],1
CMP byte[count],0
JA outLoop
JMP exit