I wrote a code in assembly language for the 8085 microprocessor. The code should change uppercase letters to lowercase. Maybe can you help me of finding the mistakes which I made in the code. All the text should be written in ASCII. And the first text should be taken into the HL register pair. Thank you for the help!
MOV C, A ; Move the length of the text to register C
MVI B, 0 ; Clear register B
nextchar: MOV A, M
CPI 41h ; Compare the character with 'A'
JNC notuppercase ; If the character is not 'A' or greater, skip to the next character
CPI 5Ah ; Compare the character with 'Z'
JC notuppercase ; If the character is not 'Z' or less, skip to the next character
ADI 32 ; If the character is uppercase, add 32 to it to convert it to lowercase
MOV M, A
JMP final
notuppercase: INR H ; Increment the address in HL
INR L ; Increment the address in HL
DCR C ; Decrement the character count in register C
JNZ nextchar ; If the character count is not zero, loop back and process the next character
final: HLT
Here is many errors.
HL
register. HL
is used as pair, as pointer to memory. You can't increment H register and L register separately. Use INX H
instruction which increment HL as 16 bit pointer.cpi 'Z'+1
otherwise 'Z' character will not be converted properly. MOV C, A ; Move the length of the text to register C
nextchar: MOV A, M
CPI 'A' ; Compare the character with 'A'
JC notuppercase ; If the character is below 'A', skip to the next character
CPI 'Z'+1 ; Compare the character with 'Z'
JNC notuppercase ; If the character is more then 'Z', skip to the next character
ADI 32 ; If the character is uppercase, add 32 to it to convert it to lowercase
MOV M, A
notuppercase: INX H ; Increment the address in HL
DCR C ; Decrement the character count in register C
JNZ nextchar ; If the character count is not zero, loop back and process the next character
final: HLT