computer organization
c m s c 311  
s u m m e r   2 0 0 2  

Project #2

Due Date Sunday, July 7, 11:59 PM (just before midnight)

Posted: June 27, 2002

Additions

These are clarifications to various project specs.

Clarifications

Purpose

You spent Project #1 trying to "allocate" memory for the data segment. We're now going to the key part of the project---running the text segment of the assembly language interpreter.

Normally, both the data and the text is stored in memory. However, for this project, you can store the assembly lanugage portion in whatever data structure you want. The data portion will be stored in a simulated memory (basically, an array of characters or bytes).

In Project #3 (the next project), you will begin to store the text section in a binary format, as well.

Academic Integrity Statement

Please note that *all* programming projects in this course (including this one) are to be done independently or with the assistance of the instructional staff of this course only, unless otherwise specified IN PRINT by official webpages.

Please review the policies outlined on the class syllabus concerning the use of class computer accounts and concerning the University's Code of Academic Integrity. The instructors of this course will review the programs submitted by students for potential violations of the Code of Academic Integrity and if it is believed that a violation has occurred it will be referred to the Office of Judicial Programs and the Student Honor Council.

Hardcoding is considered a violation of academic integrity

Reminder

I thought this was obvious, but perhaps I should repeat it again. Each memory address stores one byte. A word (32 bits) occupies 4 consecutive memory addresses. The first byte of that address must be word-aligned (in an address divisibly by 4).

Additional Commands

The commands that your program should currently support are:

In addition to these commands, you should handle the following commands.

Command Response

Once the command has been read in, you should print the same response as in Project #1.

===> (1) You entered: [quit]
followed by the appropriate output for that command. Commands should start numbering at 0.

Case Insensitive

Commands are case-insensitive. Thus, reload, RELOAD, and reloAD are all valid ways to spell.

Invalid Commands

Print invalid command, if the command is invalid. If the command is valid, assume the arguments are also valid.
*** INVALID COMMAND [<command>]
Note: invalid commands may have bogus arguments too. <command> should include the command and the arguments too.

Assumptions

Starting Up

In main(), you should create an instance of the Memory object (there will be a class provided) and give it an initial size). For now, set that size to 4096 (this is 4K). If the computer has a difficult time allocating this size, we can reduce it (it should allow for much, much larger sizes though).

The Memory object should store int values in big-endian order. (OIT stores in little-endian).

Create in an instance of RegisterFile. This will represent the 32 registers, which will just be an array of 32 signed int values.

If a program has been loaded (from command line or through a load), you should set the program counter to the first instruction. Instructions should be saved in some sort of structure, say, a vector. You may wish to create a Program object, which stores a vector of Instruction objects and a list of Label and their corresponding instruction/address.

The program should be ready to run, with the program counter (which is just an index). You may wish to make the program counter part of the Program object.

As a suggestion, you may want to have a step() method, and a run() for Program.

Also, Program should contain pointers or references to Memory and RegisterFile, so it can see and modify them. In particular, the constructor should take them as arguments and save them as data members.

Initialization

Initialization should reset the entire memory to 0. All registers should also be set to 0, except for $r29, which should be set to the number of bytes in memory minus 4. Thus, if the memory has 4096 bytes, then set it to 4092 (base 10). This is where the stack will be located.

Running Code

In Project 1, you had two parts of the input: data and text. They had very little to do with each other. This time, the two parts are going to be run together.

Here's what you need to do:

Furthermore:

At this point, you can run the program.

Commands to Support

The following are a list of assembly language commands to support.

Command Explanation
add $rd, $rs, $rt Reg[ $rd ] = Reg[ $rs ] + Reg[ $rt ]
addi $rd, $rs, immed $rd = $rs + immed where immed is 16 bit 2-complement, sign-extended
sub $rd, $rs, $rt Reg[ $rd ] = Reg[ $rs ] - Reg[ $rt ]
and $rd, $rs, $rt Reg[ $rd ] = Reg[ $rs ] & Reg[ $rt ] (bitwise and)
andi $rd, $rs, immed Reg[ $rd ] = Reg[ $rs ] & immed where immed is 16 bit 2-complement, sign extended
or $rd, $rs, $rt Reg[ $rd ] = Reg[ $rs ] | Reg[ $rt ] (bitwise or)
ori $rd, $rs, immed $rd = $rs | immed where immed is 16 bit 2-complement, zero extended
xor $rd, $rs, $rt $rd = $rs ^ $rt (bitwise xor)
xori $rd, $rs, immed $rd = $rs & immed where immed is 16 bit 2-complement, zero extended
andi $rd, $rs, immed $rd = $rs & immed where immed is 16 bit 2-complement, zero extended
beq $rd, $rs, LABEL Jump to LABEL if Reg[ $rd ] == Reg[ $rs ], otherwise next instruction
bne $rd, $rs, LABEL Jump to LABEL if Reg[ $rd ] != Reg[ $rs ], otherwise next instruction
slt $rd, $rs, $rt If Reg[ $rs ] < Reg[ $rt ], then Reg[ $rd ] = 1 else Reg [ $rd ] = 0.
slti $rd, $rs, immed (CORRECTION: slt was replaced with slti on 5/13) If Reg[ $rs ] < immed then Reg[ $rd ] = 1 else Reg$[ rd ] = 0.
jr $rd Jump to absolute address stored in $rd
j LABEL Jump to LABEL
jal LABEL Jump to LABEL, storing address after this instruction in $r31
lw $rt, offset($rs) Compute address by Reg[ s ] + offset (sign extended offset) and load word to Reg[ t ].
lbu $rt, offset($rs) Compute address by Reg[ s ] + offset (sign extended offset) and load byte to Reg[ t ] (upper 24 bits are 0).
sw $rt, offset($rs) Compute address by Reg[ s ] + offset (sign extended offset) and store word from Reg[ t ] to that address.
sb $rt, offset($rs) Compute address by Reg[ s ] + offset (sign extended offset) and Stores least significant byte of Reg[ t ] to that address.
lui $rd, immed Load upper 16 bits of $rd with immed and lower 16 bits with 0.
bgtz $rs, LABEL If Reg[ s ] > 0, jump to LABEL, otherwise next instruction.
bgez $rs, LABEL If Reg[ s ] >= 0, jump to LABEL, otherwise next instruction.
bltz $rs, LABEL If Reg[ s ] < 0, jump to LABEL, otherwise next instruction.
blez $rs, LABEL If Reg[ s ] <= 0, jump to LABEL, otherwise next instruction.

Software Interrupts

In order to print information to the screen, you will implement fake software interrupt. There are two kinds of interrupts: external (hardware) interrupts and software interrupts.

A hardware interrupt usually occurs from an external device such as a mouse, keyboard, printer, etc. One mechanism for handling, say, mouse movements is called polling. This is where the CPU repeatedly checks to see if the mouse is doing anything. This can be wasteful use of CPU resources if the mouse isn't doing anything.

The other approach is to use hardware interrupts. This is an external signal (for example, a 0 to 1 transition) to the CPU, indicating an interrupt has occurred. Typically, the CPU completes the current instruction it is working on, then handles the interrupt.

The interrupt typically saves registers on the stack (although this isn't absolutely necessary), determines what interrupt has occurred (each interrupt has a special number), then runs the appropriate interrupt handling routine.

Once the interrupt handling routine is done, the program that was interrupted is restarted. The interrupt handling routine needs to be "programmed" ahead of time and can be altered to use routines that the user has developed (if the user is "trusted").

A hardware interrupt is similar to a function call, but is less predicatable.

An interrupt can also be used like a function call. Instead of the interrupt occurring due to a device signalling the CPU, an assembly language program uses special instructions to tell the operating system to run a special routine.

This mechanism can also be used like a function call. In the old days, IBM had something called BIOS which were a series of routines stored in, say, ROM. You invoked the routines using software interrupts.

The software interrupt is much closer to a function call. It uses a similar technique to invoke the interrupt handling routine, and then the routine runs under "supervisor" or "kernel" mode, which is a privileged mode of operation.

You need to support the following software interrupts.

Syntax for Software Interrupts

The following isn't very standard, but is good enough for our purposes.

Print without any spaces or newlines except where indicated (i.e., in strings or for the debug).

The last 3 allow assembly language program to interact with the outside world.

Submitting

"Primary" posted soon!


See the class syllabus for policies concerning email
Last Modified: Sun Jun 30 23:08:48 EDT 2002
left up down right home

Web Accessibility