数组和彩色文本的问题
Trouble with array and colored text
我想用这个程序给一些字母上色:
markText proc
mov ax,data
mov ds,ax
mov es,ax
mov cx, M
mov dx, 1
push dx
mov Counter, 0
mov si, 0
colorText:
mov ah,13h ;SERVICE TO DISPLAY STRING WITH COLOR.
push ax
mov al,[CharMas+si]
cbw
mov bp, ax;STRING TO DISPLAY.
inc si
pop ax
mov bh,0 ;PAGE (ALWAYS ZERO).
mov bl,Color
mov L, cx
xor cx, cx
mov cx,1 ;STRING LENGTH.
mov dl,0 ;X (SCREEN COORDINATE).
mov dh,b.ColorRepeat ;Y (SCREEN COORDINATE).
int 10h ;BIOS SCREEN SERVICES.
mov cx, L
inc ColorRepeat
loop ColorText
mov AX,4C00h
int 21h
markText endp
在我的数组 (CharMas) 中,我有类似的东西:'a'、'b'、'c'。但是只有黑色空白而不是彩色字母。我的代码有什么问题?
P.S。如果我将 arr 的索引更改为 0 或 1,它会完美运行,例如:
mov bp, offset CharMas[0]
"Write Character String" BIOS 函数需要指向 ES:BP 中的输出字符串的指针。这正是您的 "good" 代码所做的:
mov bp, offset CharMas[0]
但是,您的"bad"代码
mov al,[CharMas+si]
cbw
mov bp, ax
从字符串中加载 1 个字节到 bp
。您需要做的是将指向该字节的 指针 放入 bp
。你可以这样做:
mov bp, offset CharMas[0]; now bp is a pointer to the string
add bp, si; now bp is a pointer to a specific byte in the string
或者实际上你可以只使用一条指令来做到这一点:
lea bp, CharMas[si]; now bp is a pointer to a specific byte in the string
这里lea
是load effective address指令
mov ah,13h ;SERVICE TO DISPLAY STRING WITH COLOR.
您选择了一个较难的 BIOS 功能来输出您的彩色字符。而且你没有正确使用参数!
幸运的是,您可以使用更加用户友好的功能。
mov si, OFFSET CharMas
mov cx, 1
mov bh, 0
mov bl, color
Again:
mov ah, 09h
lodsb ;Get next character from array
int 10h ;Outputs the colored character
mov ax, 0E0Ah ;0Ah=Linefeed
int 10h ;Advances the cursor to the next line
cmp byte ptr [si], 0
jne Again
CharMas db 'a','b','c',0
我想用这个程序给一些字母上色:
markText proc
mov ax,data
mov ds,ax
mov es,ax
mov cx, M
mov dx, 1
push dx
mov Counter, 0
mov si, 0
colorText:
mov ah,13h ;SERVICE TO DISPLAY STRING WITH COLOR.
push ax
mov al,[CharMas+si]
cbw
mov bp, ax;STRING TO DISPLAY.
inc si
pop ax
mov bh,0 ;PAGE (ALWAYS ZERO).
mov bl,Color
mov L, cx
xor cx, cx
mov cx,1 ;STRING LENGTH.
mov dl,0 ;X (SCREEN COORDINATE).
mov dh,b.ColorRepeat ;Y (SCREEN COORDINATE).
int 10h ;BIOS SCREEN SERVICES.
mov cx, L
inc ColorRepeat
loop ColorText
mov AX,4C00h
int 21h
markText endp
在我的数组 (CharMas) 中,我有类似的东西:'a'、'b'、'c'。但是只有黑色空白而不是彩色字母。我的代码有什么问题?
P.S。如果我将 arr 的索引更改为 0 或 1,它会完美运行,例如:
mov bp, offset CharMas[0]
"Write Character String" BIOS 函数需要指向 ES:BP 中的输出字符串的指针。这正是您的 "good" 代码所做的:
mov bp, offset CharMas[0]
但是,您的"bad"代码
mov al,[CharMas+si]
cbw
mov bp, ax
从字符串中加载 1 个字节到 bp
。您需要做的是将指向该字节的 指针 放入 bp
。你可以这样做:
mov bp, offset CharMas[0]; now bp is a pointer to the string
add bp, si; now bp is a pointer to a specific byte in the string
或者实际上你可以只使用一条指令来做到这一点:
lea bp, CharMas[si]; now bp is a pointer to a specific byte in the string
这里lea
是load effective address指令
mov ah,13h ;SERVICE TO DISPLAY STRING WITH COLOR.
您选择了一个较难的 BIOS 功能来输出您的彩色字符。而且你没有正确使用参数!
幸运的是,您可以使用更加用户友好的功能。
mov si, OFFSET CharMas
mov cx, 1
mov bh, 0
mov bl, color
Again:
mov ah, 09h
lodsb ;Get next character from array
int 10h ;Outputs the colored character
mov ax, 0E0Ah ;0Ah=Linefeed
int 10h ;Advances the cursor to the next line
cmp byte ptr [si], 0
jne Again
CharMas db 'a','b','c',0