9) Choose the correct Assembly Language code that will do the following: If dog is equal to cat THEN go to LOOP_A ELSE go to LOOP_B if(dog == cat) goto LOOP_A else goto LOOP_B Question 9 options:
cmp cat,dog
jnz LOOP_A
jmp LOOP_B
mov AX,cat
cmp AX,dog
jz LOOP_A
jmp LOOP_B
mov AX,dog
cmp AX,cat
js LOOP_A
jmp LOOP_B
mov AX,cat
cmp AX,dog
js LOOP_A
jmp LOOP_B
the cmp instruction compares the two values by subtracting them and sets the zero flag if both are equal
using this property we will make a jump to Loop_A using the JZ instruction which jumps to the given location if zero flag is set.
hence the correct option should be
mov AX,cat
cmp AX,dog
jz LOOP_A
jmp LOOP_B
here , we 1st move the value of cat to accumulator and then compare the accumulator with dog.
if they are equal the zero flag will be set and control will move to LOOP_A else it will do an unconditional jump to LOOP_B.
Get Answers For Free
Most questions answered within 1 hours.