CS202 - Assignment Five
Due: 2018-10-24 09:00a
Objectives
- Get your feet wet thinking about how to approach assembly programming
- Start thinking about the basics of machine architecture
[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
For the ∑niac programs, you should write out the code like I showed you in class in a spreadsheet. Google sheets is a fine option, as is Excel or Numbers.
Make a separate spreadsheet for each program. In addition, I would like you to add information about your program at the top of the file.
- First line: name of the program
- Second line: your name
- Third line: the date
- Fourth line: blank
- Fifth line: the start of your program
For your program, the columns you should include are line number (in hex), label, instruction, binary form of instruction, hex form of instruction. You are welcome to write comments in further columns. Please turn this in as an .xlsx
file (native Excel format, available as download or export format from Sheets and Numbers).
To run your programs, you need to copy the hex code into a separate file. Each instruction should be a single hex value, prefixed by a 0x sitting alone on a line. This should be a plain text file with a .hex
suffix.
[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.xlsx, containing your assembly code, and one called hw5_max.hex with your machine code.
[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.xlsx and hw5_odd.hex.
[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? On a line in the spreadsheet after your program, explain in which cases it works and why. Put your solution into files called hw5_mult.xlsx and hw5_mult.hex.
[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 useb
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.xlsx and hw5_runlong.hex. For full credit, the machine must run for 25 steps without invokingbneg
, you cannot exploit any bugs in the simulator, and you should not assume that RAM or A contains zeros when the simulation begins.
[5 points] As usual, there are five points for following all directions correctly.
Turning in your work
Submit the completed assignment on Canvas.