Francis Ngueukam
Francis Ngueukam

Reputation: 1024

ARM Assembly: How to set more than one comparing for executing a instruction?

I try to change this code into ARM without using Jump instructions :

if a == 0 || b == 1 then c:=10  else c:=20;

if d == 0 && e == 1 then f:=30  else c:=40;

I do this for the fisrt loop. But I am not sure of that. is it true?

CMP r0, #0    ; compare if a=0
CMP r1, #1    ; compare if b=0
MOVEQ r3, #10
MOVNE r3, #20

how to do the second one?

Upvotes: 0

Views: 2994

Answers (1)

Michael
Michael

Reputation: 58437

if a == 0 || b == 1 then c:=10  else c:=20;

What you want to do here is to compare one part of the condition. If that part was true, then the entire condition is true, because x OR y is true as long as at least one of x or y is true. If the first part was false, you compute the second part. So that would become:

CMP r0, #0      ; compare a with 0
CMPNE r1, #1    ; compare b with 1 if a!=0
MOVEQ r3, #10   ; a is 0, and/or b is 1 -> set c = 10
MOVNE r3, #20   ; a is not 0, and b is not 1 -> set c = 20

if d == 0 && e == 1 then f:=30  else c:=40;

Here you want to compute one part of the condition, and then compute the second part only if the first part was true. If both parts were true, then the entire condition is true, otherwise it is false:

CMP r0, #0      ; compare d with 0
CMPEQ r1, #1    ; compare e with 1 if d==0
MOVEQ r3, #30   ; d is 0, and e is 1 -> set f = 30
MOVNE r3, #40   ; d isn't 0, and/or e isn't 1 -> set f = 40

Upvotes: 2

Related Questions