Spring 2001 CSCI 255 Lab 9

This lab is scheduled for the week of 26 March - 30 March.

Goals and Methods

This week we'll look at:

  1. Writing correct assembly language programs (again)
  2. Writing subroutines

Start off by creating and then connecting to a directory called csci/255/lab9. Copy your last week's lab8.asm program into this directory. Be sure to include the period at the end of the third command!

Your product

At the end of this lab you must have a directory called csci/255/lab9 containing two files, lab8.asm and lab9.asm. Those files must contain legal LC-2 assembly language programs.

Getting lab 8 correct

Your team should have received a printout of a test run of your Lab 8 program. If you did not bring that printout to class, go and get it now. If your program passed all test cases with no problems, you can go on to the next section. If it didn't pass all the test cases, fix it your lab8.asm program.

Calling subroutiens

Start the second part of the lab by copying into your lab9 directory an instructor-provided lab9.asm file.

This incomplete program contains a main routine that prompts the user for a decimal number and prints that number in hexadecimal.

Your job

You have to complete the program. The program calls two functions readdec and prnthex, presently implemented so that they do nothing but return.

The specifications of readdec and prnthex are given by comments embedded within the code. We'll include those comments below:


;;;; **** readdec ****
;;     Purpose:
;;         readdec reads and echoes a single character typed at the console.
;;         It tests the input character and sets R0 and R1 according to the
;;         following three cases:
;;           1) if the input character is an ASCII decimal digit ('0' to '9')
;;              R0 is set to 0
;;              R1 is set to the binary equivalent of the input digit (0 to 9)
;;           2) if the input character is not a decimal digit
;;              R0 is set to -1
;;              R1 is undefined
;;
;;        Except for R0 and R1, readdec restores all registers it modifies


;;;; **** prnthex ****
;;     Purpose:
;;         prnthex receives a single argument stored in register R0.
;;         prnthex examines the least significant (bottom) four bits
;;         of that argument as a hexadecimal digit from 0 to 15.
;;         prnthex returns in register R0, the common printable ASCII
;;         equivalent of the hex digits stored in those four bits.
;;         For example, if the input is xBEEF, the output is x45,
;;         ASCII for 'F'.  If the input is x4747, the output is x37,
;;         ASCII for '7'.
;;
;;         Except for R0, prnthex restores all registers it modifies

Start thinking and then start coding. About fifteen lines of code are required to implement each routine.

In writing readdec use the getc trap to read the single input character and the out trap to echo it. When debugging your program, you may find it useful to set breakpoints at the first instruction of each of your routines.

Going home

Do not delete your files. Your lab instructor will examine them later. Your instructor can also verify that you have placed your code in the correct place by executing the following command on woodfin.