0

一旦输入了空格字符,我的输入就很难打印出来。到目前为止,我让它显示输入的大写/小写,但是一旦我输入一个字符串,它就不会读取空格字符之后的内容。有什么建议么?

编辑:英特尔 x86 处理器和即时通讯使用 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
4

1 回答 1

1

@Oded,这些寄存器是 x86,而 emu8086 意味着 8086 CPU 的模拟器。

@OP:好吧,您将 32 添加到字符代码以使其右下角?ASCII 码space是 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
于 2012-12-02T22:02:34.737 回答