At the moment, I have a program created that allows me to input a string and reverse it. It does what I want it to and I think it's the best way. Now I'd like to reverse the case meaning when someone enters Hello World, it would output DLORw OLLEh
I'm not sure what the best way to approach this is. I've taken a look at other solutions on the platform, but have had some difficulty in trying to make everything organized. I'd also appreciate any suggestions to improve my current code if there are any
Below is the code I have so far:
include 'emu8086.inc'
org 100h
CALL STRING_INPUT
RET
STRING_INPUT PROC
PRINT "Enter a string to reverse it: "
LEA DI, buffer ; put string inside so we can read it later
MOV DX, buffSize
CALL GET_STRING
PRINTN
MOV SI, DI
MOV CX, 0h ; character count of string
STRING_INPUT ENDP
STRING_REVERSE PROC
ReadInput:
;check for last character
MOV AX, [SI]
CMP AL, 0
JE CreateReverse
PUSH [SI] ; push inside stack
; count each character
INC SI
INC CX
JMP ReadInput
CreateReverse: ;
MOV SI, DI ; set input again
MOV AX, CX ; store length of input
BuildString:
CMP CX,0
JE PrintReversedInput
POP DX
MOV DH, 0
MOV [SI], DX ;set si to the reversed string character
INC SI
DEC CX
JMP BuildString
PrintReversedInput:
MOV SI, DI
PRINT "Reversed String: "
CALL PRINT_STRING
RET
STRING_REVERSE ENDP
buffer DB 20 DUP (?) ;set input max size for get_string
buffSize = $-buffer
DEFINE_GET_STRING
DEFINE_PRINT_STRING
END