Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assume that a processor has a feature that enables the compilier to specify the

ID: 3678096 • Letter: A

Question

Assume that a processor has a feature that enables the compilier to specify the initial prediction state as either LT or LNT for a branch instruction. Consider a statement of the form

IF A > B THEN A = A + 1 ELSE B = B + 1

(a) Generate assembly-language code for the statement above.

(b) In the absence of any other information, discuss how the compiler should specify the initial prediction state for the branch instructions in the assembly code.

(c) A study of the ecevution ehavior of the program containing the above statement reveals that the value of variable A is often larger than the value of variable B. If this information is made available to the compiler, discuss how it would influence the initial prediction state for the branch instructions.

I think I have part a and b. For part a, wouldn't this be something like:

Assume R0 contains the value in A and R1 contains the value in B.

            Branch_if_R0>R1   LOOP

            Add    R1, R1, #1

LOOP   Add                      R0, R0, #1

As for part b, since the loop conditional is at the beginning of the loop, wouldn't this be LNT?

Explanation / Answer

This is not LNT(less than or equal ) ..See the below assembly language code given if else statement using jge (jump greater than condition).

Answer for Question:

Simple if A>B then a =a+1 else b =b+1 demonstration :

       mov A, eax ; move a value in eax
mov b, ebx       ; move b valu in ebx
       cmp eax, ebx ; compare eax and ebx
       jge ElsePart ; jump eax is greter than ebx else part
       inc A ; increment A = A+!
       jmp EndOfIf; ; jump to EndOfIf
ElseBlk:
       inc b ; ; increment b = b+1
EndOfIf:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote