我卡在 "Enter a string:" 并且没有接受任何输入 8086 编程
I got stuck at "Enter a string:" and doesn't take any input-8086 programming
在程序中查找没有。字符串中的元音。我卡在 "Enter a string:" 了??为什么?即使编译器说一切都好。
程序来计算编号。字符串中的元音。
;;;;;;;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- sized 注册可以给你。这必须失败!
此外,您设置的缓冲区限制为 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
这太复杂了。只解释 ZeroFlag,根本不看 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
在程序中查找没有。字符串中的元音。我卡在 "Enter a string:" 了??为什么?即使编译器说一切都好。
程序来计算编号。字符串中的元音。
;;;;;;;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- sized 注册可以给你。这必须失败!
此外,您设置的缓冲区限制为 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
这太复杂了。只解释 ZeroFlag,根本不看 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