Explain steps also please. Thanks.
- We want to implement "if (m != n) m--;" in LEGv8.
Suppose m and n are in X20 and X21, respectively. What should we use in the blank in the following code segment?
SUB X9,X20,X21
_____ EXIT
SUBI X20,#1
EXIT:
- Suppose X20 contain the decimal value 5 and X21 contains the decimal value -5. Which condition codes are set to 1 after the following instruction is executed?
ADDS X9,X20,X21
- We want to implement "if (m != n) m--;" in LEGv8.
Suppose m and n are in X20 and X21, respectively. What should we use in the blank in the following code segment?
SUB X9,X20,X21
_____ EXIT
SUBI X20,#1
EXIT:
Part 1:
SUB X9,X20,X21
CBZ X9 EXIT
SUBI X20,#1
EXIT:
Knowledge behind above:
CBZ register, L1 if (register == 0) branch to instruction labeled L1;
CBNZ register, L1 if (register != 0) branch to instruction labeled L1;
Here, we will exit only when m==n otherwise we will do m--. So, we used here CBZ command.
Part 2:
The Z
flag is set if the result of the flag-setting
instruction is zero.
Here,
ADDS X9,X20,X21 result in X9 as 0
So, Z flag set to 1.
Knowledge behind above:
Condition codes, set from arithmetic instruction
negative (N): result had 1 in MSB
zero (Z): result was 0
overlow (V): result overflowed
carry (C): result had carryout from MSB
Part 3:
It is same as part 1. So, same answer as in part 1 can be used.
Hope it helps.
Thank you!
Get Answers For Free
Most questions answered within 1 hours.