Assembly 为什么我的循环跳过条件
这是我的代码: placeStart是我的播放机的第一个位置,cmp条件执行一次而不是重复Assembly 为什么我的循环跳过条件,assembly,Assembly,这是我的代码: placeStart是我的播放机的第一个位置,cmp条件执行一次而不是重复 proc Shoot mov bx,[placeStart] mov dx,offset Game add bx,dx ;; Moving to bx the position of the character mov cx,10 check_shoot: cmp [byte ptr bx-NumCols],'+' ;;checki
proc Shoot
mov bx,[placeStart]
mov dx,offset Game
add bx,dx
;; Moving to bx the position of the character
mov cx,10
check_shoot:
cmp [byte ptr bx-NumCols],'+' ;;checking if the shoot will override the plus
je exit
sub bx,NumCols
mov [byte ptr bx],'*'
cmp [byte ptr bx+NumCols],'*'
je first_shoot
jmp finish_loop
first_shoot:
mov [byte ptr bx+NumCols],' '
finish_loop:
call PrintGame
loop check_shoot
您的代码中甚至没有循环。我不确定您想要实现什么目标,但您可能希望将
jmp
返回到check_shot
或类似标签。只有这样,代码中才会有一个循环
编辑:在调用PrintGame
之后添加循环检查
,您将看到比较与cx
无关,cx是在循环过程中实际修改的内容。因此,每次程序循环时,您的所有比较都是相同的,因此您将得到相同的结果(尽管PrintGame
proc应该被调用10次)
一个建议是使用调试器,一步一步地检查代码,看看是否一切正常(即,您是否真正正确地编写了代码)。调用PrintGame后,有一个重要的循环检查(以获得正确的答案)。我根据这一点编辑了这个问题(等待同行评审)。我还编辑了我的答案,大意是什么是NumCols
?用eq
定义的立即常数,或变量(db
/dw
/dd
)?您应该发布复制问题所需的完整、最少的代码。