Tiny Computer Architecture


Memory: 4096 16-bit words
Input: ASCII characters from memory location 0FFF
Output: ASCII characters to memory location 0FFF
Accumulator: 16 bits
 

Instruction Set:

ADD -- 1,addr -- add to accumulator from memory
AND -- 2,addr -- logical AND to accumulator from memory
LD  -- 3,addr -- load to accumulator from memory
STO -- 4,addr -- store accumulator into memory
CAL -- 5,addr -- store PC into memory with JMP opcode, then jump to addr+1
JMP -- 6,addr -- jump to addr
JZ  -- 7,addr -- jump to addr if accumulator = 0

Extended Opcodes (these may be combined on one line, and executed in the order shown)
NOP -- 0000 -- no operation
CLR -- 0008 -- clear accumulator to 0
SHR -- 0004 -- shift accumulator right with sign extend
INV -- 0002 -- complement every bit of accumulator
INC -- 0001 -- add +1 to accumulator
NEG -- 0003 -- =INV+INC, arithmetic negative of accumulator
HLT -- 0010 -- stop

Detailed Explanation: If you think of the TinyComputer as a Java class, then these 14 operations could be methods, something like thus (over-simplified):

class TinyComputer {
  short[4095] Memory;
  short PC=0;
  short Ac;
  int nextIn=0;
  boolean running;

  void ADD(short addr) { Ac = Ac + Memory[addr]; }
  void AND(short addr) { Ac = Ac & Memory[addr]; }
  void  LD(short addr) {
    if (addr==4095) Ac = InData.charAt(nextIn++);
      else Ac = Memory[addr];
    }
  void STO(short addr) {
    Memory[addr] = Ac;
    if (addr==4095) OutData = OutData.concat(String.valueOf((char) Ac));
    }
  void CAL(short addr) { Memory[addr] = PC; PC = addr+1; } // PC is already incremented
  void JMP(short addr) { PC = addr; }
  void  JZ(short addr) { if(Ac==0) PC = addr; }

  void Xop(short addr) {
    if(addr&8 !=0) Ac = 0;
    if(addr&4 !=0) Ac = Ac >> 1;
    if(addr&2 !=0) Ac = -1-Ac;
    if(addr&1 !=0) Ac = Ac+1;
    if(addr&16 !=0) running = false;
    }

  void Run(int cycles) {
    running = true;
    while (0<cycles-- && running) {
      short theOp = Memory[PC++];
      short addr = theOp % 0xFFF;
      switch (theOp >> 13) {
        case 0: Xop(addr); break;
        case 1: ADD(addr); break;
        case 2: AND(addr); break;
        case 3:  LD(addr); break;
        case 4: STO(addr); break;
        case 5: CAL(addr); break;
        case 6: JMP(addr); break;
        case 7:  JZ(addr); break;
        }
      }
    } // end Run

Assembly Language: Programming machine code. Computers only understand numbers (see above), but people think better in words. An assembler lets you write words, and substitutes the appropriate numbers for them. Each assembly language line generally represents the number in one memory location, typically one machine instruction.

In the simplest assembler there are three fields:

Everything after a semicolon ";" is comment and completely ignored. A semicolon in the first column makes the whole line a comment with no effect.

Any word or number in the first column is an address. If a number, then the assembler starts loading that and subsequent lines beginning in that address. If a name, it is called a "label" and the assembler sets the value of that name to be the current load address (the memory address of that line).

All other words and numbers are just added together to become the value stored in the memory location associated with that line. If there are none, then that memory location is filled from the next non-trivial assembly line.


The assembler already knows the value of each instruction name (called "mnemonic" -- the "m" is not pronounced), and it is traditional to put the mnemonic first on the line after the label (most assemblers require it). The TinyComputer machine instructions have at most two fields, so they are represented on the assembly line with just the mnemonic and possibly a label reference. Other computer architectures with more complex machine code typically have required operands after the mnemonic corresponding to each field in the instruction word.

The Assembly Listing is just the source text with two columns of hexadecimal numbers prepended to it on the left. The first column is the respective memory addresses, and the second column is the numeric value of the memory at that address. The following is a sample assembly listing for a snippet of TinyComputer code, representing A=(A+3)/2+1, which is loaded into memory locations 0321 through 0327:
 

Locn Data Label Mnem Opnds Comments
0321 6326       LD   VarA  ; get variable
0322 2327       ADD  Int3
0323 0004       SHR INC    ; both SHR then INC in one cycle
0324 8326       STO  VarA
0325 0010       HLT
0326 0000 VarA  0
0327 0003 Int3  3

 

TinyComputer emulator, on the Novell server, use the shortcut:
    G:\CLASS\Computer Science\CIS2233\TinyComputer

To operate this emulator, 2-click the shortcut, then

1.  Click "Load" button and navigate to your F drive or wherever you have assembly language source text in a file. I suggest you start with "PewTest" in the CIS2233 folder of the G drive.

2.  If you have input text, click in the "Input" field and type (or paste) in any text. PewTest expects two characters, for example "x3" (without the quotes)

3.  Choose an execution mode from the radio buttons:
    S -- Single step
    A -- Trace all (for 100 cycles)
    J -- Trace only jumps and I/O for 1000 cycles
    N -- No trace, for 10,000 cycles (or until it halts)

4.  Click on the Run button

5.  The trace log is appended to the main panel (you can select and copy the text, and paste it into a text file document for later review). Similarly see memory contents in the left panel, and output in the lower right panel.

6.  Click on the Run button again as needed to continue execution. Click the Load button to restart. Giving PewTest "x3" results in output "6120".
 

If you want to run this program on your own computer, just copy all three items (the Java program is in the folder) onto your own computer. You also need the Java runtime environment (J2EE or most any Java 1 version) installed, which you can download from the www.sun.com website. You may need to adjust the shortcut to reflect the new location of the Java folder (it's the executable Java classes). The current DOS command executed by this shortcut is:

    java -cp "G:\CLASS\Computer Science\CIS2233\Java" TinyComputer
 

Enhanced Architecture The TinyComputer has been extended to encompass the architectural changes appropriate to projects #2,3 (multiply), 8 (indirect addressing), 9 (index register), 12 (floating-point add/subtract), and 16 (floating-point multiply), as follows: A new button near the top-left of the simulator window selects between indirect addressing, index register, and the other additional instructions that use instruction bit 12, and a new processor register MX was added to serve as a multiplier/product or index register, as appropriate. The new operation codes are:

TAX -- 0020 -- transfer accumulator to MQ (after INC, if combined)
TXA -- 0040 -- transfer MQ to accumulator (before INC, if combined)
MPY -- 0100 -- multiply accumulator times MQ, and put the product in MQ
FAD -- 1*,addr -- floating-point add to accumulator from memory
FSB -- 2*,addr -- floating-point subtract memory from accumulator
FMP -- 3*,addr -- floating-point multiply to accumulator from memory
JN  -- 7*,addr -- jump on accumulator negative

LD *addr -- (or any memory access instruction) load indirect/load indexed
 

Rev. 2002 November 1