Question: Need help with code in uVision using ARM Assembly: Have one read - only byte called Input and one read / write byte called Output

Need help with code in uVision using ARM Assembly:
Have one read-only byte called Input and one read/write byte called Output
Each bit of Output is to be set/cleared based on the following, with 0 being the least
significant bit and 7 being the most significant bit.
o Output bit 0 is equal to Input bit 0
o Output bit 1 is the opposite of Input bit 1
o Output bit 2 is only set if Input bits 2 and/or 3 are set
o Output bit 3 is only set if both Input bits 2 and 3 are set
o Output bit 4 is only set if neither Input bits 4 or 5 are set
o Output bit 5 is only set if only one of Input bit 5 or Input bit 6 are set (it will
be cleared if both or neither are set).
o Output bit 6 is set if Input bit 6 is set and Input bit 7 is clear
o Output bit 7 is set if both Input bits 6 and 7 are clear
Have a comment on the first line stating that this is part A of the homework
Below are examples of Input arrays and their corresponding Output arrays.
Input dcb 0xB4
;Output: 0x26
Input dcb 0x00
;Output: 0x92
Input dcb 0x5A
;Output: 0x64
Input dcb 0xFF
;Output: 0x0D
The code Ive tried to implement but does not work as intended is shown below.
AREA RESET, CODE
THUMB
ENTRY
; Part A of the Homework
LDR RO,=Input ; Load Input value into RO
LDR RI,=output ; Load Output address into RI
MOV R2, #0 ; Load immediate value 0 into R2
STRB R2,[R1] ; Store zero into the Output byte
MOV R3, #1 ; Initialize loop counter with 1
Loop
TST R0, R3 ; Test Input with bit masks (1 in current position)
BEQ ClearBit ; Branch if bit is clear (clear Output bit)
ORR R2, R2, R3 ; Set Output bit if Input bit is set
B SetNextBit ; Branch to set the next bit
ClearBit
BIC R2, R2, R3 ; Clear the corresponding bit in Output
SetNextBit
LSL R3, R3, #1 ; Shift bit mask left by 1 for next bit
CMP R3, #0x80 ; Compare with 0x100(highest bit)
BNE Loop ; Branch back to Loop if not the last bit
STRB R2,[R1] ; Store R2(modified Output) back to Output address
B.
AREA Data, CODE, READWRITE
Output DCB 0 ; Replace with your actual memory address for Output
AREA MyData, DATA
Input DCB OxB4 ; Replace with your actual memory address for Input
END
 Need help with code in uVision using ARM Assembly: Have one

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!