This assignment must be submitted, as a PIC assembly file, to the Moodle submission page for Homework 8 by 11:00 PM on Thursday, 1 November.
Problem 1 and only
In Lab 8 you wrote a small PIC program to work on the Syracuse problem for 16-bit integers. Your task for this homework assignment is to extend that solution to 32-bit integers.
Here’s a few things you will need to get started.
- You will need to increase the space allocated for
x
from 2 bytes to 4 bytes. - In the lab you used one register,
W5
, forx
. This time you will need to use a two registers forx
. I suggestW4
andW5
. -
In the, you used the following code to initialize
x
..equ initX,2012 MOV #initX,W0 MOV WREG,x
Because the initial value ofx
is now 32-bits, you will need to do something different. I suggest the following:.equ initX,7527 MOV #(initX&0xFFFF),W0 MOV WREG,x MOV #(initX>>16),W0 MOV WREG,x+2
Once you’ve made those changes, the task isn’t that
hard. Find the places in your lab program where your tested,
added, and shifted x
.
Replace those few instructions with 32-bit versions as found
in Chapter 5.
It’s not that hard.
There were about six instructions testing and modifying x
in the 16-bit version. Each will be doubled in the 32-bit version.
However, don’t wait too long to get started.
Some test cases
initial x |
final r |
---|---|
2012 | 68 |
7527 | 150 |
131071 | 224 |
131072 | 17 |
131073 | 100 |