Question

Assembly Code & debug the following program in VS, then answer these questions at the end...

Assembly

Code & debug the following program in VS, then answer these questions at the end of the code using comments:

a) To which label the program jumped?

b) Why did the program jump to this label?

c) Why the program didn’t jump to the other label, since ‘80h > 7Fh’ is correct?

mov al,+127 ;hex value is 7Fh (+127)

cmp al,-128 ;hex value is 80h (-128)

ja IsAbove

jg IsGreater

IsAbove:

exit

IsGreater:

exit

Homework Answers

Answer #1

To answer this question lets, first understand the JA and JF flags.

JA Flag : Algorithm: if (CF = 0) and (ZF = 0) then jump

JG Flag : if (ZF = 0) and (SF = OF) then jump

Now, let us understand the CMP label:

Compare. Algorithm: operand1 - operand2

The immediate result is not stored anywhere, flags are set (OF, SF, ZF, AF, PF, CF) according to result.

Now in the question we are using CMP on +127 and -128, when subtracting it will result in -1.

For jump condtion to stasify we need to set ZF = 0.

But ZF = 0 only if  After any arithmetical or logical operation if the result is 0 or 00H, the zero flag becomes set i.e. 1, otherwise it becomes reset i.e. 0.
We can see that carry flag is also 0.

So JA Flag would be used.

a) isAbove label

b) I have explained it above.

c) Because the result is not stored in immediate result, but using flags, as explained above.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a sequence of two instructions that copies bits 0-5 from AL to bits 0-5 in...
Write a sequence of two instructions that copies bits 0-5 from AL to bits 0-5 in BL. Bits 6-7 in BL should be cleared, and AL should be unchanged             Mov al, bl       And 00111111, bl       Write a sequence of two instructions that copies the integer in bits 4-7 from AL register into bits 0-3 of the BL register. Upper 4 bits of AL and BL will be cleared             Shr al, 4       Mov bl,...
Section 2: Using the MARS or SPIM simulator develop a program that will implement the following...
Section 2: Using the MARS or SPIM simulator develop a program that will implement the following conditional statement. If ( n is even) { n = n / 2; } else { n = 3 * n + 1; } In this case, n is to be input by the user (assume they input a non-negative value), the conditional is performed, and the resulting n is to be output. Again, use the system calls for input, output, and exiting the...
In assembly masm use the code below! Write a program that reverse a string using indirect...
In assembly masm use the code below! Write a program that reverse a string using indirect addressing (may not use the stack - push/pop). The string will be given by the user and be up to 64 characters long INCLUDE Irvine32.inc INCLUDE macros.inc MAX = 64 .data source BYTE MAX DUP('#'),0 destination BYTE LENGTHOF source DUP('*'),0 actual_length DWORD ? ask BYTE "Enter a String: ",0 .code main proc ; ask user for input mov edx, OFFSET ask call WriteString ;...