Convert Lowercase to Uppercase in Assembly Language

How can you convert lowercase letters to uppercase in assembly language?

Assume Register R0 contains an ASCII character. Write assembly code that converts any lower-case letters (a-z) to upper case (A-Z).

Answer:

To convert a lowercase letter to uppercase in assembly code, you can use the ASCII values of the characters and a simple conditional statement.

To convert a lowercase letter to uppercase in assembly code, you can use the ASCII values of the characters and a simple conditional statement. Here's how you can achieve this:

Step-by-Step Process:
  1. Load the ASCII character from Register R0 into a temporary register, let's call it R1.
  2. Check if the value in R1 is between the ASCII values of 'a' and 'z' (97 and 122, respectively).
  3. If the condition is true, subtract 32 from the value in R1 to convert it to its uppercase equivalent.
  4. Store the resulting value back into Register R0.

Here's the code in assembly language:

LOAD R1, R0 ; Load ASCII character from Register R0 into R1 CMP R1, 'a' ; Compare R1 with the ASCII value of 'a' BLT NOT_LOWERCASE ; Branch if less than 'a' CMP R1, 'z' ; Compare R1 with the ASCII value of 'z' BGT NOT_LOWERCASE ; Branch if greater than 'z' SUB R1, 32 ; Subtract 32 from the value in R1 to convert to uppercase NOT_LOWERCASE: STORE R0, R1 ; Store the result back into Register R0

Let's go through an example to see how this code works. Suppose Register R0 initially contains the ASCII value of the lowercase letter 'g' (which is 103 in decimal).

After executing this code, Register R0 will contain the ASCII value of the uppercase letter 'G', effectively converting the lowercase letter 'g' to uppercase.

It's important to note that this code assumes Register R0 contains a valid ASCII character. If R0 contains a non-letter character, the code will not modify it.

← Ensuring safety testing automatic line leak detectors Pedicure tools understanding the role of foot files →