8086 asm递归问题

problems with 8086 asm recursion

我的 ITEM3 程序应该做的是检查在 "game of the goose" 游戏板上,地标的最终目的地是否已被占用,如果是,则返回直到找到一个空单元格。所以我想使用递归过程。 编辑:

代码如下: 在掷出骰子后推动位置标记的计算位置(或计算出单元格给予玩家的奖励)后调用该过程。

    ITEM3 PROC
    MOV BP, SP
    PUSHA
    MOV BX, [BP+2]    ;BX now contains the position to be checked.
    CMP BX, 0         ;if the placemarker is in the start cell,
    JE no_collision   ;there's no collision
    MOV DL, PLAYER    ;PLAYER is a variable containing 1, 2 or 3, pointing the player
;now some thoughts: if the player doesn't actually move (some "negative award")
;then there is no collision. So I check if the future position is already occupied, but
;I check if it is occupied by the same player, too. The following 6 labels are for this purpose
    CMP BL, P1_POS
    JE collisionp1
p2collision:
    CMP BL, P2_POS
    JE collisionp2
p3collision:
    CMP BL, P3_POS
    JE collisionp3
    JMP no_collision
collisionp1:
    CMP DL, 1
    JE p2collision
    JMP collision
collisionp2:
    CMP DL, 2
    JE p3collision
    JMP collision
collisionp3:
    CMP DL, 3
    JE no_collision
collision:             ;there's a collision. The placemarker goes back by 1 cell. Then the recursion start.
    DEC BL
    PUSH BX
    CALL ITEM3
    POP BX
    MOV [BP+2], BX
no_collision:
    POPA
    RET
ITEM3 ENDP

但是,调用过程时,地标没有任何变化。错误在哪里?谢谢

Here你可以找到完整的代码。

这是一个旧的 post 但我认为应该 post 编辑一个明确的答案。

问题是对 ITEM3 过程的调用发生了变化 BP registry,因此涉及 BP 的以下指令没有正确执行。

解决办法就是PUSH BP在调用过程之前,然后在之后弹出。

    ITEM3 PROC
    MOV BP, SP
    PUSHA
    MOV BX, [BP+2]
    CMP BX, 0
    JE no_collision
    MOV DL, PLAYER
    CMP BL, P1_POS
    JE collisionp1
p2collision:
    CMP BL, P2_POS
    JE collisionp2
p3collision:
    CMP BL, P3_POS
    JE collisionp3
    JMP no_collision
collisionp1:
    CMP DL, 1
    JE p2collision
    JMP collision
collisionp2:
    CMP DL, 2
    JE p3collision
    JMP collision
collisionp3:
    CMP DL, 3
    JE no_collision
collision:
    DEC BL
    PUSH BP                 ; HERE
    PUSH BX
    CALL ITEM3
    POP BX
    POP BP                  ; AND HERE
    MOV [BP+2], BX
no_collision:
    POPA
    RET
ITEM3 ENDP