问题
im trying to do an Assembler program, that change the upper cases for lower cases and vice versa, all at the same time.
For example:
the input would be: Hello, this is AN EXAMPLE.
And i want
the output to be: hELLO, THIS IS an example.
all i have get is to change the string to Uppercase only, im using Assembler 8086 and Microsoft Macro Assembler (MASM) as far i know.
Thanks!
This is my code
stackseg segment para stack 'stack'
db 32 dup (' ')
stackseg ends
datasgmt segment para 'data'
show db 'write here:','$'
ln db 0
gv db 35
savedata db 35 dup(' '),'$'
rg db 1
db (' ')
db (' ')
datasgmt ends
codepos segment para 'code'
start proc far
assume cs:codepos,ss:stackseg,ds:datasgmt
push ds
xor ax,ax
push ax
mov ax,datasgmt
mov ds,ax
mov ch,0
mov cl,0
mov dh,24d
mov dl,79d
mov bh,07
mov al,0
mov ah,06
int 10h
mov ah,02
mov dh,5
mov dl,7
mov bh,0
int 10h
lea dx, show
mov ah,09h
int 21h
mov ah,02
mov dh,6
mov dl,7
mov bh,0
int 10h
lea dx,gv
mov ah,0ah
int 21h
lea si,savedata
mov bh,00
mov bl,ln
mov savedata[bx],07h
lea si, savedata
startagain: cmp byte ptr[si],61h
jb dont
cmp byte ptr[si],7ah
ja dont
sub byte ptr[si],20h
jb dont
dont:inc si
cmp byte ptr[si],0dh
jne startagain
mov ah,02
mov dh,8
mov dl,19
mov bh,0
int 10h
mov ah,09
lea dx, savedata
int 21h
lea dx,rg
mov ah,0ah
int 21h
ret
start endp
codepos ends
end start
回答1:
Change:
startagain: cmp byte ptr[si],61h
jb dont
cmp byte ptr[si],7ah
ja dont
sub byte ptr[si],20h
jb dont
dont:inc si
cmp byte ptr[si],0dh
jne startagain
with:
startagain: cmp byte ptr[si],61h
jb dont
cmp byte ptr[si],7ah
ja dont
sub byte ptr[si],20h
jmp dont2
dont:
cmp byte ptr[si],41h
jb dont2
cmp byte ptr[si],5ah
ja dont2
add byte ptr[si],20h
dont2:
inc si
cmp byte ptr[si],0dh
jne startagain
来源:https://stackoverflow.com/questions/37131194/assembler-switch-lower-case-for-upper-case-and-vice-versa