Skip to content
Related Articles

Related Articles

GATE | GATE CS 1999 | Question 65

View Discussion
Improve Article
Save Article
  • Last Updated : 10 Oct, 2017
View Discussion
Improve Article
Save Article

[5 Marks question]
Consider the following program fragment in the assembly language of a certain hypothetical processor. The processor has three general purpose registers R1, R2 and R3. The meanings of the instructions are shown by comments (starting with ; ) after the instructions.

X:  CMP R1, 0   ;Compare R1 and 0, set flags appropriately in status register
    JZ  Z       ;Jump if zero to target Z
    MOV R2, R1  ;Copy contents of R1 to R2
    SHR R1      ;Shift right R1 by 1 bit
    SHL R1      ;Shift left R1 by 1 bit
    CMP R2, R1  ;Compare R2 and R1 and set flag in status register
    JZ  Y       ;Jump if zero to target Y
    INC R3      ;Increment R3 by 1;
Y:  SHR R1      ;Shift right R1 by 1 bit
    JMP X       ;Jump to target X
Z:...

a. Initially R1, R2 and R3 contain the value 5, 0 and 0 respectively. What are the final values of R1 and R3 when control reaches Z?
b. In general, if R1, R2 and R3 initially contain the values n, 0 and 0 respectively. What is the final value of R3 when control reaches Z?


Answer:

Explanation:

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!