我在学校做一个太空侵略者项目,我想检查外星人是否到达了屏幕的按钮。我在代码中使用了 int 10h d(它需要屏幕上像素的颜色)并且它卡住了所有东西,我试图了解发生了什么并得出结论,行“ mov ah,0Dh
”以及“ int 10h
”行使其卡住了。有人知道我该怎么做才能让它工作吗?
(这是代码)
proc checkAliensDown
pusha
push ax
mov cx,320 ;loop counter
checkPixel:
push cx
mov bh,0h
mov cx,[x]
mov dx,140
mov ah,0Dh
int 10h
;the output of the int 10h goes into al
cmp al,10 ;check if the color of the pixel is green
jne notDown ;if not jumps to notDown
mov [lost],1 ;if it is green moves to lost 1
jmp endProc ;if it found that the pixel is green it jumps to the end of the proc
notDown:
inc [x] ;increasing x var in order to check all the pixels in the row, if one of them is green the player lost
pop cx
loop checkPixel
endProc:
pop ax
popa
ret
endp checkAliensDown
我试过推和弹出啊,但没有成功
堆栈变得不平衡!
堆栈上的随机数据被用作返回地址,这会导致程序崩溃。
当你的代码跳转到endProc时,右下方
push cx
的checkPixel仍然在堆栈上(以防绿色外星人到达屏幕底部)。只需添加一个即可将其删除:pop cx
或者,使用另一个寄存器来控制循环:
提示:
push ax
后面的pusha
没什么用。AX 已通过 保留pusha
。同样适用于pop ax
前面的popa
。无法使用字节大小的寄存器是正常的
push
。在pop
x86-16中,堆栈以字大小的块进行操作。您的checkAliensDown过程依赖于x变量预先包含 0。我建议您将其添加到过程中:
奖金
此 8086 任务的最佳解决方案是,其中
pusha
和popa
不是有效指令: