我正在练习NASM x86,我试图在屏幕上显示一个像素(红色)。我尝试以下代码:
BITS 16 ;16 bit mode FTW
start: ;define our entry point
mov ax, 07C0h
add ax, 288
mov ss, ax ;set the stack segment
mov ax, 07C0h
mov ds, ax ; set the data segment (code base)
;these lines will almost always be the same
; mov esi, my_var
; call getline
; jmp $
mov cx,100 ; align X
mov bx,100 ; align Y
call red_dot
.done:
ret
red_dot:
mov ah, 0Ch
mov al, 00h
mov bh, 00h
int 10h
ret
使用以下脚本编译好[批处理]:
nasm.exe -f bin -o TestOS.bin TestOS.asm
copy /b TestOS.bin TestOS.flp
copy TestOS.flp cdiso
mkisofs.exe -no-emul-boot -boot-load-size 4 -o TestOS.iso -b TestOS.flp cdiso/
当我在VirtualBox中运行时,我得到一个在[0,0]对齐的undercscore,没有红点?
答案 0 :(得分:3)
y坐标应位于dx
寄存器中:
mov cx,100 ; align X
mov dx,100 ; align Y
call red_dot
颜色0将是背景颜色,因此请使用其他颜色:
red_dot:
mov ah, 0Ch
mov al, 04h ;red
mov bh, 00h ;page
int 10h
ret
但首先你需要设置一个图形模式,你可以实际绘制像素。例如:
mov ah, 00h
mov al, 13h ;320x200, 256 colors
int 10h
答案 1 :(得分:0)
用“int 10h”设置像素非常慢。更快的方法是将像素的颜色直接写入帧缓冲区。图形模式13h的段地址是0A000h。用于计算像素的偏移地址=(Y_position *垂直分辨率)+ X_position
mov ax,13h
int 10h ; set the graphic mode 13h with 320x200, 256 colors
mov ax,0A000h
mov es,ax ; move the offset address of the framebuffer to the ES-segmentregister
mov cx,100 ; X_position
mov bx,100 ; Y_position (do not need to use another register on this way)
mov ax,200 ; vertical resolution of mode 13h
mul bx ; * Y_position
add ax,cx ; + X_position
mov di,ax ; move the result to an address-register
mov al,color
stosb ; set the pixel-color in AL to the framebuffer ("mov es:[di],al")
德克