The Gateway to Computer Science Excellence
+4 votes
2.4k views

How many number of times the instruction sequence below will loop before coming out of the loop?

        MOV AL, 00H

 A1:  INC AL

        JNZ A1

  1. 1
  2. 255
  3. 256
  4. Will not come out of the loop.
in CO and Architecture by Boss (30.9k points) | 2.4k views

4 Answers

+8 votes
Best answer
256. AL is incremented 1 in each iteration and after 256 increments, it becomes 0 again as AL register is 8 bits.

When AL=0000 0000 and CY=1,  JNZ will be false. JNZ means jump when previous operation set Zero flag and not jump when previous operation did not set zero flag. So control comes out of loop after 256 iterations.
by Active (1.5k points)
selected by
0
  • The jnz instruction is a conditional jump that follows a test.
  • jnz is commonly used to explicitly test for something not being equal to zero. if it is ZERO it loop exits.
  • jumps to the specified location.

***********************************************

solutions:////////

at the stats AL is 0000 0000H

after 1st increment AL becomes 0000 0001H (here JNZ test that AL is equal to zero ot not since AL is not equal to 0)

similar after 255 it ill be 1111 1111H (you can simply relate it like decimal value for convenience)

after 256 increment 10000 0000H (9 bit) , so discards 9 th bit an again 0000 0000H (this becomes the) now it will comes out of loop.

 

0
Why did you take size of AL as 8 bits ? I mean, nowhere it's mentioned that it's 8086 processor right ? in 8085 processor size of AL is 4 bits only. I think here processor is as per the given options:D:P
0 votes
Answer would be D Since AL = 00H =0000 0000 H after incrementing it every time it will be 0000 0001 0000 00010 .... 1111 1111 (highest value ) and then again incrementing will make result back 0000 0000 with Cy 1 so loop doesnt end and the process goes on !
by Loyal (9.9k points)
0 votes
by Active (3.9k points)
0
check it once their In question Paper Answer D which is 256
0 votes

Answer would be D Since AL = 00H =0000 0000 H after incrementing it every time it will be 0000 0001 0000 00010 .... 1111 1111 (highest value ) and then again incrementing will make result back 1111 1111 bcoz increment decrement would not impact if values are at extreme, so loop doesnt end and the process goes on !

by Junior (823 points)
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
50,737 questions
57,391 answers
198,591 comments
105,442 users