The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+4 votes
197 views

In the program below, the number of ​times the FIRST and SECOND JNZ instructions cause the control to be transferred to LOOP respectively

  MVI H, 02H
  MVI L, 05H
LOOP: DCR L ; Decrement L by 1
FIRST: JNZ LOOP
  DCR H
SECOND: JNZ LOOP
  1. 5 and 2
  2. 4 and 1
  3. 259 and 1
  4. 260 and 1
asked in CO & Architecture by Boss (5.5k points)
retagged by | 197 views

...................

1 Answer

+5 votes
Best answer
just conver above code into Loops

 L=5,H=2;
DO
{
   L=L-1
      If(L>0)
        {
             PRINT("LOOP") // prints 4 times
        }
}WHILE(L>0)

L=0; After above code.

DO
{
      H=H-1;
      IF(H>0)
     {
              print("LOOP"); // prints 1 time
                DO
                {
                         L=L-1 // 0-1 give -1 and so on ... it will run -1 to -128 and 127 to 1 total 255 times
                         If(L>0)
                       {
                                PRINT("LOOP") // 255 times printed
                        }
                 }
 }

So because of L= 4+255 = 259 times and Because of H=1 times.
answered by Veteran (26k points)
edited by
Please explain how 127 will come after value reaches to -128..
#include<stdio.h>
int main()
{
   char i=0;
   int b;
   while(1)
   {
       i=i-1;
      printf("%d \t",i);
      if (i==0)

        break;
   }
  
  /* i=-128;
   b=(((int)i)-1);
   printf("%d",b); */
   
}

 

after -128 it will become -129 in 2's complement :

that is 101111111 but our no is of only 8 bit msb 1 is truncated and it gives 127 ...
Good explanation bro.

Related questions

+1 vote
3 answers
2
+1 vote
3 answers
3


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

29,997 questions
37,681 answers
96,746 comments
35,329 users