简体   繁体   中英

Comparing R0 with R1 using assembly (Keil)

I have two values stored in R0 and R1 . I am comparing the two as follows:

MOV R3, #(R0 XOR R1)
CJNE R3,#0,NOT_EQUAL

Apparently it is not possible to use the XOR OPERATOR this way. Is there another way to compare R0 with R1 and check is they are equal or not?

Since you want to perform the XOR at runtime, you will have to use instructions to accomplish that. Unfortunately, the XRL instruction only operates on the A register, so you might have to do some rearranging. Assuming A is not available, but R3 is, you can do:

MOV R3, A ; save A to R3
MOV A, R0
XRL A, R1
XCH A, R3 ; restore A and put the result into R3
CJNE R3, #0, NOT_EQUAL

If A is available, you can use the CJNE accepting a memory operand knowing that registers are memory mapped:

MOV A, R0
CJNE A, 1, NOT_EQUAL ; 1 is the bank0 address of R1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM