此 BIOS.WriteCharacterWithAttribute 函数 09h 不会使光标前进。为此,您可以使用 BIOS.Teletype 函数 0Eh。
由于 BIOS.WriteCharacterWithAttribute 函数 09h 使用 CX 寄存器作为重复计数,因此最好不要将 CX 用于循环计数器。下面的代码使用DI。此代码还避免使用因速度慢而臭名昭著的LOOP 指令!见Why is LOOP so slow?。
;print screen
mov di, 45
mov si, -1
mov cx, 1 ; Repetition count
mov bx, 0034h ; DisplayPage 0, Color RedOnCyan
TheLoop:
inc si
mov al, msg3[si]
mov ah, 09h
int 10h
mov ah, 0Eh
int 10h
dec di
jnz TheLoop
可以使用偏移量SI 来处理字符作为循环计数器。在一个有 45 个字符的字符串中,最后一个字符的偏移量为 44,所以这是我们在循环退出时需要达到的值:
;print screen
mov si, -1
mov cx, 1 ; Repetition count
mov bx, 0034h ; DisplayPage 0, Color RedOnCyan
TheLoop:
inc si
mov al, msg3[si]
mov ah, 09h
int 10h
mov ah, 0Eh
int 10h
cmp si, 44
jne TheLoop
进一步的改进是使用 xor si, si 的一字节短编码,将偏移量 SI 从 0 开始。这会影响我们检查循环退出的方式!
;print screen
xor si, si
mov cx, 1 ; Repetition count
mov bx, 0034h ; DisplayPage 0, Color RedOnCyan
TheLoop:
mov al, msg3[si]
mov ah, 09h
int 10h
mov ah, 0Eh
int 10h
inc si
cmp si, 45
jb TheLoop
除了使用固定的字符串长度计数,您还可以轻松地使用像零这样的字符串终止符。
;print screen
xor si, si
mov cx, 1 ; Repetition count
mov bx, 0034h ; DisplayPage 0, Color RedOnCyan
TheLoop:
mov al, msg3[si]
test al, al
jz Done
mov ah, 09h
int 10h
mov ah, 0Eh
int 10h
inc si
jmp TheLoop
Done:
...
msg3 db "-- WELCOME TO E-VOTING MANAGEMENT SYSTEM --", 0