assembly 为什么当我把它的位置转换成变量时,像素没有显示出来?组件8086 NASM

7gcisfzg  于 2023-06-06  发布在  其他
关注(0)|答案(1)|浏览(126)

我试图使一个球与大会8086 NASM使用的INT 10H和DOSBOX,在UBUNTU
就像这样:

MOV AH, 0Ch ; function to write the pixel
 MOV AL, 0Fh ; color of the pixel (set to white)
 MOV BH, 00h ; the page number (0 because its the only page im working on)
 MOV CX, 160 ; X Position on the screen
 MOV DX, 100 ; Y Position on the screen
 INT 10h

我正在使用360x200视频模式,所以像素显示在中间,这是它的工作方式:https://imgur.com/BS62ohp
当我直接将值赋给CX和DX(x和y位置)时,一旦我将其转换为初始化变量,像素显示得非常好,它消失了,屏幕完全变黑。没有bug,没有任何警告,这里它变成了变量:

segment .data
  BALL_X DW 160
  BALL_Y DW 100

segment .text
  global main

main:
  MOV AH, 0Ch
  MOV AL, 0Fh
  MOV BH, 00h
  **MOV CX, [BALL_X]**
  **MOV DX, [BALL_Y]**
  INT 10h

我试过“[BALL_X]",“word [BALL_X]",“BALL_X”。这是我把它转换成变量的时候:https://imgur.com/6jXqoaq
下面是完整的代码:

segment .data
  BALL_X DW 300
  BALL_Y DW 170

segment .text
  global main

main:
  ; setting the video mode to 360x200
  MOV AH, 00h
  MOV Al, 13h
  INT 10h
  
  ; setting the background color to Black
  MOV AH, 0Bh
  MOV BH, 00h
  MOV BL, 0h
  INT 10h

  ; the pixel code
  MOV AH, 0Ch
  MOV AL, 0Fh
  MOV BH, 00h
  MOV CX, word [BALL_X]
  MOV DX, word [BALL_Y]
  INT 10h
e0uiprwp

e0uiprwp1#

COM程序使用“微小”内存模型:文本、数据和堆栈在同一段中。代码从偏移100h开始。您需要在文件开头使用org指令指定此偏移量:

org 100h
...

但是直接绘制到视频内存比使用int 10h服务绘制要快得多:

org 100h
cpu 186 ; for one-instruction shifts

main:
    ; setting the video mode to 320x200
    mov ax, 0013h
    int 10h

    ; ES points to video memory
    mov ax, 0A000h
    mov es, ax

    ; setting the background color to Black
    ; fill memory area with 0
    xor ax, ax
    xor di, di
    mov cx, 320*200/2
    cld
    rep stosw

    ; the pixel code
    mov ax, word [BALL_Y]
    shl ax, 6                   ; ax = BALL_Y * 64
    mov bx, ax
    shl ax, 2                   ; ax = BALL_Y * 4 * 64 = BALL_Y * 256
    add bx, ax                  ; bx = BALL_Y * 64 + BALL_Y * 256 = BALL_Y * 320
    add bx, word [BALL_X]       ; bx = BALL_Y * 320 + BALL_X

    mov byte es:[bx], 0Fh       ; draw white pixel

    mov ah, 0                   ; wait for key
    int 16h
    mov ax, 0003h               ; return to 80x25 text mode
    int 10h
    mov ax, 4C00h               ; exit to DOS
    int 21h

BALL_X DW 300
BALL_Y DW 170

相关问题