Java Reference
In-Depth Information
private final static int
READ_B_entry
#
7;
private final static int
READ_B
#
8;
private final static int
ADD_entry
#
9;
private final static int
ADD
#
10;
private final static int
WRITE_MEM2_entry
#
11;
private final static int
WRITE_MEM2
#
12;
private final static int
HALT_entry
#
13;
private final static int
HALT
#
14;
Step 2. Define an integer state attribute:
private int
state;
Step 3. Initialize the state attribute. Here we initialize the state in the
constructor; in particular we have to add a statement in the constructor that
was defined above.
CPU(Bus bus) {
this
.bus
#
bus;
state
#
READ_MEM0_entry;
}
Steps 4 and 5. Define the state evolution method.
void
execute() {
switch
(state) {
case
READ_MEM0_entry:
bus.setCommand(RAM.RAM_READ);
bus.setAddress(0);
state
!!
;
case
READ_MEM0:
if
( bus.getCommand().equals(RAM.ACK))
state
#
READ_A_entry;
break
;
case
READ_A_entry:
RegA
#
bus.getData();
state
!!
;
case
READ_A:
state
#
READ_MEM1_entry;
break
;
case
READ_MEM1_entry:
bus.setCommand(RAM.RAM_READ);
bus.setAddress(1);
state
!!
;
case
READ_MEM1:
if
(bus.getCommand().equals(RAM.ACK))
state
#
READ_B_entry;
break
;