Systems Level Programming

 

First assessed coursework

 

You are asked to build in C a simple simulator for the assembly code used in the first two lectures. It should read in two files, given as command line arguments via argv. One of these files will contain the assembly code instructions, the other will contain the initial contants of memory.

 

You should assume that there are twenty four byte words of memory and eight 32 bit registers available, plus a program counter register.

 

The code file will start with an integer on a line by itself, which is the number of assembler instructions folowing. A sample file will be made available.

 

You do not need to represent a stack in this simulator.

 

This work is due in by the end of Week 6. You should submit a written report describing your program and how you tested it. A box will be placed in the student office and you should get your work stamped by the secretaries. You should send your source file to bpalmer@cee.hw.ac.uk for me to check it.

 

I may run a plagiarism check on the source files. If you have collaborated with someone, please make that clear in your report and detail who contributed what. I am happy to plit the credit for acknowledged joint work. If you copy or allow others to copy you will receive zero.

 

Brian Palmer


Some code to start you off

 

#include<stdio.h>

#include<stdlib.h>

 

typedef char * STRNG;

STRNG code[20];

int registers[8];

int memory[20];

 

STRNG get_line(FILE * inf)

{

  STRNG s;

  char tok = getc(inf);

  int count = 0;

  s = malloc(80);

  while(tok!='\n')

  {

    s[count++] = tok;

    tok = getc(inf);

  }

  s[count] = '\0';

  return s;

}

 

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

{

  int lines=0,

  count = 0;

 

  scanf("%d\n", &lines);

  for(count =0;count<lines;count++) code[count]= get_line(stdin);

  for(count = 0;count<lines;count++) printf("%s\n",code[count]);

  return 1;

}