在程序中找出字符串中的元音。我卡在"输入字符串:"??为什么?即使编译器说一切都好。
程序来计算字符串中元音的编号。
;;;;;;;PROGRAM TO CHECK NO. OF VOWELS IN A STRING;;;;;
.model small
.stack 100h
.data
vowels db 'AEIOUaeiou$'
msg1 db 'Enter a string:$'
msg2 db 'The string is:$'
msg3 db 'No of vowels are:$'
string db 50 dup('$')
count db ?
.code
main proc
mov ax, @data
mov ds, ax
mov es, ax
lea dx,msg1
mov ah,09h ;for displaying enter a string
int 21h
lea di,string
cld
xor bl,bl
input:mov ah,01 ; stuck here, at taking input, why??
cmp al, 13
je endinput
stosb
inc bl
jmp input
endinput:cld
xor bh,bh
lea si,string
vowelornot: mov cx,11
lodsb
lea di,vowels
repne scasb
cmp cx, 00
je stepdown
inc bh
stepdown: dec bl
jnz vowelornot
mov ah,06 ;;;THIS FOR CLEARING SCREEN I GUESS
mov al,0 ;;;
int 10h
lea dx,msg2
mov ah,09
int 21h
mov dl, 13 ;;; NEW LINE
mov ah, 2
int 21h
mov dl, 10
mov ah, 2
int 21h
lea dx,string
mov ah, 09
int 21h
mov dl,13 ;;;NEW LINE
mov ah,2
int 21h
mov dl,10
mov ah,2
int 21h
lea dx, msg3
mov ah,09
int 21h
mov dl,13 ;;;NEW LINE
mov ah,2
int 21h
mov dl,10
mov ah,2
int 21h
mov count, bh
mov dh, count ;;; DH = VOWEL COUNT
mov ah,09
int 21h
mov ah, 4ch ;;; EXIT
int 21h
main endp
end
多个错误
input:mov ah,01 ; stuck here, at taking input, why?? cmp al, 13
在这里,您的代码缺少int 21h
指令!
input:
mov ah,01
int 21h
cmp al, 13
xor bl,bl input: stosb inc bl jmp input
您正在使用BL
来计算输入字符串中的字符数,但您编写的示例需要远远超过此字节大小寄存器可以为您提供的最大 255 个。这必须失败!
此外,您设置的缓冲区限制为 50 字节。你不可能在那里存储这么长的输入。
lea si,string vowelornot: mov cx,11 lodsb lea di,vowels repne scasb cmp cx, 00 je stepdown inc bh stepdown: dec bl jnz vowelornot
这太复杂了。只是解释零旗,根本不看CX
。您不再需要用"$"终止元音文本(使用CX=10
(。
lea si,string
vowelornot:
lodsb
mov cx,10
lea di,vowels
repne scasb
jne stepdown
inc bh ;Vowel found +1
stepdown:
dec bl
jnz vowelornot
mov ah,06 ;;;THIS FOR CLEARING SCREEN I GUESS mov al,0 ;;; int 10h
当然,函数 06h 可以清除屏幕,但您需要提供所有必需的参数。CX
的左上角,DX
的右下角和BH
的显示页面。
mov dx, 184Fh ;(79,24) If screen is 80x25
xor cx, cx ;(0,0)
mov bh, 0
mov ax, 0600h
int 10h
lea dx,string mov ah, 09 int 21h
此操作将失败,因为您没有在输入的字符串末尾放置"$"字符。
如果您打算在之后直接输出 CRLF,为什么不将其添加到缓冲区中呢?
jmp input
endinput:
mov ax, 0A0Dh <-- ADD THIS
stosw <-- ADD THIS
mov al, "$" <-- ADD THIS
stosb <-- ADD THIS
xor bh,bh
打印msg2和msg3,后跟 CRLF。你为什么不把它附加到定义中?不再需要单独输出。
msg2 db 'The string is:', 13, 10, '$'
msg3 db 'No of vowels are:', 13, 10, '$'
mov count, bh mov dh, count ;;; DH = VOWEL COUNT mov ah,09 int 21h
要输出计数,并且如果它是 0 到 9 范围内的数字,则需要将数字转换为字符。只需添加 48 或"0"。
不要使用函数 09h。它需要一个地址,你显然想使用一个字符。
mov dl, bh ;Count of vowels [0,9]
add dl, '0'
mov ah, 02h
int 21h