2
這是代碼:移動用箭頭鍵的像素在組件
IDEAL
MODEL small
STACK 100h
DATASEG
; --------------------------
key db 0
locH dw 0 ;location horizontal
locV dw 0 ;location vertical
; --------------------------
CODESEG
UP_ON equ 48h
UP_OFF equ 0c8h
DOWN_ON equ 50h
DOWN_OFF equ 0d0h
LEFT_ON equ 4Bh
LEFT_OFF equ 0cBh
RIGHT_ON equ 4Dh
RIGHT_OFF equ 0cDh
ESCAPE equ 1
proc getKey
in al, 60h
mov [key],al
ret
endp getKey
start:
mov ax, @data
mov ds, ax
; --------------------------
;fullscreen
MOV AL, 13H
MOV AH, 0
INT 10H
;print red pixel
MOV AH,0Ch
MOV AL,4
MOV CX,160 ; 0 ≤ X ≤ 319
MOV DX,100 ; 0 ≤ Y ≤ 199
INT 10H
mov [locH],cx
mov [locV],dx
mainLoop:
call getKey
cmp [key],ESCAPE
jne next
jmp exit
next:
;checks if key is up
cmp [key],UP_ON
je up
;checks if key is down
cmp [key],DOWN_ON
je down
;checks if key is left
cmp [key],LEFT_ON
je left
;checks if key is right
cmp [key],RIGHT_ON
jne next2
jmp right
next2:
jmp mainLoop
; --------------------------
exit:
;exits full screen mode
MOV AL, 3H
MOV AH, 0
INT 10H
mov ax, 4c00h
int 21h
up:
;delete previous red pixel
MOV AH,0Ch
MOV AL,0
MOV CX,[locH] ; 0 ≤ X ≤ 319
MOV DX,[locV] ; 0 ≤ Y ≤ 199
INT 10H
inc [locV]
;print next red pixel
MOV AH,0Ch
MOV AL,4
MOV CX,[locH] ; 0 ≤ X ≤ 319
MOV DX,[locV] ; 0 ≤ Y ≤ 199
INT 10H
mov [locH],cx
mov [locV],dx
jmp mainLoop
down:
;delete previous red pixel
MOV AH,0Ch
MOV AL,0
MOV CX,[locH] ; 0 ≤ X ≤ 319
MOV DX,[locV] ; 0 ≤ Y ≤ 199
INT 10H
dec [locV]
;print next red pixel
MOV AH,0Ch
MOV AL,4
MOV CX,[locH] ; 0 ≤ X ≤ 319
MOV DX,[locV] ; 0 ≤ Y ≤ 199
INT 10H
mov [locH],cx
mov [locV],dx
left:
;delete previous red pixel
MOV AH,0Ch
MOV AL,0
MOV CX,[locH]; 0 ≤ X ≤ 319
MOV DX,[locV] ; 0 ≤ Y ≤ 199
INT 10H
dec [locH]
;print next red pixel
MOV AH,0Ch
MOV AL,4
MOV CX,[locH] ; 0 ≤ X ≤ 319
MOV DX,[locV] ; 0 ≤ Y ≤ 199
INT 10H
mov [locH],cx
mov [locV],dx
right:
;delete previous red pixel
MOV AH,0Ch
MOV AL,0
MOV CX,[locH]; 0 ≤ X ≤ 319
MOV DX,[locV] ; 0 ≤ Y ≤ 199
INT 10H
inc [locH]
;print next red pixel
MOV AH,0Ch
MOV AL,4
MOV CX,[locH] ; 0 ≤ X ≤ 319
MOV DX,[locV] ; 0 ≤ Y ≤ 199
INT 10H
mov [locH],cx
mov [locV],dx
jmp mainLoop
END start
似乎有兩個問題中的代碼:通過000EH字節
相對跳轉超出範圍。 - 求解
該代碼無法正常工作。當我按下一個箭頭鍵時,像素會出現異常並移動到屏幕上的其他位置。 我不知道爲什麼有問題,我嘗試了所有我能想到的事情。
感謝您的幫助!
對於第一個問題的指令'JUMPS'添加到源代碼開始。 TASM將自動改變兩個正確跳轉序列中的錯誤跳轉(一個相對和一個絕對跳轉)。 – rkhb
@rkhb對不起,我不明白。我該怎麼做? – Emil
@Emil - 超出範圍跳躍的解決方案是將'je exit'更改爲更長的序列'jne next/jmp exit/next:'。顯然TASM可以爲你做到這一點,如果你問它。 –