首页 > 解决方案 > 程序集 8086 - 分数无法正常工作

问题描述

我正在尝试打印此分数以创建游戏,并且分数仅打印在一侧,(当我增加分数时,它仅在一侧打印分数,另一侧保持为零。这是代码,谢谢。

proc print_score
    ; prints the points in the middle of the screen:

    ; set cursor to the middle:
    mov  dl, 170  
    mov  dh, 45   
    mov  bh, 0
    mov  ah, 02h  
    int  10h
    ; print scores, knowing it can be 0-9 (aka one char):
    mov al, [Score1]
    mov bl, 0Fh
    mov bh, 0
    mov ah, 0eh
    add al, '0'
    int 10h

    ; score1:score2
    mov al, ':'
    mov bl, 0Fh
    mov bh, 0
    mov ah, 0Eh
    int 10h

    mov al, [Score2]
    mov bl, 0Fh
    mov bh, 0
    mov ah, 0eh
    add al, '0'
    int 10h

    ret
endp print_score

    proc check_goal
    pusha
;if player 1 scores to player2 inc his score
check_goal_player1:
    cmp [ballX],315d
    ja  goal_1

    jmp check_goal_player2

goal_1:
    inc [score1]

    call refrash
    ;call player_2_scored

    jmp new_round

check_goal_player2:
    cmp [ballX],0d
    jb goal_2

    jmp no_update

goal_2:

    inc [score2]
    call refrash

    ;call player_1_scored
new_round:


    call restore_ball_possition
    jmp no_update

no_update:


    popa
    ret
endp check_goal

标签: assemblyx86-16tasm

解决方案


最令人不安的事情。

; prints the points in the middle of the screen:
; set cursor to the middle:
mov  dl, 170  
mov  dh, 45   
mov  bh, 0
mov  ah, 02h  
int  10h

BIOS.SetCursor 函数 02h 要求您传递所需光标位置的字符单元坐标。一行上的字符单元格数不能超过 255,同样的限制适用于行坐标。如果您说您的目标是屏幕中间并为列坐标传递一个值 170,那么您的屏幕将有大约 340 列!使用此 BIOS 调用是不可能的。您是否对字符坐标和像素坐标感到困惑?

例如,320x200 256 色屏幕的中间有光标坐标 (20,12),因为只有 40 列和 25 行。

第二个分数保持为零的原因

check_goal_player2:
    cmp [ballX],0d
    jb goal_2
    jmp no_update
goal_2:
    inc [score2]

当您将某个值与 0 进行比较时,您永远无法获得以下条件代码。因此,该jb goal_2指令将永远不会跳转到您想要增加score2的位置。

看到cmp [ballX], 315 ja goal_1并考虑到对称性,我的猜测是您使用的是 320 像素宽的屏幕。也许解决方案是写cmp [ballX], 4 jb goal_2


推荐阅读