Spring 2001 CSCI 255 Lab 13

This lab is scheduled for the week of 23 April - 27 April.

Goals and Methods

This week we'll look at:

Getting started

Begin by executing the following commands to create a directory csci/255/lab13 and copy one file into it.

The copied file is an LC-2 program that is missing a single routine. You'll write that routine.

The program

The complete program is based on an age-old problem called the Syracuse problem. All your program really need to do is compute the Syracuse function:

int SYR(int x) {
  if (x & 1)
    return 3*x + 1 ;
    return x/2 ;

In most computers, it's not hard to computer x/2. They have divide or shift right instructions. The LC-2 has neither. However, we've provided a function DIV2 that does this for you. All you have to do is call it.

When you run the complete program, it will prompt you for a four hexadecimal-digit number. It will then call your Syracuse function (SYR) over and over, first with your input number and thereafter with the result of the last call of the Syracuse function, until the Syracuse function returns a one.

If you write your SYR correctly, a run will look something like this:

Enter a four hexadecimal-digit number: 1c71
  Syracuse test:  1C71
  Syracuse test:  555A
  Syracuse test:  2AAA
  Syracuse test:  1555
  Syracuse test:  4000
  Syracuse test:  2000
  Syracuse test:  1000
  Syracuse test:  0800

It can take a while to get to 1. If your 3*X+1 overflows, you may never get there. By the way, the 3*X+1 will overflow an unsigned 16-bit number with X is greater than or equal to 21845 (0x5555).

Rules of engagement

Your program must implement SYR and call DIV2 using the calling conventions described in the 18 April lecture.

Going home

Hopefully, this is your last CSCI 255 lab. Don't delete your lab13.asm.