assembly 汇编x8086改变字符颜色出错

z9ju0rcb  于 2023-08-06  发布在  其他
关注(0)|答案(1)|浏览(100)

What the doctor told us to do:在我尝试运行它之后,当一个元音被打印时,它被打印了3到5次,我不知道为什么,这里是一些输出的截图。first output:second output:有人能帮助我这里了解什么是错的吗?

org 100h 

.data

sentence db 100 dup(?),0dh   ;sentence with size 100 and an 'enter' to 
end it 
vowels db 'aeiouAEIOU'  ; vowels
colors db 04h, 0Bh, 0Dh, 0Ah,  0Eh 
;         red  cyan pink green yellow 

; add your code here
.code 
mov ax,@data
mov ds,ax

; reading the input untill the user enters 'enter' 
; or untill it reachs 100 character
mov cx,100
mov si,0                                     

mov ah,1

input: 

int 21h

cmp al,0dh
jz endOfLine 

mov sentence[si],al
inc si

loop input 

jmp L1

; when the user inputs 'enter'
; it makes the next character of the sentence a 'enter'
; to make it as end of line refference

endOfLine:
mov sentence[si],0dh
                
                
; to centralize the output                    
L1:

mov dh, 12
mov dl, 30
mov bh, 0
mov ah, 2
int 10h 

; output part

mov si,0 

output:
mov dl,sentence[si]
 
cmp dl,0dh

jz stop_print

;checks for uppercase and lowercase vowel 
mov cx,5 
mov di,0

check_if_vowel:
 mov bl,vowels[di]

 cmp dl,bl
 jz is_vowel

 mov bl,vowels[di+5]
 cmp dl,bl

 jz is_vowel 
 inc di

loop check_if_vowel     

mov ah,2
int 21h 
inc si
jmp output

      
is_vowel: 
mov al,bl       
mov ah,09h
mov bl,colors[di]
int 10h 
  

mov ah,2      
mov dl,al
int 21h  

mov ah,09h
mov bh,0 
mov bl,0Fh
int 10h 

inc si
jmp output

stop_print:
ret

字符串
对我来说,这似乎是一个正确的代码,但不幸的是,它不像它似乎

cfh9epnr

cfh9epnr1#

直接的问题是服务int10/09cx中接受重复计数。对于第一个调用,您还忘记将bh归零。此外,对于彩色打印,您可能希望打印一次并移动光标。使用字符索引和已知的起始位置(不会是中间位置,所以应该使用字符串长度来计算),您可以得到如下内容:

is_vowel:
mov cx, 1 ; repeat count

mov al,bl
mov ah,09h
mov bh, 0
mov bl,[colors+di]
int 10h

inc si ; next char

mov dl, 30
add dx, si ; move cursor
mov dh, 12
mov bh, 0
mov ah, 2
int 10h

jmp output

字符串

相关问题