The Assignment This assignment requires you to write a number of subroutines in LC3 assembly code. As the LC3 has a limi

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

The Assignment This assignment requires you to write a number of subroutines in LC3 assembly code. As the LC3 has a limi

Post by answerhappygod »

The Assignment
This assignment requires you to write a number of subroutines in
LC3 assembly code. As the LC3 has a limited instruction set, you
will find that you must write code to perform operations that you
take for granted in high level programming languages such as C. For
example, the left and right shift operators (<< and >>)
do not exist in LC3, nor is there a bitwise OR operator (|).
Therefore, you must write functions to perform these operations in
terms of instructions that the LC-3 can understand. For all
operations, the Param1 and Param2 variables are the two operands
and the answer is stored in the Result variable. All numbers are
16-bit integers stored in 2's complement representation, and all
results are limited to 16-bits. No detection of overflow is
necessary. Here is a description of the functions you must
write:
NOTE: For IntMul, you may assume that
Param2 is either 0 or positive (Param1 could be anything). For the
left shift operation, you should fill the vacant positions with 0's
(it is a logical shift). For the right shift, you
will have to perform the sign extension (arithmetic
shift). Also, the number of bits (Param2) for left or right
shifts will never be negative or zero.
IMPORTANT:
The protocol for debugging this assignment is presented in the
lab. Note that you worked on the first three subroutines in the
recitation.
Getting Started
Perform the following steps:
Note: when programming in assembly, it is easy to forget the
syntax of each instruction (e.g., where do the source and
destination registers go). Please refer to this
document (starting on page 6) for a description of the
assembly syntax for each LC-3 instruction.
Arithmetic Right Shifting
Unlike left shifting, right shifting is not a trivial operation
to implement in the LC-3. Let's go through an example of how to
perform an arithmetic right shift. For this example, we will be
using 5 bits instead of 16.
Suppose I want to do 10110 >> 2.
First, I will initialize my result to be 00000. The idea is that
I will walk through the bits copying from left to right as
follows:
Step 1
Notice that the first two bits starting from the right will go
away. Hence, I'll start by copying bit 2 in my parameter to bit 0
in my result:
Step 2
Now, I move to the next bit. The next bit is 0, so I don't need
to copy that bit to the result because the result was initialized
to 0's:
Step 3
Now, I move to the next bit. The next bit is 1, so I need to
copy that to the result:
Step 4
I need to perform the sign extension (copy the parameter's most
significant bit over up to the result's most significant bit). I do
that with bit 4...
Step 5
... and I do the same with bit 5.
Step 6
It looks like I've gone through all the bits in the parameter,
so I'm done.
To inspect and copy bits, you will need to use masks and bitwise
operations. Below is a flowchart that shows you the general
algorithm for right shifting. You will need to take care of the
details. Remember that numbers in the LC-3 are 16 bits wide (not
5).
Grading Criteria
Preliminary Testing (40 points):
Final Testing (60 points):
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply