Spring 2002 CSCI 255 Project 3

This assignment is due Friday, 10 May.

Write an LC-2 assembly language program that prompts its users to enter a string of 10 digits. The program counts the number of times each digit occurs and prints a table the number of occurences of each digit to the terminal.

Load your program at location x3000 and be sure to use GETC and OUT to read and write characters.

Here is an equivalent program written in C. By the way, using putc to write the output one character at a time is a little silly. But I did it this way to give a better idea of how the LC/2 program should be written.


#include <stdio.h>

void main(int argc, char *argv[]) {

  int i, c ;
  int H[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} ;

  fputs("Enter ten digits\n", stdout) ;
  for (i=0; i<10; ++i) {
    c = getc(stdin) ;
    if (('0' < c) && (c < '9'))
      H[c-'0']++ ;
  }

  for (i=0; i<10; ++i) {
    putc(i+'0', stdout) ;
    putc(':', stdout) ;
    putc(' ', stdout) ;
    putc(' ', stdout) ;
    putc(H[i]+'0', stdout) ;
    putc('\n', stdout) ;
  }
}

Turning in this assignment

This assignment is to be turned in by copying it to your Computer Science Unix directory. First create a protected directory csci/255/proj2 as shown below:

Then save your completed assembly program in the file proj3.asm within your csci/255/proj3 directory.