Inverting letter cases refers to converting uppercase letters to lowercase and vice versa. We can achieve this by changing the ASCII code of each character. We need to add 32 to ASCII code of uppercase letter to convert it to a lowercase and if the character is a small letter, subtract 32 from its ASCII code to convert it to capital letter.
Assembly Program to input a capital letter from user and convert it into small letter (uppercase to lowercase)
dosseg ; Tells the assembler to use the DOS segment addressing mode
.model small ; Sets the memory model to "small"
.stack 100h ; Sets the size of the program stack to 256 bytes (100h in hexadecimal)
.data ; Indicates the start of the data segment
.code ; Indicates the start of the code segment
main proc ; Starts the "main" procedure
mov ah, 1 ; Move the value 1 into the AH register (AH is used for input/output operations)
int 21h ; Call the DOS interrupt 21h, which prints the character in the AL register (ASCII code 1 is "SOH")
mov dl, al ; Move the value in the AL register (which was set by the interrupt) into the DL register (which is used for input/output operations)
add dl, 32 ; Add 32 to the value in the DL register (which converts a lowercase letter to uppercase in ASCII)
mov ah, 2 ; Move the value 2 into the AH register (which indicates the "print character" function)
int 21h ; Call the DOS interrupt 21h, which prints the character in the DL register (which is now the uppercase version of the character printed earlier)
mov ah, 4ch ; Move the value 4Ch into the AH register (which indicates the "terminate with return code" function)
int 21h ; Call the DOS interrupt 21h, which terminates the program with the return code in the AL register
main endp ; Ends the "main" procedure
end main ; Indicates the end of the program
Assembly Program to input a small letter from user and convert it into capital letter (lowercase to uppercase)
dosseg
.model small
.stack 100h
.data
.code
main proc
mov ah, 1
int 21h
mov dl, al
sub dl, 32 ; Subtract 32 from the value in the DL register (which converts an uppercase letter to lowercase in ASCII)
mov ah, 2
int 21h
mov ah, 4ch
int 21h
main endp
end main
