Converting an All Upper Case String to an All Lower Case String
The concept of the code is to read each character from the memory allocation and converting one by one into it equivalent lower case character. Since the difference between a Lower Case and an Upper Case letter is equivalent to 20H, and since the Upper Case has a lower value that the Lower Case, to convert to lower case, we add the value of the Upper Case Letter to 20H. To traverse through the string, we start at index 2 up to the last. the CL holds the length of the string so that it is possible to determine how many times the process will repeat. We also use the Stack Index to hold the index of the character we are looking for, so everytime we repeat the loop, we increment the SI to proceed with the next index.
Why didn't we use the CX? It is because, the Counter Register counts backwards. Meaning, if CX=09H, it counts from 09H to 01H.
Here is the code.
Data Segment
STR1 DB 11, 12 DUP('$')
STR2 DB 0AH, 0DH, '$'
Code Segment
MOV AX, dseg
MOV DS, AX
LEA DX, STR1
MOV AH, 0AH
INT 21H
LEA DX, STR2
MOV AH, 09H
INT 21H
LEA DX, STR1
MOV SI, DX ; asign the si with DX since it already holds the address of str1
ADD SI, 02H ; increment 2H to start at the third element
MOV CL, STR1[1] ; assign CL with the length of the string
A: MOV AH, 02H
MOV DL, [SI] ; get each character based on SI
ADD DL, 20H ; convert each character
INT 21H
INC SI ; increment the index
LOOP A ; repeat the process
MOV AH, 4CH
INT 21H
0 comments:
Post a Comment