CMP is a flag-setting instruction that compares two operands: one register, and either another…
CMP is a flag-setting instruction that compares two operands: one register, and either another register or an immediate value. It then updates the flags accordingly.
Example: CMP r0, #5 ; compare contents of r0 with decimal number 5
CMP r0, r1 ; compare contents of r0 with contents of r1
For unsigned operands, after executing CMP operand1, operand2:
* if C = 1 and Z = 0, then operand1 > operand2;
* if C = 0, then operand1 < operand2; and
* if Z = 1, then operand1 == operand2.
The BHI instruction is an example of a conditional operation (branch, in this case) that will branch if operand1 > operand2 after a flag setting instruction such as CMP. It does this by checking if C = 1 and Z = 0. Similarly, BLO branches if operand1 < operand2, and BEQ branches if operand1 == operand2. (Note: You do not have to use branches, you may use any conditional instruction you wish.)
Modify your code from part 1 to accommodate the following changed pseudocode:
h = 3
for j = 0 to 2
if h < 50
h = (5*h) + j
Observe that your code is to run through all 3 iterations of the for loop.