-1

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
IutbaZion
  • 103
  • 2
  • What's the issue with the current code? – samgak May 10 '16 at 06:55
  • it only converts to Uppercase, i cant figure out how to do what i want – IutbaZion May 10 '16 at 06:56
  • Possible duplicate of [How to access a char array and change lower case letters to upper case, and vice versa](http://stackoverflow.com/questions/35932273/how-to-access-a-char-array-and-change-lower-case-letters-to-upper-case-and-vice) – Peter Cordes May 10 '16 at 08:11

1 Answers1

2

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
AhmadWabbi
  • 2,253
  • 1
  • 20
  • 35
  • Hi, thanks for the help, but it only change to lower case, i want it mix the upper and lower case like in the example – IutbaZion May 10 '16 at 07:10
  • For example: the input would be: Hello, this is AN EXAMPLE. And i want the output to be: hELLO, THIS IS an example. – IutbaZion May 10 '16 at 07:26
  • No. The part before `dont` changes to upper case (if it is lower), and the part after it changes to lower case (if it is upper) – AhmadWabbi May 10 '16 at 07:39
  • Hi, it keeps showing me only in lower case all the text, no matter how i input my text, instead of switching the upper ones for lower ones and vice versa – IutbaZion May 10 '16 at 07:47
  • Yes. Sorry. add this line `jmp dont2` just after the `sub ...` line. – AhmadWabbi May 10 '16 at 08:00
  • 1
    @A.Wabbi If you __know__ that your answer has an error, you should edit it. Writing a sorry-comment is not enough! Please add the `jmp dont2` line where it is needed! – Fifoernik May 13 '16 at 16:17