問題描述
循環無法打印字母 (Loop does not work to print alphabets)
我正在使用 emu8086 彙編程序,我是彙編語言的新手。我想以黑色背景的黃色打印所有 AZ 字母。我的循環不工作。它一直在運行,只顯示 B 字母。 有人可以幫我嗎?這是我的代碼:
include emu8086.inc
ORG 100h
MOV AX,0B800h
MOV DS,AX
MOV CX,26
ALPHABETS:
MOV CL,41h
ADD CX,1
MOV CH,00001110b
MOV BX,0x0000
MOV [BX],CX
loop ALPHABETS
RET
參考解法
方法 1:
Your program has 2 problems:
- You use the
CX
register for both the loop counter and the character that you want to display. - You forget to update the address in the
BX
register and so everything gets displayed on top of each other.
First solution using CX
as a loop counter:
include emu8086.inc
ORG 100h
MOV AX, 0B800h
MOV DS, AX
mov al, "A" ;First character
mov ah, 00001110b ;YellowOnBlack
mov bx, 0 ;Address in video RAM
mov cx, 26
ALPHABETS:
mov [bx], ax
inc al ;Next character
add bx, 2 ;Next address
loop ALPHABETS
RET
Second solution using the character code itself as a loop counter:
include emu8086.inc
ORG 100h
MOV AX, 0B800h
MOV DS, AX
mov al, "A" ;First character
mov ah, 00001110b ;YellowOnBlack
mov bx, 0 ;Address in video RAM
ALPHABETS:
mov [bx], ax
inc al ;Next character
add bx, 2 ;Next address
cmp al, "Z"
jbe ALPHABETS
RET
(by user7056520、Sep Roland)