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

The purpose of this assignment is to write a program in LC-3 machine language to

ID: 3601486 • Letter: T

Question

The purpose of this assignment is to write a program in LC-3 machine language to find if a given input is
a power of 2 and a perfect square. If it is then, write its exponent (as power of 2) as the result otherwise,
write -1 as the result.

Description:

Find if a given number N at location x2FFE is, a power of 2 and a perfect square; If yes, write its exponent (k where N=2^k) to x2FFF, else write a -1 to x2FFF

Notes:
Program must be at x3000.
Program must be written in binary
Do not assume any values in registers

0010000000000000 ; First line says where the program must load to
Put your code here
1111000000100101 ; Halt machine

Explanation / Answer

orig x3000

LD R2, Zero

LD R0, M0

LD R1, M1

Loop BRz Done

ADD R2, R2, R0

ADD R1, R1, -1

BR Loop

Done ST R2, Res

HALT

Res.FILL x0000

Zero.FILL x0000

M0 .FILL x0007

M1 .FILL x0003

END