Sie sind auf Seite 1von 2

COMS 2223 Computer Organization and Programming, Spring 2015

Programming Assignment #2
Due Friday, March 20, 2015
Write a program that simulates a simple computer with the following instruction set, which we
have been using in class:
Opcode
0
1
2
3
4
5
6
7
8
9
10
11
12
Note: AC

Mnemonic Description
HLT
Stop execution
LDA
Move contents of memory cell addressed into AC
STA
Move contents of AC into addressed memory location
ADD
Add contents of memory cell addressed to AC
SUB
Subtract contents of memory cell addressed from AC
MUL
Multiply AC value by contents of memory cell addressed
DIV
Divide AC value by contents of memory cell addressed
JMP
Branch to address part of instruction (unconditional jump)
BRZ
Branch to address part of instruction if AC value is zero
BRP
Branch to address part of instruction if AC value is positive
BRN
Branch to address part of instruction if AC value is negative
READ
Input from keyboard (read decimal data) and store it in AC
WRITE
Display value of AC on screen (in decimal)
is the accumulator.

The computer is designed with 16-bit words. In each word, the first 4 bits are used for the opcode
and the next one bit indicates the addressing mode: 0 means direct addressing and 1 means indirect
addressing, which adds the indirect cycle before the execute cycle. (In your simulator, when this
bit is 1, simply executes a code segment that simulates the indirect cycle before executing the
instruction.) The remaining 11 bits are used for the address. With 4 bits for the opcode, 16
different code values are possible, but only 13 are used. (See the table above.) The 11-bit address
space extends from 0 to 211 1, which is 2047. Note that HLT, READ, and WRITE do not use
the address field. A sample input file (with comments) is shown below. Note that your program
should read the input file name from the command line.
0001000000001000
0011000000001010
1100000000000000
0000000000000000
0000000000001111
0000000000000101

;
;
;
;
;
;

LDA 8
ADD 10
WRITE
HLT
15
5

The comments (assembly code) shown above are not included in the actual input file. The actual
input file contains only the binary code. (Your simulator program may be programmed so that the
comments are ignored.) (Q. What will be the output of the above code? Note that user I/O should
be done in decimal, NOT in binary. For the READ instruction, the user enters data in decimal
from the keyboard. Output from the program is in decimal on the screen.)
Create your own test cases (assembly programs in binary text) and test your simulator program.
Make sure to test all three addressing modes.
Non-standard C++ elements should not be used in your program. It should be documented and
readable. The course number/title, the assignment number, your name, and a short description
of the program should appear at the top of the source code. Provide a separate users guide

in plain text file. It should be written so that users after reading the users guide can use your
simulator, i.e., users can do assembly language programming (in binary text mode) using your
simulator. The instruction set should be described in your document.
On the due day (at the beginning of the class period), the instructor will be collecting your program
directly from your boole account using super user commands. The file names of your program and
users guide must be:
2223-prog2.cpp
2223-prog2.txt
These files must be placed in your login directory.