为什么这个汇编代码显示2种不同的颜色?

时间:2012-06-29 18:37:24

标签: assembly x86 nasm

我用nasm编译了这个,我正在通过bochs运行它。在我看来,2颜色变量应该使它以蓝色打印2行。它实际上打印出一个棕色和一个白色。我无法弄明白。任何帮助都非常感激

    [BITS 16]   
    [ORG 0x7C00]
    main:

    ;set video mode
    mov ah,0x00     ;function ref
    mov al,0x10     ;param - video mode
    int 0x10

    mov si, TestString
    mov bl,Color        ; Normal text attribute
    call PutStr

    mov si, TestString
    mov bl,Color2       ; Normal text attribute
    call PutStr

    jmp $

    ;-------------------------------- End of running code

    PutStr:
    ; Set up the registers for the interrupt call
    mov ah,0x0E         ; The function to display a chacter (teletype)
    mov bh,0x00         ; Page number

    .nextchar:
    lodsb               ; load string byte from SI into AL and increments SI
    or al,al            ; check for end of string
    jz .endofstring     ; jump to end if null

    int 0x10            ; Run the BIOS video interrupt 
    jmp .nextchar       ; Loop back round to the top

    .endofstring:
    ret


    Color db 0001b
    Color2 db 0001b
    TestString db 'Hello world',13,10,0,0

    times 510-($-$$) db 0       ; Fill the rest of the sector with zero's
    dw 0xAA55           ; Add the boot loader signature to the end

2 个答案:

答案 0 :(得分:1)

问题实际上是使用Color和Color2标识符。您需要“取消引用”它们以获得它们“指向”的实际值:

mov bl, [Color]

查看NASM手册中的Effective Addresses以获取更多信息。

答案 1 :(得分:1)

db分配一个字节的内存并将符号设置为该内存的地址(因此需要取消引用它)。

如果您只想要一个常量值的符号名称,请使用equ

Color equ 0001b
...
mov bl, Color
...