You are asked to add a multiply instruction to LC3 making us
Solution
Most assembly language instructions require operands to be processed. An operand address provides the location, where the data to be processed is stored. Multiplication is achieved via addition means a repeated addition is multiplication.
X*Y means X+X+……. Y times
Register Addressing mode, a register contains the operand. Depending upon the instruction, the register may be the first operand, the second operand or both.
An immediate operand has a constant value or an expression. When an instruction with two operands uses immediate addressing, the first operand may be a register or memory location, and the second operand is an immediate constant. The first operand defines the length of the data.
LC 3 has two basic data types int and char these are 16 bit word.
Sign <- 1 //if sign is -ve
If X< 0 then // x is below 0
X = -X // then s is -ve
If Y<0 then
Y = -Y
Prod <-0
While Y !=0 do
Prod <-prod +X
Y<- Y-1
If sign <0 then
Prod <- -prod
Orig x3000
X3000 Load R2, 0
X3001 Load R0, M0
X3002 Load R1, M1
Begin multiply
X3003 Loop BRz Done
X3004 ADD R2, R2, R0
X3005 ADD R1, R1, #-1
X3006 BR Loop
End Multiply
X3007 Done ST R2, Result
X3008 Halt
X3009 Result .Fill X0000
X300A zero .Fill X0000
X300B M0 .Fill x0007
X300C M1 .Fill x0003
End.

