In: Computer Science
When r0 = 24, r1 = 36 (decimal), how many instructions will the next program fetch? What is r0 when exit the loop?
L1 CMP r0, r1
SUBGT r0, r0, r1
SUBLT r1, r1, r0
BNE L1
Provide the number of instruction the next program will fetch:
Code:
L1: CMP r0, r1 ; Compare the register r0 and r1
SUBGT r0, r0, r1 ; Subtract on Greater than. if r0 > r1 then r0 = r0 - r1.
SUBLT r1, r1, r0 ; Subtract on Less than. if r0 < r1 then r1 = r1 - r0.
BNE L1 ; Branch on not equal to label L1.
• The number of instruction the next program will fetch: 8 instruction
• The value of register r0 on exiting the loop: r0 = 12
Description:
Provided r0 = 24 and r1 = 36
Fetch ⇒ L1: CMP r0, r1 (Compare 24 and 36)
Fetch ⇒ SUBGT r0, r0, r1 (not executed)
Fetch ⇒ SUBLT r1, r1, r0 (r1 = r1 - r0 = 36 - 24 = 12)
Fetch ⇒ BNE L1 (go to label L1)
Fetch ⇒ L1: CMP r0, r1 (Compare 24 and 12)
Fetch ⇒ SUBGT r0, r0, r1 (r0 = r0 - r1 = 24 - 12 = 12)
Fetch ⇒ SUBLT r1, r1, r0 (not executed)
Fetch ⇒ BNE L1 (exit)
• Total number of the fetched instruction: 8
• The value of register r0 after the execution: r0 = 12