Question: Keil uvision5, M3 Cortex. should be easy. Please tell me whats wrong with my code here: Im trying to get R1 to result with 0x0000000E.
Keil uvision5, M3 Cortex.
should be easy. Please tell me whats wrong with my code here:
Im trying to get R1 to result with 0x0000000E. Currently it results in 0 and i get a warning.
I'm not able/allowed to use ADC in this code. I can only use 1. LDR 2. MOV 3. CMP 4. BEQ 5. CLZ 6. ADD 7. LSL 8. BNE
To reiterate, please help me fix the code so that R1 results in 0x0000000E without using ADC. thanks, will thumbs up for good answer.


++code++
AREA name, CODE, READONLY
EXPORT __main
__main
LDR r0, = 0x7E0C0A2B ; MOV wont work
MOV r1, #0 ;r1 = 0
MOV r2,r0 ; r2 = r0
MOV r4, #0 ; r4 = 0
countone ; loop
MOVS r2, r2, LSR #1
CLZ r3, r2
ADD r1,r1,r4 ; Now Add carry bit
CMP r3, #0
BNE stop ; if r3 not equal to 0, then LSB is 0, dont perform ADD as adding 0 doesn't make sense
ADD r1, r1, #1 ; if r3 is set to 0 then LSB is 1,add 1 to r1
CMP r2, #0 ; compare r2 and 0
BNE countone ; branch if not equal to loop
stop B stop
END
1 CODE, READONLY AREA EXPORT main main LDR r0, -0x7E0COA2B ; MOV wont work MOV r1, #0 MOV r2,ro MOV r4, #0 7 10 11 Countone 12 13 : loop MOVS r2, r2, LSR #1 CLZ r3, 2 ADD r1,r1,r4 CMP r3, #0 BNE stop ADD r1, r1, #1 CMP r2, #0 BNE Countone 15 Now Add carry bit 17 18 19 20 21 22 stop B stop 23 24 : if r3 not equal to o, then LSB is 0, dont perform ADD as adding 0 doesn't make sense : if r3 is set to 0 then LSB is 1,add 1 to rl :compare r2 and 0 : branch if
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
