jfrace.cpu
Class FJE5

java.lang.Object
  |
  +--jfrace.cpu.FJE5
All Implemented Interfaces:
CPU, Hardware

public class FJE5
extends java.lang.Object
implements CPU

A simple 5-bit CPU. It has the following registers:
A  5-bit accumulator
I  5-bit index register. It defines the higher order bits of a 10-bit address in instructions with a bias.
SP  10-bit stack pointer
PC  10-bit program counter

Here is the list of operations:
Assembler-OperationMachine-code Meaning
NOP00000 No operation.
PC <- PC + 1
XAI00001 Exchange accumulator with index register.
A <-> I
PC <- PC + 1
LDA value 00010 value Load accumulator with value
A <- value
PC <- PC + 2
LDI value 00011 value Load index register with value
I <- value
PC <- PC + 2
LDAI bias 00100 bias Load accumulator indirectly from the location build by the index register and the bias.
A <- (32*I+bias)
PC <- PC + 2
LDAD bias 00101 bias Load accumulator double indirectly.
A <- (32*(32*I+bias)+(32*I+bias+1))
PC <- PC + 2
STAI bias 00110 bias Store accumulator indirectly to a location build by the index register and the bias.
(32*I+bias) <- A
PC <- PC + 2
STAD bias 00111 bias Store accumulator double indirectly.
(32*(32*I+bias)+(32*I+bias+1)) <- A
PC <- PC + 2
PUSH01000 Push accumulator and index register on stack
(SP-1) <- A
(SP-2) <- I
SP <- SP - 2

PC <- PC + 1
POP01001 Pop accumulator and index register from stack
I <- (SP)
A <- (SP+1)
SP <- SP + 2

PC <- PC + 1
CALL address 01010 address-high address-low Call a subroutine. Push the program counter on stack.
(SP-1) <- (PC + 3)low
(SP-2) <- (PC + 3)high
SP <- SP - 2
PC <- 32 *
address-high + address-low
RET01011 Return from subroutine. Pop the program counter from the stack
PC <- 32 * (SP) + (SP+1)
SP <- SP + 2
LDS value 01100 value-high value-low Load stack pointer
SP <- 32 * value-high + value-low
PC <- PC + 3
JP address 01101 address-high address-low Jump to address
PC <- 32 * address-high + address-low
JPZ address 01110 address-high address-low Jump to address if accumulator equals zero
if A == 0: PC <- 32 * address-high + address-low
if A != 0: PC <- PC + 3
JPNZ address 01111 address-high address-low Jump to address if accumulator not equals zero
if A != 0: PC <- 32 * address-high + address-low
if A == 0: PC <- PC + 3
ADD bias 10000 bias Add to accumulator a value from the location build by the index register and the bias.
A <- A + (32*I+bias)
PC <- PC + 2
SUB bias 10010 bias Subtract from accumulator a value from the location build by the index register and the bias.
A <- A - (32*I+bias)
PC <- PC + 2
AND bias 10100 bias Logically AND to accumulator a value from the location build by the index register and the bias.
A <- A AND (32*I+bias)
PC <- PC + 2
OR bias 10110 bias Logically OR to accumulator a value from the location build by the index register and the bias.
A <- A OR (32*I+bias)
PC <- PC + 2
XOR bias 11000 bias Logicall XOR to accumulator a value from the location build by the index register and the bias.
A <- A XOR (32*I+bias)
PC <- PC + 2
SARA11010 Shift arithmetically right accumulator. The uppermost bit will be shifted from the left into the accumulator. Corresponds to a division by two of a signed number.
A <- A >> 1
SLRA11100 Shift logically right accumulator. A zero bit will be shifted from the left into the accumulator.
Corresponds to a division by two of an unsigned number.
A <- A >>> 1
SLA11110 Shift left accumulator. A zero bit will be shifted from the right into the accumulator. Corresponds to a multiplication with 2.
A <- A << 1
HALT11111 Stops exceution. Program counter will not be incremented.

Author:
Franz-Josef Elmer

Field Summary
static int A
          Index of register A (accumulator).
static int I
          Index of register I (index register).
static int PC
          Index of register PC (pogram counter).
static int READ_DATA
          Activity mask: Data read
static int READ_PRG
          Activity mask: Program read
static int SP
          Index of register SP (stack pointer).
static int WRITE_DATA
          Activity mask: Data write
 
Constructor Summary
FJE5()
           
 
Method Summary
 int disassemble(java.lang.StringBuffer sb, int address)
          Disassemble the next op-code at the given address and append it to the given string buffer.
 int getActivityAddress(int index)
          Return the activity address for a given index.
 AddressSpace getAddressSpace()
          Get the address space.
 java.lang.String getErrorDescription()
          Return error description.
 java.lang.String getName()
          Return "FJE5".
 int getNumberOfBits()
          Return 5.
 int getNumberOfRegisters()
          Return 4.
 Register getProgramCounter()
          Return the program counter.
 Register getRegister(int index)
          Return a register.
 void interrupt(long interrupt)
          Not implemented.
 int next()
          Proceed one opcode further.
 void reset()
          Reset the hardware.
 void setAddressSpace(AddressSpace addressSpace)
          Set the address space.
 void setRegisterValue(int index, int value)
          Set the value of a register.
 boolean supportsDisassembling()
          Disassembling is supported.
 java.lang.String toString()
          Return the state of the CPU as a well-formed string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

READ_PRG

public static final int READ_PRG
Activity mask: Program read

READ_DATA

public static final int READ_DATA
Activity mask: Data read

WRITE_DATA

public static final int WRITE_DATA
Activity mask: Data write

A

public static final int A
Index of register A (accumulator).

I

public static final int I
Index of register I (index register).

SP

public static final int SP
Index of register SP (stack pointer).

PC

public static final int PC
Index of register PC (pogram counter).
Constructor Detail

FJE5

public FJE5()
Method Detail

getActivityAddress

public int getActivityAddress(int index)
Return the activity address for a given index. An activity address is an address together with kind of reading or writing activity (i.e. READ_PRG, READ_DATA, or WRITE_DATA). There are up to five activity address stored during the execution of the next() method.

toString

public java.lang.String toString()
Return the state of the CPU as a well-formed string.
Overrides:
toString in class java.lang.Object

getName

public java.lang.String getName()
Return "FJE5".
Specified by:
getName in interface CPU

getNumberOfBits

public int getNumberOfBits()
Return 5.
Specified by:
getNumberOfBits in interface Hardware

getNumberOfRegisters

public int getNumberOfRegisters()
Return 4.
Specified by:
getNumberOfRegisters in interface CPU

getRegister

public Register getRegister(int index)
Description copied from interface: CPU
Return a register.
Specified by:
getRegister in interface CPU
Following copied from interface: jfrace.CPU
Parameters:
index - Index of the register.
Returns:
null if no register exists for the given index.

getProgramCounter

public Register getProgramCounter()
Description copied from interface: CPU
Return the program counter. The program counter is a special register.
Specified by:
getProgramCounter in interface CPU

setRegisterValue

public void setRegisterValue(int index,
                             int value)
Description copied from interface: CPU
Set the value of a register.
Specified by:
setRegisterValue in interface CPU
Following copied from interface: jfrace.CPU
Parameters:
index - Index of the register.
value - New value.

setAddressSpace

public void setAddressSpace(AddressSpace addressSpace)
Description copied from interface: CPU
Set the address space.
Specified by:
setAddressSpace in interface CPU

getAddressSpace

public AddressSpace getAddressSpace()
Description copied from interface: CPU
Get the address space.
Specified by:
getAddressSpace in interface CPU

reset

public void reset()
Description copied from interface: Hardware
Reset the hardware. After reseting this hardware will be in a well-defined state.
Specified by:
reset in interface Hardware

interrupt

public void interrupt(long interrupt)
Not implemented.
Specified by:
interrupt in interface CPU
Following copied from interface: jfrace.CPU
Parameters:
interrupt - Bit pattern of the interrupt. The meaning of the bits depend on the implementation.

getErrorDescription

public java.lang.String getErrorDescription()
Description copied from interface: CPU
Return error description. The meaning of the error code depends on the implementation. This method should be called when CPU.next() returns -1.
Specified by:
getErrorDescription in interface CPU

next

public int next()
Description copied from interface: CPU
Proceed one opcode further. Return the number of clock cycles.
Specified by:
next in interface CPU
Following copied from interface: jfrace.CPU
Returns:
-1 if an error occured.

supportsDisassembling

public boolean supportsDisassembling()
Disassembling is supported.
Specified by:
supportsDisassembling in interface CPU

disassemble

public int disassemble(java.lang.StringBuffer sb,
                       int address)
Description copied from interface: CPU
Disassemble the next op-code at the given address and append it to the given string buffer. If disassembling isn't supported -1 will be returned.
Specified by:
disassemble in interface CPU
Following copied from interface: jfrace.CPU
Parameters:
sb - String buffer.
address - Address of op-code.
Returns:
number of addressable units of the op-code at address.