Home > database >  How do I need to change assembly code that it is going to work correctly?
How do I need to change assembly code that it is going to work correctly?

Time:01-02

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      

CodePudding user response:

Here is many errors.

  1. You are use wrong instruction for increment 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.
  2. JNC and JC is used in opposite way.
  3. JMP to final cause that you are end conversion after converting first uppercase char.
  4. test for 'Z' must be proceed as cpi 'Z' 1 otherwise 'Z' character will not be converted properly.
  5. loading zero to B register is unnecessary
    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
  • Related