为什么我的循环跳过条件

时间:2015-06-21 14:13:36

标签: 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],'+'  ;;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

1 个答案:

答案 0 :(得分:0)

您的代码中甚至没有循环。我不确定您要实现的目标,但您可能希望将jmp返回check_shoot或某些此类标签。只有这样,你才能在代码中使用循环。

修改:在loop check_shoot之后添加call PrintGame,您会看到比较与cx无关,这是loop期间实际修改的内容1}}。因此,每次程序循环时,所有比较都是相同的,因此您将获得相同的结果(尽管PrintGame proc应该被调用10次。)

一个建议是使用调试器并单步执行代码以查看一切是否正常工作(即您是否实际编码正确)。

相关问题