You are asked to add a multiply instruction to LC3 making us

You are asked to add a multiply instruction to LC3, making use of the unused opcode. Give the format of the instruction with support for both register addressing mode and immediate addressing mode for its second source operand. Also, the twist is that the destination register is also the first source. So, for example R3 times R1 rightarrow R2, so its only necessary to specify the destination, because it is also the first source.

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.

 You are asked to add a multiply instruction to LC3, making use of the unused opcode. Give the format of the instruction with support for both register addressi
 You are asked to add a multiply instruction to LC3, making use of the unused opcode. Give the format of the instruction with support for both register addressi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site