输入空格字符后,输入打印有点困难。到目前为止,我有它显示输入的大写/小写但是一旦我输入一个字符串,它不会读取白色空格字符后的什么。有什么建议吗?
编辑:intel x86处理器和im使用EMU8086
org 100h
include 'emu8086.inc'
printn "Enter string to convert"
mov dx,20
call get_string
printn
mov bx,di
mov ah,0eh
mov al,[ds+bx]
cmp al, 41h
cmp al, 5Ah
jle ToLower1
cmp al, 61h
cmp al, 7ah
jle ToUpper1
ToLower1:
add al, 20h
int 10h
jmp stop1
ToUpper1:
sub al, 20h
int 10h
stop1:
inc bx
mov al,[ds+bx]
cmp al, 41h
cmp al, 5Ah
jle ToLower2
cmp al, 61h
cmp al, 7ah
jle ToUpper2
ToLower2:
add al, 20h
int 10h
jmp stop2
ToUpper2:
sub al, 20h
int 10h
stop2:
inc bx
mov al,[ds+bx]
cmp al, 41h
cmp al, 5Ah
jle ToLower3
cmp al, 61h
cmp al, 7ah
jle ToUpper3
ToLower3:
add al, 20h
int 10h
jmp stop3
ToUpper3:
sub al, 20h
int 10h
stop3:
inc bx
mov al,[ds+bx]
cmp al, 41h
cmp al, 5Ah
jle ToLower4
cmp al, 61h
cmp al, 7ah
jle ToUpper4
ToLower4:
add al, 20h
int 10h
jmp stop4
ToUpper4:
sub al, 20h
int 10h
stop4:
inc bx
mov al,[ds+bx]
cmp al, 41h
cmp al, 5Ah
jle ToLower5
cmp al, 61h
cmp al, 7ah
jle ToUpper5
ToLower5:
add al, 20h
int 10h
jmp stop5
ToUpper5:
sub al, 20h
int 10h
stop5:
printn
hlt
define_get_string
define_print_string
end
答案 0 :(得分:1)
@Oded,这些寄存器是x86,emu8086意味着8086 CPU的仿真器。
@OP:
那么你在字符代码中添加32可以使它更低吗? space
的ASCII码是32,@
符号的ASCII码是64吗?这应该告诉你你的比较在某处是错误的。
cmp al, 41h ;A
; WHAT ARE YOU MISSING HERE?
cmp al, 5Ah ;Z
jle ToLower1
cmp al, 61h ;a
; WHAT ARE YOU MISSING HERE?
cmp al, 7ah ;z
jle ToUpper1
你看到错误吗?这基本上告诉CPU当前字符是否等于或小于Z
以降低。此外,如果字符等于或小于z以使上面。
所以你拥有的是:
您需要cmp al, 41H
后的条件跳转和cmp al, 61H
但这仍然行不通,这应该有效:
cmp al, 41H
jb CheckForLower
cmp al, 5AH
ja CheckForLower
; convert to lowercase here
; Process next char
cmp al, 61H
jb NotValid
cmp al, 7AH
ja NotValid
; convert to uppercase here
; Process next char
*编辑* 我们可以将所有代码压缩成1循环:
org 100h
include 'emu8086.inc'
printn "Enter string to convert"
mov dx,20
call get_string
printn
mov bx, di
mov ah,0eh
jmp Start
NextChar:
inc bx
Start:
mov al, [ds+bx]
test al, al
jz stop5
cmp al, 20H
je PrintChar
cmp al, 41H
jb CheckLower
cmp al, 5AH
ja CheckLower
add al, 20H
int 10H
jmp NextChar
CheckLower:
cmp al, 61H
jb NextChar
cmp al, 7AH
ja NextChar
sub al, 20H
PrintChar:
int 10H
jmp NextChar
stop5:
printn
hlt
define_get_string
define_print_string
end