Translate into assembly where x, y, z are int32_t
z = (x < y) ? 6 : x ;
Front
Active users
1
All-time users
2
Favorites
0
Last updated
4 years ago
Date created
Nov 3, 2020
Ch 6
(4 cards)
Translate into assembly where x, y, z are int32_t
z = (x < y) ? 6 : x ;
LDR R0, x
LDR R1, y
CMP R0, R1 // comparing x to y by subtracting x to y
BGE EndIf // if(x >= y) goto EndIf
Then: LDR R0,=6 // replace x in R0
EndIf: STR R0,z
Translate into assembly
uint16_t a, b ;
if (a > 0 && a < 100)
b = b / 2
LDRH R0, a
CMP R0, 0
BLS EndIf // if a <= 0, goto EndIf
CMP R0, 100
BHS EndIf // if a >= 100, goto EndIf
LDRH R0, b
LDR R1, =2
UDIV R0, R0, R1
STRH R0, b
EndIf:
Translate into assembly where x,y is of int32_t
x = 0;
for (y = 1; y < 1000; y = 2*y){
x += y;
}
LDR R0, =0
STR R0, x
LDR R0, =1
STR R0, y
Top: LDR R0, y // load y into R0
CMP R0, 1000 // counter for y
BGE Done // if y >= 1000, goto Done
LDR R1, x
ADD R1, R1, R0 // add y + x and store in R1
STR R1, x // store R1 into x
LSL R0, R0, 1 // y = 2 * y
STR R0, y
B Top // branch to label Top
Done:
Translate into assembly with x,y,z as int32_t
if (x > 10)
if (x < 20)
y = 1
else
z = 0
LDR R0, x
CMP R0, 10
BLE Done // if x <= 10, goto Done
CMP R0, 20
BGE Else // if x >= 20, goto Else
Then: LDR R0, =1
STR R0, y // y = 1
B Done // branch to Done
Else: LDR R0, =0
STR R0, z // z = 0
Done: