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: 3678168 • 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?

For part c, if we know that A is often greater than B then this means the loop will be taken so this would be LT, wouldn't it?

Explanation / Answer

Assembly code

Here we comapre A and B

if (A>B) then add 1 in A that is A ->A+1

if (A<B) then add 1 in B that is B ->B+1

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