Professional Documents
Culture Documents
! "
#
#
$ ! ! " #
%
%
&
$
'
!
" #
$% & ''( )
# !
*
) &+
&,
-
)
.
.
. !
&+&& .
&+&, !
/
0
/ 0 ) $2 ' '% '3( /'0
'
$4 , 3 + '+ '3(
)
$%( 1 1
2++
$%( .
*
-
) )
!
7
* &+
&,
1 2 1 %
1 4
1 ,
1 3
&+&,
$ 2 8 '&(
8&+ 9:
&+&, ;5< &+&, ,
* ;5 9: &+&&
& $ 2(
1
&+&&=&, " )
*
>
&+'&, &+&&=&, &+'&,
# '%
&+2&,
2' 2'
?
2&, @ &+
&, ! )
&+%&, !
;
# %&, )
; ; ;
)
/
AB
C
D
0
))
; ; )
$&(
&+
&,
! "
# 7
)
7
$'2( "
!
- !
$'(
)
!
$ &
''( 1 )
)
)
-# )
ProcessorSimulator
ProcessorSimulator(char*); // Load program from file
int runSim();
CPU
CPU(BIU*);
Word getFlags();
void setFlags(Word);
Content readReg(registerName);
void writeReg(registerName, Content&);
BIU
Bus
Memory
Memory(char *);
BIU(Bus*);
Bus(Memory*);
Instruction* fetchInstruction(Address);
Instruction* fetchInstruction(Address);
Byte fetchDataByte(Address);
Byte fetchDataByte(Address);
Instruction* decodeInstruction(Address);
Instruction* readInstruction(Address);
void writeInstruction(Address, Instruction*);
Byte readDataByte(Address);
void writeDataByte(Address, Byte);
Word fetchDataWord(Address);
Instruction* fetchInstruction(Address);
Register<Content>
Content read();
void Write(Content);
Address
Word
Byte
Operand
Instruction
Instruction();
virtual void execute(CPU&)
throw(Halt, ErrorMsg) = 0; Byte getLength();
void setLength(Byte);
)
#
)
5 !" C * #
"
!" 9
!" ! #
5
1
9
*
- *
)
! ;
; - ! ! .
*
AD ; ;
E
"
C
)
$'4(
-
.
! /0
/
5GG0
)
< 7
#$% & ''( .
ProcessorSimulator
Proc8088Simulator
int runSim();
CPU
BIU
Bus
Memory
CPU(BIU*);
BIU(Bus*);
Bus(Memory*);
Word getFlags();
void setFlags(Word);
Instruction* fetchInstruction(Address);
Instruction* fetchInstruction(Address);
Content readReg(registerName);
void writeReg(registerName, Content&);
Memory(char *);
Instruction* decodeInstruction(Address);
Instruction* readInstruction(Address);
void writeInstruction(Address, Instruction*);
Byte readDataByte(Address);
void writeDataByte(Address, Byte);
Instruction* fetchInstruction(Address);
void storeInstruction(Address, Instruction*);
Byte fetchDataByte(Address);
BIU8Bit
BIU8Bit(Bus8Bit*);
Byte fetchDataByte(Address);
Bus8Bit
Bus8Bit(Memory*);
Byte fetchDataByte(Address);
void storeDataByte(Address, Byte);
Register<Content>
Content read();
Address
void Write(Content);
Word
DataStore
Byte
Byte read(Address);
void write(Address, Byte);
CodeStore
Instruction* read(Address);
void write(Address, Instruction*);
5
&+
&, *
!
&+&& )
'
-
)
$
5 5
&
CodeStore
Instruction* read(Address);
void write(Address, Instruction*);
Instruction
Instruction();
virtual void execute(CPU&) throw(Halt, ErrorMsg) = 0;
Byte getLength();
void setLength(Byte);
ZeroOpInst
OneOpInst
TwoOpInst
ZeroOpInst();
OneOpInst(Operand *);
...
...
Ret
Ret();
void execute(CPU&) throw(Halt,ErrorMsg);
...
Jmp
Add
Jmp(Operand *);
void execute(CPU&) throw(Halt,ErrorMsg);
Operand
virtual Word read(CPU&) = 0;
virtual void write(CPU&, Word) throw(ErrorMsg) = 0;
virtual Address getEffectiveAddress(CPU&) throw(ErrorMsg) = 0;
Byte getSize();
MemOp
RegOp
ImmOp
Word read(CPU&);
RegOp(registerName);
Word read(CPU&);
ImmOp(Word);
Word read(CPU&);
! &+&&
9F&9 9&9
*
.
" 5
/
0
B
7 * # 5
2
&+&& <
8
Cpu
Biu
Bus
Memory
CodeStore
IP
Inst
go();
read();
addr
fetchInstruction(addr);
fetchInstruction(addr);
readInstruction(addr);
read(addr);
Inst*
if Inst* == NULL?
decodeInstruction(addr);
forever
Inst*
Inst*
Inst*
Inst*
read();
addr
getLength();
len
write(addr+len);
execute(Cpu&);
ADD
DestOperand
SourceOperand
Cpu
FLAGS
execute(Cpu&);
read(Cpu&);
destOp
read(Cpu&);
srcOp
getFlags();
read();
flags
flags
setFlags(newFlags);
write(newFlags);
write(CPU&, destOp+srcOp);
/ 5GG0 "
)
&+&& ?
*
7
1 / %" 0
*
7
) )
)
!
C
!
- 4+H
I
ProcessorSimulator
Proc8088Simulator
Proc8086Simulator
Proc8086Simulator(char*); // Load program from file
CPU
BIU
CPU(BIU*);
Word getFlags();
void setFlags(Word);
Bus
Memory
Memory(char *);
BIU(Bus*);
Bus(Memory*);
Instruction* fetchInstruction(Address);
Instruction* fetchInstruction(Address);
Content readReg(registerName);
void writeReg(registerName, Content&);
Instruction* decodeInstruction(Address);
Instruction* readInstruction(Address);
void writeInstruction(Address, Instruction*);
Byte readDataByte(Address);
void writeDataByte(Address, Byte);
Instruction* fetchInstruction(Address);
void storeInstruction(Address, Instruction*);
Byte fetchDataByte(Address);
BIU8Bit
BIU8Bit(Bus8Bit*);
Byte fetchDataByte(Address);
Bus8Bit
Bus8Bit(Memory*);
Byte fetchDataByte(Address);
void storeDataByte(Address, Byte);
Register<Content>
BIU16Bit
Content read();
void Write(Content);
Bus16Bit
BIU16Bit(Bus16Bit*);
Bus16Bit(Memory*);
Word fetchDataWord(Address);
Word fetchDataWord(Address);
Address
Word
DataStore
Byte
Byte read(Address);
void write(Address, Byte);
CodeStore
Instruction* read(Address);
void write(Address, Instruction*);
7
4 >
?
7
. #
.
&+&&
&+&, I
* &+&, &+&&
'
5
5 &
5 &
5 &
5 9 ,9
5 9F
5 9
1 ,
7 &
5 &
5 '
() 5 ) *
5
5 &
)
5 &
5
'
() ? !
&+&& &+&, .
&+'&,
!
"
E
)
"
3
)
5 )+
5
5 +
5 )+
5 )+
)+
5 5
"
Proc8088Simulator
Proc8088Simulator(char*); // Load program from file
ProcessorSimulator
Proc8086Simulator
DebuggingSimulator
DebuggingSimulator(char*); // Load program from file
void debug();
CPU
BIU
CPU(BIU*);
Word getFlags();
void setFlags(Word);
Bus
Memory
Memory(char *);
BIU(Bus*);
Bus(Memory*);
Instruction* fetchInstruction(Address);
Instruction* fetchInstruction(Address);
Content readReg(registerName);
void writeReg(registerName, Content&);
Instruction* decodeInstruction(Address);
Instruction* readInstruction(Address);
void writeInstruction(Address, Instruction*);
Byte readDataByte(Address);
void writeDataByte(Address, Byte);
Instruction* fetchInstruction(Address);
void storeInstruction(Address, Instruction*);
Byte fetchDataByte(Address);
BIU8Bit
BIU8Bit(Bus8Bit*);
Byte fetchDataByte(Address);
Bus8Bit
Bus8Bit(Memory*);
Byte fetchDataByte(Address);
void storeDataByte(Address, Byte);
Register<Content>
BIU16Bit
Content read();
void Write(Content);
DebuggingCPU
Bus16Bit
BIU16Bit(Bus16Bit*);
Bus16Bit(Memory*);
Word fetchDataWord(Address);
Word fetchDataWord(Address);
DebuggingCPU(BIU*);
void debug();
void trace();
void printRegs();
void dumpMemory();
void help();
Address
Word
DataStore
Byte
Byte read(Address);
void write(Address, Byte);
CodeStore
Instruction* read(Address);
void write(Address, Instruction*);
CodeStore
Instruction* read(Address);
void write(Address, Instruction*);
Instruction
Instruction();
virtual void execute(CPU&) throw(Halt, ErrorMsg) = 0;
Byte getLength();
void setLength(Byte);
virtual void print() = 0;
virtual void printMnemonic() = 0;
ZeroOpInst
OneOpInst
TwoOpInst
ZeroOpInst();
OneOpInst(Operand *);
void print();
virtual void printMnemonic() = 0;
...
void print();
virtual void printMnemonic() = 0;
...
Ret
...
Jmp
Add
Ret();
void execute(CPU&) throw(Halt,ErrorMsg);
Jmp(Operand *);
void execute(CPU&) throw(Halt,ErrorMsg);
void printMnemonic();
void printMnemonic();
void printMnemonic();
Operand
virtual Word read(CPU&) = 0;
virtual void write(CPU&, Word) throw(ErrorMsg) = 0;
virtual Address getEffectiveAddress(CPU&) throw(ErrorMsg) = 0;
Byte getSize();
virtual void print() = 0;
MemOp
MemOp(Memory *, Address, Byte&, Byte);
RegOp
ImmOp
void print();
void print();
void print();
Word read(CPU&);
void write(CPU&, Word) throw(ErrorMsg);
&6 :!
& " 5 " 5
5 !"
"
"
5
5 )+
!
5;F "
!
1 2 % &+
&,
. *
!
*
.
&+&, :;1) * $%(
1 1
" 1 1
5$ 4(
1 1 6
2++
$%(
) .
*
- 5 ! *
7> *
7 &+&,
5 ;5 &+&,
&+&,
. " ."1:$',(
5-: ! " 5-: !
!
5-: !
,
!!"
&
$## %
%# #
"""
"%#
$
"
!!
$!
"
"
&
$%$
$%%
!
&
# #!
!
""
$
# $
"%
"#"
!#
"
#
"
%
!
$
"!#$
"$
&
" #
&
"""
%#
#
"%
$
!$!
$$
#
!$
#
!
!
#
%!!
!
;) 22
/ 0
8 ++ >
J $'8(>
> !
, $' (>
$'8(>
# ++++
/ ++
++0
822,,3
32,+2+
? 7
7 ! %%%
%34 !
;) 22 ++2
"
# 8
7
7 : 7
*
@15
7
#
&
++
'
2
%
,
4
,
3 -
&
,
8
+ "
"
!"#$
%
!
'4+,
' +2
'2++
''+2
'2 4
'233
'4 8
''3'
'2&2
'2%'
'22'
%
!
'++&+
3,8
43%&
43%4
& %8
&, &
82&+
&,8'
&2+
324,
,2&%
&+
448
,&4
',
3&%
3&2
3,8
&'2
3,&
3%
,83
++
'
2
%
,
4
,
3 -
&
,
8
+ "
"
!"#$
%
8+,
%%%+
+''
++%
''&4
4'+
%2%
+88
&8
'&
%
'32
%34
++8
++%
4+,
4%%
'&2
+%,
442
24,
22'
2+
'%%
++
%4
'38
4+,
' 4
2%'
2 3
2+&
* 7
@15
'
<
! '
5
7 @15
515
;
1 1
"
:
5 * K
$3( ?
# )
)
F
:
$2 ' '% '3(
'+
" 5
!
5
$, +(
$4 3 '+ '3(
"
$8
&
#
1 1
$%(
"
! 7
'
#
$ ( " B 9 ; - 88,
$'( 9 L @ I -
!
&
48M3+ L 88'
$2( @ 9* 1 '
())* + ,!- .
L
88+
$%( B 9 : " 1 9 C 6
@ 8,) 2+& . F
L
88,
$4( 5 5 B F C I "
)
)
&/ 0#) - 8&8
$,( 5 : C K I . C
! ."
., : 8&,
$3( 9 5 * B K 16 " )
! ())1
/." !2"%3!. . "
" .
88%
$&( 5
( ; B J .?C / 0
"* N
6==
. . .
$ '( L
B ; .
8
4
7 % 9
9
!
: K 1 882 "
"
L @ I
$ 2( L
B ; .
/
7 / :
/ : K)
1 88, "
B6 " " @156 &+
&,
$ %( 1 1. O '+ F?P . . . 6==
$ 4( 9 . K B : @ % .
83&
()); '
+ @15
''
! ." .,
/." !2 &/, ())@ .
& 4
!
L 88'
$'%( @* 1Q B 6 "
$'4( B " 1
* 9 " :
())$ '
. B 88,
$',( C * '/ " (*7 '9 /
!<"
.
. 8&4
$'3( L C O @ L :?6 " )
)
!
' =
" /
A
.
%
'+ M'+3 L
88%
$'&( L .*
"
/
$'8( : . .
! 88,
'2
''
(
)
JMP
SourceOperand
CPU
IP
execute(Cpu&);
read(Cpu&);
offset
readReg(IP);
read();
addr
addr
writeReg(IP, addr+offset);
write(addr+offset);
'%
PUSH
Cpu
SP
SourceOperand
Biu
Bus
Memory
DataStore
execute(Cpu&);
readReg(SP);
read();
addr
addr
writeReg(SP,addr-2);
write(addr-2);
read(CPU&);
dataWord
storeDataWord(addr-2, dataWord);
storeDataWord(addr-2, dataWord);
storeDataByte(addr-1, highByte);
writeDataByte(addr-1, highByte);
write(addr-1, highByte);
storeDataByte(addr-2, lowByte);
writeDataByte(addr-2, lowByte);
write(addr-2, lowByte);
'4
RegOp
CPU
AX
write(Cpu&, value);
writeReg(AX, value);
write(value);
MemOp
Cpu
BX
Biu
Bus
Memory
DataStore
read(Cpu&);
readReg(BX);
read();
addr
addr
fetchDataWord(addr);
fetchDataWord(addr);
fetchDataByte(addr+1);
readDataByte(addr+1);
read(addr+1);
highByte
highByte
highByte
fetchDataByte(addr);
readDataByte(addr);
read(addr);
lowByte
lowByte
lowByte
fullWord
fullWord
fullWord
',
DebuggingCpu
Biu
Bus
Memory
CodeStore
trace();
read();
addr
fetchInstruction(addr);
fetchInstruction(addr);
readInstruction(addr);
read(addr);
Inst*
if Inst* == NULL?
decodeInstruction(addr);
Inst*
Inst*
Inst*
Inst*
read();
addr
getLength();
len
write(addr+len);
execute(Cpu&);
'3
IP
Inst
'&