Simple Machine

arch.sm213.machine.student
Class CPU

java.lang.Object
  extended by java.util.Observable
      extended by machine.AbstractCPU
          extended by arch.sm213.machine.AbstractSM213CPU
              extended by arch.sm213.machine.student.CPU
Direct Known Subclasses:
VirtualMemoryCPU

public class CPU
extends AbstractSM213CPU

The Simple Machine CPU. Simulate the execution of a single cycle of the Simple Machine SM213 CPU.


Nested Class Summary
 
Nested classes/interfaces inherited from class machine.AbstractCPU
AbstractCPU.ImplementationException, AbstractCPU.InternalState, AbstractCPU.InvalidInstructionException, AbstractCPU.MachineHaltException
 
Field Summary
 
Fields inherited from class arch.sm213.machine.AbstractSM213CPU
insOp0, insOp1, insOp2, insOpCode, insOpExt, insOpImm, instruction, pc, physMem, ps, ptbr
 
Fields inherited from class machine.AbstractCPU
is, mem, reg
 
Constructor Summary
CPU(String name, AbstractMainMemory memory)
          Create a new CPU.
 
Method Summary
protected  void execute()
          Execution Stage of CPU Cycle.
protected  void fetch()
          Fetch Stage of CPU Cycle.
 
Methods inherited from class arch.sm213.machine.AbstractSM213CPU
cycle, enableVirtualMemory, setPC, translateAddress
 
Methods inherited from class machine.AbstractCPU
getMainMemory, getName, getPC, getProcessorState, getRegisterFile, isInterrupt, newInstance, start, triggerInterrupt
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CPU

public CPU(String name,
           AbstractMainMemory memory)
Create a new CPU.

Parameters:
name - fully-qualified name of CPU implementation.
memory - main memory used by CPU.
Method Detail

fetch

protected void fetch()
              throws AbstractMainMemory.InvalidAddressException
Fetch Stage of CPU Cycle. Fetch instruction at address stored in "pc" register from memory into instruction register and set "pc" to point to the next instruction to execute. Input register: pc. Output registers: pc, instruction, insOpCode, insOp0, insOp1, insOp2, insOpImm, insOpExt

Specified by:
fetch in class AbstractSM213CPU
Throws:
MainMemory.InvalidAddressException - when program counter contains an invalid memory address.
AbstractMainMemory.InvalidAddressException - Program counter stores an invalid memory address for fetching a new instruction.
See Also:
for pc, instruction, insOpCode, insOp0, insOp1, insOp2, insOpImm, insOpExt

execute

protected void execute()
                throws AbstractCPU.InvalidInstructionException,
                       AbstractCPU.MachineHaltException,
                       RegisterSet.InvalidRegisterNumberException,
                       AbstractMainMemory.InvalidAddressException
Execution Stage of CPU Cycle. Execute instruction that was fetched by Fetch stage. Input state: pc, instruction, insOpCode, insOp0, insOp1, insOp2, insOpImm, insOpExt, reg, mem Ouput state: pc, reg, mem

Specified by:
execute in class AbstractSM213CPU
Throws:
InvalidInstructionException - when instruction format is invalid.
MachineHaltException - when instruction is the HALT instruction.
RegisterSet.InvalidRegisterNumberException - when instruction references an invalid register (i.e, not 0-7).
MainMemory.InvalidAddressException - when instruction references an invalid memory address.
AbstractCPU.InvalidInstructionException - instruction is invalid.
AbstractCPU.MachineHaltException - instruction is the halt instruction.
AbstractMainMemory.InvalidAddressException - instruction encodes an invalid memory address.
See Also:
for pc, instruction, insOpCode, insOp0, insOp1, insOp2, insOpImm, insOpExt, for mem, for reg

Simple Machine

Copyright © 2010, 2011 Mike Feeley. All Rights Reserved.