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

Using this instruction set: Instructions ADD (1, ACC = ACC +arg) BR (1, jump to

ID: 3581135 • Letter: U

Question

Using this instruction set:

Instructions
ADD (1, ACC = ACC +arg)
BR (1, jump to arg)
BRNEG (1, jump to arg if ACC < 0)
BRZNEG (1, jump to arg if ACC <= 0)
BRPOS (1, jump to arg if ACC > 0)
BRZPOS (1, jump to arg if ACC >= 0)
BRZERO (1, jump to arg if ACC == 0)
COPY (2, arg1 = arg2)
DIV (1, ACC = ACC / arg)
MULT (1, ACC = ACC * arg)
READ (1, arg=input integer)
WRITE (1, put arg to output as integer)
STOP (0, stop program)
STORE (1, arg = ACC)
SUB (1, ACC = ACC - arg)
NOOP (0, nothing)
LOAD (1, ACC=arg)
ADD, DIV, MULT, WRITE, LOAD, SUB can take either variable or immediate value
as the arg: immediate value is positive integer or negative integer
PUSH (0, tos++)
POP (0, tos{)
STACKW (1,stack[tos-arg]=ACC)
STACKR (1,ACC=stack[tos-arg])

convert the following do while loop into a while loop using the ASSEMBLY instructions provided.

do

{

racer1 += 20; racer2 += 25;

} while(racer2 < racer1);

Explanation / Answer

L1:
ADD (1, AX = AX + 20)
ADD (1, BX = BX + 25)
BRNEG (1, jump to L1 if BX < AX)

Here AX is racer1 and BX is racer2.

Here i am adding 20 value to AX variable and 25 to BX variable.

Then i am comparing two varibale values using the provided instruction BRNEG. If it is true then it will continue the loop.