我有一项任务是通过以下规则更改一串数字(<=100
):nr becomes 1 if it's less tham 60 and 2 if not
。我出来了这段代码。我认为最大的挑战是打印数字......但是它给了我2个错误,指出代码标记为:
Prints macro number
mov bx, 10 ; need to divide by 10 to get the last digit
mov al, number
mov ah,0
mov cx,0
decompose:
inc cx
div bx ; reminder stored in ah
mov dl,ah
add dl,48 ; to convert to char ; <<<<< HERE
push dl
cmp al,0 ;the nr=0 means that the loop ends
jnz decompose
printloop: ;loops for as many times as counted in cx ; <<<< HERE
pop dl
mov ah,2h ; prints whatever is in dl
int 21h
loop printloop
mov dl,' ' ; the space after a number
mov ah,2h
int 21h
endm
data segment para public 'data'
sir DB 15, 78, 12, 39, 42, 88
lungime_sir EQU $-sir
data ends
;stack segment para public 'stack'
; dw stack_size dup(?)
; stack_start label word
;stack ends
code segment para public 'code'
start proc far
assume cs:code, ds:data
push ds
xor ax,ax
push ax
mov ax, data
mov ds, ax
mov si,0
mov cx,lungime_sir
next:
cmp sir[si],60
jb mic
mov sir[si],2
inc si
loop next
mic:
mov sir[si],1
inc si
cmp si,lungime_sir
jle next
mov cx,lungime_sir
mov si,0
;put values on a stack and pop them out
print:
Prints sir[si]
inc si
loop print
ret
start endp
code ends
end start
怎么了? :(
答案 0 :(得分:0)
将push dl
和pop dl
更改为push dx
和pop dx
。你不能推/弹一个字节。
div bx ; reminder stored in ah
将此除法更改为div bl
以获得AH中的余数。
将mov ah,0
放在标签分解之后,以获得成功的第二次和第三次迭代
mov cx,0
decompose:
mov ah,0
您已将 Prints 定义为不保留任何寄存器的宏。因此,以下代码将无法按预期工作。至少推/弹CX。
print:
Prints sir[si]
inc si
loop print