I have a couple exercises that are supposed to be simple. This will be my first time coding in assembly. I have always used C, so bear with me. Just looking for assurance that I am doing it correctly.
Question 1. Write a subroutine to convert a null-terminated string of lower case letters into upper case letters. The original data is in RAM, so this routine overwrites the string. A pointer to the string is passed by reference in register 0 (R0).
To convert from lower case to upper case, one must subtract by 32. [A, Z] = [65, 90] and [a, z] = [97, 122].
Here is my subroutine:
Next example I did involved a comparison of two null-terminated strings. A pointer to the first string is passed by R0 and a pointer to the other is passed by R1. If they are equal R0 is passed as 1 and 0 if they are not.
The last example I did involved writing a subroutine Average in assembly that calculated the average of three unsigned 32-bit numbers. The three paramters are passed by way of the stack. Our result is to return in R0. A typical calling sequence is as follows
What I did was as follows:
Thanks in advance!
Question 1. Write a subroutine to convert a null-terminated string of lower case letters into upper case letters. The original data is in RAM, so this routine overwrites the string. A pointer to the string is passed by reference in register 0 (R0).
To convert from lower case to upper case, one must subtract by 32. [A, Z] = [65, 90] and [a, z] = [97, 122].
Here is my subroutine:
Rich (BB code):
CMP R0, #122
BHI skip ; if(R0 > 122) then jump to next skip
CMP RO, #96
SUBHI R0, R0, #32 ; if(R0>96){R0-=32}
skip
Rich (BB code):
CMP R0, R1
BEQ skip ; if(R0==R1), jump to next skip
AND R0, R0, #0x00000000 ; R0=R0&0
BNE skip2
skip AND R0, R0, #0x00000000
ORR R0, R0, #0x00000001
skip2
Rich (BB code):
MOV R0, #200
MOV R1, #300
MOV R2, #400
PUSH (R0-R2}
BL Average
Rich (BB code):
Average POP {R0-R2} ; load values on stack into R0, R1, R2
ADD R0, R0, R1
ADD R0, R0, R2
UDIV R0, R0, #3
BX R0
Last edited: