这是我的代码(在汇编中):如果有人可以帮助我理解为什么up&向下箭头向右移动&离开,为什么我的退出是写我deternmind代码0我会喜欢!:
> IDEAL MODEL small STACK 100h DATASEG x dw 0 xa dw 0 y dw 5 ya dw 5 z dw 1 za dw 1 color db 4 Pixels Color bgcolor db 0 ;BackGround Color > CODESEG start: mov ax, @data mov ds, ax ; Graphic mode mov ax, 13h int 10h ; Print red dot mov bh,0h mov cx,[x] mov dx,[y] > mov al,[color] mov ah,0ch int 10h amit: > ;Wait for + > mov ah,00h > int 16h > cmp ax, 0d3dh > je plus > ;Wait for - > cmp ax, 0c2dh > je minus > ; Wait for exit > cmp ax, 1071h > je exit > cmp ax, 4d00h > je right > cmp ax, 4b00h > je left1 > cmp ax, 4800h > je up1 > cmp ax, 5000h > je down1 > > exit: > mov ah, 0 > mov al, 2 > int 10h > mov ax, 4c00h > int 21h > plus: > add [x], 1 > mov cx, [x] > add [y], 1 > mov dx, [y] > mov bh, 0h > mov al,[color] > mov ah, 0ch > int 10h > add [z], 1h > add [za], 1h > jmp amit > left1: > jmp left > up1: > jmp up > down1: > jmp down > minus: > mov bh, 00h > mov al,[bgcolor] > mov ah,0ch > int 10h > sub [x], 1 > mov cx, [x] > sub [y], 1 > mov dx, [y] > sub [z], 1h > sub [za], 1h > jmp amit > right: > clsright: > mov bh, 00h > mov al,[bgcolor] > mov ah,0ch > int 10h > sub [x], 1 > mov cx, [x] > sub [y], 1 > mov dx, [y] > sub [z], 1h > cmp [z], 0h > jne clsright > add [x],1h > jmp arrowplus > left: > clsleft: > mov bh, 00h > mov al,[bgcolor] > mov ah,0ch > int 10h > sub [x], 1 > mov cx, [x] > sub [y], 1 > mov dx, [y] > sub [z], 1h > cmp [z], 0h > jne clsleft > sub [x], 1h > jmp arrowplus > up: > clsup: > mov bh, 00h > mov al,[bgcolor] > mov ah,0ch > int 10h > sub [x], 1 > mov cx, [x] > sub [y], 1 > mov dx, [y] > sub [z], 1h > cmp [z], 0h > jne clsup > sub [y], 1h > jmp arrowplus > down: > clsdown: > mov bh, 00h > mov al,[bgcolor] > mov ah,0ch > int 10h > sub [x], 1 > mov cx, [x] > sub [y], 1 > mov dx, [y] > sub [z], 1h > cmp [z], 0h > jne clsdown > add [y], 1h > jmp arrowplus > arrowplus: > add [x], 1 > mov cx, [x] > add [y], 1 > mov dx, [y] > mov bh, 0h > mov al,[color] > mov ah, 0ch > int 10h > add [z], 1h > mov [z], dx > cmp [za], dx > jne arrowplus > jmp amit END start
答案 0 :(得分:2)
我假设你正在使用VGA模式(或者可以切换到VGA)。 关于不同模式here有一个很好的解释。 简而言之,您可以切换到多种显示模式,图形或文本。 对于所有传统模式,包括VGA,您可以通过中断与显示器进行交互,但它非常笨拙。更好的选择是使用DMA(直接内存访问)。它是存储器地址的间隔,它直接映射到显示存储器。因此,通过向存储器写入一个字节,您可以更改字符/像素/像素(取决于确切的模式)。 最简单的方法是切换到VGA 16颜色,并在显示屏上写一个恒定字节。 您可以使用DMA here找到有关与监视器交互的信息,以及此模式here的调色板。
示例代码(信用到this页面):
mov ax, 13h ; AH=0 (Change video mode), AL=13h (VGA mode, 16 colors, 320x200)
int 10h ; Video BIOS interrupt, switching to VGA
mov ax, 0A000h ; The offset to video mapped memory
mov es, ax ; We load it to ES through AX, becouse immediate operation is not allowed on ES
mov ax, 0 ; 0 will put it in top left corner. To put it in top right corner load with 320, in the middle of the screen 32160 = 320*100 + 160.
mov di, ax ; load Destination Index register with ax value (the coords to put the pixel)
mov al, 7 ; Grey color.
mov cx, 64000 ; 6400 = 320 * 200 pixels
rep stosb ; paint the whole screen with grey
此模式的调色板,为了完整起见:
0 - black
1 - blue
2 - green
3 - cyan
4 - red
5 - magenta
6 - brown
7 - light gray
8 - gray
9 - light blue
10 - light green
11 - light cyan
12 - light red
13 - light magenta
14 - yellow
15 - white