Helo那里!我有一个问题,我希望有人可以帮助我:) 我需要2个宏:一个用于读取,另一个用于打印32位整数 我有一个星期一的项目,我没有想法:( 这就是我现在所拥有的:
Macro for reading:
reads macro x
local r, final
push eax
push ebx
push edx
xor eax,eax
mov ebx, 10
r:
mov ah,1h
int 21h
cmp al,0dh
je final
sub al,48
xor ah,ah
mov edx,eax
mov eax, x
mul ebx
add eax, edx
mov x,eax
jmp r
final:
pop edx
pop ebx
pop eax
endm
Macro for printing:
prints macro number
local decompose, printloop
push ax
push bx
push cx
push eax
push edx
mov bl, 10 ; need to divide by 10 to get the last digit
mov eax, number
mov cx,0
decompose:
mov ah,0
inc cx
div bl ; reminder stored in ah, quotient in al
mov number,eax
add edx,48 ; to convert to char
push edx
cmp number,0 ;the nr=0 means that the loop ends
jnz decompose
printloop: ;loops for as many times as counted before, in cx
pop edx
mov ah,2h ; prints whatever is in dl
int 21h
loop printloop
mov dl,' ' ; the space after a number
mov ah,2h
int 21h
pop edx
pop eax
pop cx
pop bx
pop ax
endm prints
答案 0 :(得分:1)
这些是宏
阅读:
reads macro x,aux
local r, final
push eax
push ebx
push edx
mov ebx, 10
r:
mov ah,1h
int 21h
cmp al,0dh
je final
cmp al,30h
jb r
cmp al,39h
ja r
sub al,48
xor ah,ah
mov aux,eax
mov eax, x
mul ebx
add eax,aux
mov x,eax
jmp r
final:
pop edx
pop ebx
endm
用于打印:
print macro number
local println, loopr
push eax
push edx
push ebx
push si
mov cx,0
mov eax,number
mov ebx, 10
loopr:
xor edx, edx
div ebx ; eax <- eax/10, edx <- eax % 10
add dl, '0' ; edx to ASCII
push dx
inc cx
cmp eax, 0
jnz loopr
println:
pop dx
mov ah, 2h
int 21h
dec cx
jnz println
mov dl, 13d ;Carriage Return
mov ah, 2h
int 21h
mov dl, 10d ;Line Feed
mov ah, 2h
int 21h
pop si
pop edx
pop eax
endm print