关于汇编:8086 asm递归问题

problems with 8086 asm recursion

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

代码如下:
在掷出骰子(或已计算出单元格给予玩家的奖励)之后,按下计算出的地标位置后,将调用该过程。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
    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

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

在这里您可以找到完整的代码。


这是一个过时的帖子,但我认为应该发布明确的答案。

问题在于对ITEM3过程的调用更改了BP registry,因此以下涉及BP的指令未正确执行。

解决方案只是在调用过程之前,然后在随后弹出的PUSH BP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
    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