in CO and Architecture edited by
15,037 views
35 votes
35 votes

Consider the following assembly language program for a hypothetical processor $A, B,$ and $C$ are $8-$bit registers. The meanings of various instructions are shown as comments.
$$\small \begin{array}{lll} & \text{MOV B, #0}&& \text{;} & \text{$B \leftarrow 0$} \\& \text{MOV C, #8} && \text{;}& \text{$C \leftarrow 8$} \\
\text{Z:} & \text{CMP C, #0} &&\text{;}& \text{compare C with 0} \\ 
& \text{JZ X} && \text{;}& \text{jump to X if zero flag is set}  \\
& \text{SUB C, #1} && \text{;}& \text{$C \gets C-1$}  \\ 
& \text{RRC A, #1} && \text{;}& \text{right rotate A through carry by one bit. Thus:}  \\  & \text{} && \text{;}& \text{If the initial values of A and the carry flag are $a_7\ldots a_0$ and}  \\ 
& \text{} && \text{;}& \text{$c_0$ respectively, their values after the execution of this}  \\ 
& \text{} && \text{;}& \text{instruction will be $c_0a_7\ldots a_1$ and $a_0$ respectively.}  \\ 
& \text{JC Y} && \text{;}& \text{jump to Y if carry flag is set}  \\
& \text{JMP Z} && \text{;}& \text{jump to Z}  \\
\text{Y:} & \text{ADD B, #1} && \text{;}& \text{$B \gets B+1$}  \\ 
& \text{JMP Z} && \text{;}& \text{jump to Z}  \\ 
\text{X:}& \text{} && \text{;}& \text{}  \\ \end{array}$$
If the initial value of register A is A0 the value of register B after the program execution will be

  1. the number of $0$ bits in $A_0$
  2. the number of $1$ bits in $A_0$
  3. $A_0$
  4. $8$
in CO and Architecture edited by
15.0k views

4 Comments

Thank you Sir🙏🙏
0
0
what is meant by the line if intial value  of register A is A0
1
1

Detailed Video Solution with Complete Analysis: https://youtu.be/5aC2H2u_VgI 

Both Question 48 & Q 49 are analyzed in the above lecture

1
1

3 Answers

35 votes
35 votes
Best answer

All other instructions except CMP are self explanatory.

CMP A, #K

The above instruction does A – #K, where A is a register and #K is a constant value, and if the result is positive, negative or zero, sets the flag accordingly which in turn activates the following “JZ” (Jump on Zero), “JP” (Jump on Positive), “JN” (Jump on Negative) etc. The mnemonic I used here might be different on different architecture but the working remains the same. 

So, the code here is counting the number of 1 bits in $A_0$. When a 1 is moved to carry, B is incremented.

Correct Option: B. 

edited by
by

4 Comments

8 bit register along with 1 carry bit->9 bits are rotated right 8 times.

So, In Each rotation $i$, bit $a_{i-1}$ comes into carry flag and depending on whether it's 1 or 0, CY flag is set or reset.

8 times rotation, bits $a_0-a_7$ each time come in CY flag.

After $8^{th}$ rotation, register would contain $a_6a_5a_4a_3a_2a_1a_0c_0$ and CY flag $a_7$
3
3
0
0
@Arjun sir, where a0=1 is given?
0
0
7 votes
7 votes

$Let A=7(00000111)$

$|B=0|C=8|carry=0,zero=0|zero\neq1 |C=7|00000011\ \ 1|B=1$

$|carry=0,zero=0|zero\neq1 |C=6|10000001\ \ 1|B=2$

$|carry=0,zero=0|zero\neq1 |C=5|11000000\ \ 1|B=3$

$|carry=0,zero=0|zero\neq1 |C=4|11100000\ \ 0|$

$|carry=0,zero=0|zero\neq1 |C=3|01110000\ \ 0|$

$|carry=0,zero=0|zero\neq1 |C=2|00111000\ \ 0|$

$|carry=0,zero=0|zero\neq1 |C=1|00011100\ \ 0|$

$|carry=0,zero=0|zero\neq1 |C=0|00001110\ \ 0|$

$|carry=0,zero=1|zero=1:Jump\ to\ X|$


$Ans:B$

1 vote
1 vote

Hence the option B seem to be right one ..

Answer:

Related questions