【发布时间】:2020-05-12 20:05:42
【问题描述】:
DOS segment
.model small
.stack 100h
.data
array1 dw 1,4,6,3,7 ; since division 8 bit divisor require 16 bit dividend
.code
main proc
mov ax,@data
mov ds,ax
lea si,array1
mov cx,5
l1:
mov ax,[si]
mov bl,2
div bl
cmp ah,0
jne odd **if the remainder is not 0 means even**
resume:
inc si
loop l1
odd:
push ax **I am using stack**
jmp resume
mov cx,5
l2:
mov ax,[si]
mov bl,2
div bl
cmp ah,0
je even **if the remainder is 0 means even**
re:
inc si
loop l2
even:
push ax
jmp re
mov cx,5
l3:
pop dx
mov ah,2
int 21h
loop l3
main endp
end main
我相信我的算法是正确的,但我面临的问题是除法错误。我环顾四周,它发生在CX=0 时,但循环将如何工作?我很困惑。
如果有人告诉我解决方案,我将不胜感激
【问题讨论】:
-
我指定了 mov cx,4 但为什么我的循环没有在 4 处停止
-
你想用
jmp resume做什么?因为看起来这会让你回到循环中。 -
我不应该?我想我必须,因为当它跳转到标签时它会退出循环,所以我想也许我必须把它带回来进行下一次迭代
-
我尝试在不使用 jmp 的情况下运行它,但如果我在无限期之前执行生命,则循环只迭代一次我该怎么办
-
阅读代码。如果它只执行一次,它怎么会跳出循环呢?因为只有 1 个其他跳转指令 (
je l2) 必须在它发生的地方。因此,如果在执行除法之后 ah=0,它将跳过循环指令,然后我们就走了。为什么 ah 可能为零?是时候使用调试器了。特别是,看看lea ax,[si]会发生什么。