I am writing an assembler code to do the following:
ToUpper function converts a string of characters to uppercase, if they are not already uppercase. That is, the string already exists in memory (on the stack)

(Yes it is Homework) I am trying my best to do everything I know... whats to the right after the ';' is what is SUPPOSED to happen. I have filled in everything beyond that. and the ____ is where I am totally lost.

So far this is what I have:

[R0= tha address of the null-terminated string
R1=Current character to test
R2=Offset value between upper and lower cases (beware of sign)
R3= lowercase/uppercase compartor
R4=scratch register for use with comparisons

.orig 0x3000

LEA  R0, Data  ; Load the address of the data into R0
LEA  R2, offset ; Load the address of the lower/upper compartor into R2
LDR  R3, R2, #0 ; Load the lower/upper compartor into R2
LEA R3, offset ; Load the address of the offset, OFFSET, into R3
LDR R3, R3, #0; Load the compartor into R3

;Test for the end of the string
Test      ADD R1, R2, R3 ; Load the data element  to test into R1
            BRz Quit ; Branch on zero (null terminated string)

;Test for Lowercase

            ADD R4, R1, R3; Do the comparison to set condition code (Use R4)
            BRz Test ; Branch on Lowercase

;increment any counters as needed

INCR     ADD R0, R0, #1 ; increment address to data
             BRnzp TEST  ; unconditionally branch to the top of the loop
QUIT      RET  

LOWER  ADD R1, R1, #1 ; Convert value to uppercaes
             ___, __, __, __  ; Save the changed value back into memory
             BRnzp  INCR     ; Return to the loop

OFFSET .FILL  #-____
COMP   .FILL  #-____
DATA   .FILL  #116         ;'t'
           .FILL  #111         ;'o'
           .FILL  #109         ;'m'
           .FILL    0
9 Years
Discussion Span
Last Post by Duoas

(Thanks Ancient Dragon).

In order to check whether an ASCII number is uppercase or lowercase you must decide whether it is greater-than (for lowercase) or less-than (for uppercase) a specific number. You must figure out what that number is. Pay attention on line 22: you test for equality when you should be testing for an inequality (greater-than or less-than). Also pay attention to where you are branching.

Lines 27 and 32: If you want to unconditionally branch you could just say BR Test .

Lines 34,35: It isn't particularly clear, but I think that COMP is supposed to be the number you use to test upper/lower case, and OFFSET is supposed to be the number you add to a lowercase letter to get an uppercase letter. Like your professor noted, be careful of the sign for each one.

Lines 30..32: converting to lowercase. In your main loop, you should be obtaining a letter from the string using LDR. If you change the letter, you should save it back using an instruction like LDR but that works in the opposite direction (register to memory instead of memory to register).

Lines 36..39: You could just say .FILL 't' instead of .FILL #116 . The assembler is at least that smart...

I haven't assembled and tested this myself, but that should cover everything...

Hope this helps.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.