CS202 - Assignment Five

Due: 2016-03-25 11:55

Objectives

[15 points] The Σniac Simulator

The first part of this assignment is to write a Σniac simulator. You will not need to write this from scratch. Instead, start with zniac.c, which is labeled as to what you need to fill in to complete the simulator. The amount you need to write is relatively small. The bigger part of this assignment is actually reading the source code and understanding what it does. Do not skimp on this part.

Σniac Programs

  1. [10 points] Write a program to compute the maximum of two non-negative numbers in ROM (you will have to hard code these in). I want two files, one called hw5_max.zn, containing your assembly code, and one called hw5_max.hex with your machine code.

  2. [10 points] Write a program that tests if a number is even or odd and leaves either 0 (the number was even) or 1 (the number was odd) in the A register. Put your solution into files called hw5_odd.zn and hw5_odd.hex.

  3. [10 points] Write a program that computes the product of two non-negative numbers in ROM and leaves the result in A. You may assume that the multiplication does not result in overflow (i.e., that the result is less than or equal to 127). Does your program work if one or both numbers are negative? In a comment, explain in which cases it works and why. Put your solution into files called hw5_mult.zn and hw5_mult.hex.

  4. [10 points] We can only load 24 bytes into ROM. For this program your task is not to complete some work, just to get the machine to run for more than 24 steps… without executing a single bneg instruction. Ah, you say, simple, I’ll just use b and make a loop. Not so fast — the program has to properly run to completion (i.e., it must halt, so no infinite loops). Put your solution into files called hw5_runlong.zn and hw5_runlong.hex. For full credit, the machine must run for 25 steps without invoking bneg, you cannot exploit any bugs in the simulator, and you should not assume that RAM or A contains zeros when the simulation begins.

Σniac Assembly Format

There is no official format for Σniac files since there isn’t an assembler. As such, I would like you to use the format used on the reference sheet. Here is an example of what I would like those files to look like:

; Zniac summation program
; C. Andrews
; 2014-10-07
;
; Sums the numbers from 1 to 5 and stores the result at location 0x19
   
00         ld   A, N     ; 000 01100  0C
01         st   A, sum   ; 011 11001  79
02  loop:  sub  A, C1    ; 001 01011  2B
03         bneg end      ; 101 01001  A9
04         st   A, i     ; 011 11000  78
05         add  A, sum   ; 010 11001  59
06         st   A, sum   ; 011 11001  79
07         ld   A, i     ; 000 11000  18
08         b    loop     ; 100 00010  82
09  end:   ld   A, sum   ; 000 11001  19
0A         halt          ; 111 11111  FF
0B  C1:    1             ; 0000 0001  01
0C  N:     5             ; 0000 0101  05

18  i:
19  sum:

Note that comments use the ‘;’ in the same way that Python uses ‘#’ for single line comments. The inclusion of the opcodes is optional (note that they are comments), but I strongly encourage them since you will need to generate them anyway for the .hex files. As I said in class, I recommend using a spreadsheet to write your code initially and then copy and past it into a text file for submission.

The .hex files (the files the Σniac actually runs) can only contain hex values. Each instruction should be a single hex value, prefixed by a 0x sitting along on a line. So the above program will look like:


0x0C
0x79
0x2B
0xA9
0x78
0x59
0x79
0x18
0x82
0x19
0xFF
0x01
0x05


Turning in your work

To make our lives easier, please zip all of your files together before submitting them.

The .zip file should then be uploaded via Moodle.