You are on page 1of 147

MANCHESTERMETROPOLI

TANUNI
VERS
ITY

BS
c.(
Hons
)Ap
pli
edCo
mpu
ting

ASi
mpl
eSimul
atorf
oraBa
sic
Mic
ropr
ocess
or

Au
thor
: Sup
erv
iso
r:
Mar
ekRepa
k Moha
mma
dHa
mmou deh

Nopa rtof t
hisproj
ecthasbeensubmit
tedinsuppo
rtofanappl
ica
ti
onf or
anyothe rdegre
eorqu ali
fi
cat
ionatthi
soranyotheri
nsti
tut
eoflear
ning.
Apartfrom thosepartsoftheproj
ectcont
aini
ngcit
ati
onstotheworkof
othe
rs,thisproj
ecti
smyownu nai
dedwork.

S
igne
d:_____________________
Abs
tra
ct
Mi c
roprocessorareg e
ne r
al
lyv eryc omplic
atedi ntegratedcir
cu itchi
pswhicha r
edi ffi
cul
ts u
b j
ecttoteach.I tisa n
i
mpor tanttopicincompu terarchi
te ct
uresasitist hefundame ntalpar
tofeverycompu t
ersyste
m. Possi
bi
lityofl ar
g e
cal
culati
onsinas mallamo untof t
ime ,pr
ogrammi ngc apabi
li
ti
e sandthepotenti
alt
oc ommu nic
atewithothe rde v
ices
hasincreasedt hescal
eofa ppli
c a
tionsthemi c
ropr oce s
sorhasb e
enu s
edin.Att hepr esentti
mee v
eryi ntell
igent
elec
tronicdevicesuchasamob i
lep honeorana vig at
ions ys
temdoe sconta
ins omekindof microproc
essor.Asar es
u l
t
ofthiseveryc omputersci
ences tudentshouldk nowt heg e
nera lar
chi
tect
ureofmi c
r oproce
s s
orandhowi tma nages
andpr oces
sesda ta
,andc ontrol
sot herpa r
tsoft hes ystem.Ma nyme t
hodsforteachingmi cr
oprocess
orsha v
eb ee n
proposed,onei mportantme t
hodi ssimu l
ati
on.Ca mb r
idgeAdv a
nced Le a
rner
'sDi c
ti
ona r
y[ 2008]de fi
ne sa
si
mu lat
ionas


amo
del
ofas
eto
fpr
obl
emso
fev
ent
sth
atc
anb
eus
ed
t
ote
achs
ome
oneh
owt
odos
ome
thi
ng,
ort
hep
roc
esso
f
ma
kin
gsu
chamo
del

Howe ver,puretheoret
ic
altea chingoft hesubjectdoesnotful
lycla
r i
fieswhatt
hes t
ude ntisexpectedt
ou nders
tand,
andthisisthet i
mewhe ns imu lationcome sin,tob r
idgethegapbe tweenthetheoryandt her ealword.Oneoft he
mostva l
ua b
lefeat
ureofsimu lationisthatstu
de ntshaveanopportunitytoappl
ytheirtheoret
icalknowledgeinasafe
r
e a
li
sti
ce nvi
ronme nt
.Mi cropr oce s
sorsimulati
onr eveal
srealsi
tua t
ionsofinnermi cr
oprocessorprocess
es.The
advant
a geofsimulati
onistha tu serhasacapabil
itytographi
cal
lyi
ll
u strat
ethewholeprocessanddi spl
aytheint
ernal
s
tateata nytimeoft hee x
e cution.Addi ti
onall
y,inst
ruct
ionscanb ee xecut
edste
p-by-stepme thodwhi chst
opsthe
exec
u t
iona ft
ereachinst
ruction, thusstudent
sha veanopportunit
yt oidenti
fyt
hec hangesthathav ebeenmadeafter
eac
hs t
e p.
Ac
kno
wle
dge
ment
s
Pe
opl
ewhoh
avec
ont
ri
but
edt
othi
spr
oje
cta
ndIwou
ldl
i
ket
otha
nksa
re:
 Dr.MohammedHa mmou
deh,f
orhi
ssu
per
vis
ionoft
hispr
oje
ct,a
ndpr
ovi
di
ngmewi
thg
uida
ncea
nd
s
ugges
ti
onst
hrou
ghout
.
 S
ara
hRog
ers
,forpr
oof
rea
dingt
her
epor
tandf
orpr
ovi
di
ngmewi
thu
sef
ulf
eedb
ack
.

i
Co
nte
nts
1 I
ntr
oduc
tion 1
1
.1 WhatisMi cr
oproces
sor?.................................. 1
1
.2 WhatisS i
mu l
at
ion? .................................... 1
1
.3 Whyu seSimulat
ion?.................................... 2
1
.4 Si
mu l
ationinEducat
ional
Cont
ext.............................. 2
1
.5 Methodology ....................................... 3

2 Li
ter
atur
eRe
vie
w 5
2
.1 Intr
oduct i
on........................................ 5
2
.2 Simulat
ioni nEdu c a
tion................................... 5
2
.3 Conc l
usion ........................................ 9
2
.4 Intr
oduct i
ontoMi cropr ocess
orArc hi
tect
ure.........................1
0
2
.5 Microprocessor6 502....................................1 0
2.5.
1 Ar it
hme ticLog i
cUni tArchit
ectu
re..........................1
1
2.5.
2 AddOpe rati
onDe s
ign ...............................1 2
2.5.
3 Re gist
erAr chi t
e c
ture................................1 7
2.5.
4 3 -
b i
tRe gist
erDe sig
n................................1 8
2.5.
5 Cont rol AndTi ming................................2 0
2.5.
6 Cl ockGe neratorDe si
gn ..............................2 1
2.5.
7 Me mor yAr chitectu
re ...............................2 4
2
.6 Compi l
erAr chitect
u re...................................2 5
2
.7 Inst
ruct
ionS et Architecture.................................2 7
2
.8 Reviewof Exist
ingS imu lators................................2 8
2.8.
1 GNUS im8 085...................................2 8
2.8.
2 Gs im8 5......................................3 0
2.8.
3 Mi croproc essorS i
mu l
ator5.............................3 2
2.8.
4 Emu 808 6.....................................3 4
2.8.
5 Mi croproc essor8 085Simu la
tor3 ..........................3
5
2.8.
6 Conc l
u s
ion ....................................3 7

3 De
sig
nandAna
lys
is 39
3
.1 Intr
oducti
on........................................3 9
3
.2 Ite
rati
ve&I ncr
eme nt
alMode l................................3 9
3
.4 Simulat
orDe s
ign......................................4 1
3
.5 Microproce
ssorDe s
ign...................................4 4
3.5.
1 Cont rolandTiming ................................4 5
3.5.
2 Re gist
erDe s
ign ..................................4 5
3.5.
3 I nst
ruct
ionSetDe s
ign ...............................4 6
3.5.
4 Ex ter
nalMe moryDe s
ign..............................4 8
3.5.
5 Me moryS t
ackDe s
ign ...............................5 1
3.5.
6 Ar it
hme t
icLogicUnitDes
ign............................55
3
.6 AssemblyLanguageSyntaxandCompil
er...........................5
7
3.6.
1 As semblyLanguageSynt
ax..............................57

i
i
3.
5.
2 Compi lerDesig
n..................................5 8
3
.7 Gra
phi
cal
UserInte
rfa
c e ..................................61
3.
7.
1 Ma i
nMe nuLa you
t.................................61
3.
7.
2 S tat
usPanelandMe mor
yMa
pLa
you
t........................6
2

4 I
mplementation 64
4
.1 S i
mu lat
orope rati
on.....................................6 4
4
.2 Timi ngI mpl eme ntati
on...................................6 5
4.
2.
1 Cl oc kRa te ....................................6 5
4.
2.
2 Cl oc kThr e a
d ...................................6 6
4.
2.
3 Thr eadImpl eme ntat
ion...............................6 7
4
.3 Re gi
sterImpl eme ntati
on ..................................6 8
4
.4 Nu mb erBa seConv ers
ions .................................6 9
4
.5 Me mor yI mpl eme nt a
ti
on..................................7 0
4
.6 S t
ackI mpleme ntation ...................................7 1
4
.7 Ar i
thme ti
cLog icUni tImpl e
me ntat
ion............................7 3
4
.8 Mi croproces sorImpl eme nta
ti
on...............................7 4
4.
8.
1 I ns tructi
onEx ecuti
on ...............................7 5
4.
8.
2 Re g i
s t
erTr ansferOpe r
ati
on.............................7 6
4.
8.
3 Ar ithme ticOpe rat
ion................................7 6
4.
8.
4 Cont rolFlowI ns t
ruct
ion..............................7 6
4
.9 Gr aphicalUs erInt erf
aceImpleme ntat
ion...........................78
4.
9.
1 GTK+Tool ki
t...................................7 8
4.
9.
2 Gl ade.......................................7 8
4.
9.
3 g t
k mma ndGl ade .................................8 0
4.
9.
4 S i
g na l
s......................................8 0
4.
9.
5 I nv ok i
ngCompi l
er.................................8 0
4.
9.
6 S i
mu lat
ion.....................................8 1
4
.10 Compi l
e r.........................................8 2

5 Sof
twa
reTe
sti
ng 85
5
.1 Fi
rs
tSi
mu l
at
ion ......................................8 5
5.
1.
1 Da t
aTr a
ns f
erInstr
ucti
ons..............................88
5.
1.
2 Ar it
hme ti
candLog i
cOpe r
ati
ons
...........................8
9
5.
1.
3 Re gist
erOv erf
low .................................9 0
5.
1.
4 Ov er
fl
owDe t
e ct
ion ................................9 1
5.
1.
5 Cont rolFlowI nstr
uct
ions..............................91
5.
1.
6 Eng agingMe mor y.................................9 3
5
.2 Si
mula
ti
onAnalysi
s.....................................9 4
5.
2.
1 S peedAna ly
sis...................................9 4
5.
2.
2 Cl ockRa t
eAna l
ysi
s ................................9 7
5
.3 Rev
ers
eCodeEng i
ne er
ing .................................1 0
4

6 Ev
alua
tion 109
6
.1 Ai
msandOb je
cti
ves....................................109
6
.2 Fe
edback.........................................1 11
6.
2.
1 Feedbac
kForm ...................................112
6.
2.
2 Evalu
ati
ononFee
dba
ck................................1
12
6
.3 Fur
the
rWor k .......................................1 13

i
i
i
Appe
ndi
ces

A Te
rmsofRef
erence 115
A.
1 Proj
ectBack
ground.....................................115
A.
2 Aims...........................................1 16
A.
3 Ob j
ect
ive
s.........................................1 16
A.
4 Proj
ectDeli
ver
able
s ....................................117

B I
nst
ruc
tionSe
t 118

C Sol
uti
ons 126

D Fe
edba
ck 128
D.
1 Feedb
a c
kFor
m ......................................1 28
D.
2 SampleComment
s.....................................129

E Re
quir
eme nts 131
C.
1 Tool s...........................................1 31
C.
2 Librari
es .........................................1 31
C.
2.
1Ru nningSi
mul
at
ion ....................................131
C.
2.
2Gt kmm ..........................................1 31
C.
2.
3Libglademm........................................1 32
C.
2.
4Boos t...........................................1 32

F Ins
tal
la
tion 133
D.1 Sou r
ceAvai
la
bil
i
ty.....................................133
D.2 Compi l
at
ion........................................1 33

G CDCont
ents 134
G.
1 Proj
ectReport.......................................134
G.
2 micp-s
im .........................................1 34
G.
3 AssemblyScr
ipt
s......................................134

Re
fer
enc
es 135

i
v
Li
sto
fFi
gur
es
1
.1 Compu
terb
ase
dsy
ste
mde
pic
ti
ngt
hef
lowof
inf
orma
ti
on ................... 1

2
.1 Use ri nterfaceof interacti
v eanima tions oftware........................ 8
2
.2 Inter nal archit
e ct
u reof MOSTe c
hnol o gy6 5
0 2mi c
r oproc
e s
sor.................1 1
2
.3 3-bit ALUb lockd iagram ..................................1 2
2
.4 Tru tht a blede t
e r
mi ningtheope rationf orALU ........................1 2
2
.5 Bloc ks che meof addb l
ock .................................1 3
2
.6 Tru tht ab l
eo f3 -
bita dder.A,Ba ndCa ret hei
np utvariabl
es
.Inputsaremappedint
oCa rryandSum
outp u tva ri
ables ......................................1 3
2
.7 Log icg atesp erforminga dd i
tion.No neo ftheinputsiso nandc or
rectl
ynoneoftheou t
putsi
sfl
ashi
ng.1 4
2
.8 Kar na ug hMa pwi t
h4v ari
ab l
esa ndmi nima l
is
edg rou ps.....................1 4
2
.9 Kar na ug hma po fSUM a ndCARRYo u tputvari
ables......................1 5
2
.10 Mi nima li
sedmo de lofl og
icg atesper f
o rmingad di
tion.Twoi nputvari
abl
es(BandC)a ndc orr
ect
ly
onlyCa rryisset t
o1 .....................................1 5
2
.11 Ad ditio nfu ncti
o ne nga gi
ngEXOR, ANDa ndORg ates.
Allthr
eeinpu tv
ari
abl
esaresetandbothCa r
ry
andS u ma r
ec orreclyind i
cati
ngl ogical 1............................1 6
2
.12 Ad dingt wo3 -bitnu mb ers(1+3=4 )b yu si
ngintegratedci
rcuit
s.................1 6
2
.13 6-bit ad der.5inp utsa r
es et1a ndo nlyo neinp ut(D)i sswit
chedo f
f.1+1+1+1+1e qu
als5wh i
chis
i
nb ina ry1 01........................................1 7
2
.14 Bloc kd iag r
amo fan8 -b i
tregiste
r...............................1 7
2
.15 Fli
p -flopt ransit
iond i
agram. Firstbitisth eInputvari
a bl
e,secondbitdenot
estheWr i
teprote
cti
onb i
t
andt h el astbitistheCl ockt i
me ...............................1 8
2
.16 Tru tht ab l
eo fregisterb a
sedo nt hetr ansiti
ond ia
gram......................1 8
2
.17 Kar na ug hma pf orQns ta
te..................................1 9
2
.18 As imp lefli
p -
fl
o ph olding1b itof i
nfo rma ti
on.Th ecu rr
entstat
eis1(stat
efl
ash
ing).I
np utandClockis
setto0a ndo nlyLo a db i
tisset 1.Th es t
atewillchangea ssoonasclockbith
asoccurr
eda tt
heinput..1 9
2
.19 3-bit register.3Inp utb it
sd ef
inesth ev aluetobes t
o r
edi ntheregi
ste
r...............2 0
2
.20 Clo cks ign alwithfreq uency2 Hz...............................2 1
2
.21 Asta blemu lti
vibrator....................................2 1
2
.22 Simu lateda st
ab l
eflip-f
lop( mu lt
ivibrato r
)...........................2 2
2
.23 Ou tp u tsignalprod ucedb ya st
a bl
eflipflop( node1 0)......................2 2
2
.24 As imp lec urrentamp l
ifi
er..................................2 3
2
.25 No rma lisedo utputsigna l
(no de1 4)..............................2 3
2
.26 Co mp arisono ftheo u t
p utsignal
s...............................2 4
2
.27 Bloc kd iag r
amo fame mo ryuni t...............................2 4
2
.28 Bloc kd iag r
amo fame mo ryan da s
so ci
a tedregi
sters.......................2 5
2
.29 Bloc kd iag r
amo fcomp il
er..................................2 6
2
.30 Instru ctione xecutionc ycl
e..................................2 7
2
.31 Differ ent ISAa pproa ches..................................2 8
2
.32 GNUS im8 085Us erInterface.................................2 9
2
.33 Instru ctionk eyp a
d .....................................3 0
2
.34 Use ri nterfaceo fGsim8 5 ..................................3 1
2
.35 Gsim8 5Ke yp ad ......................................3 1
2
.36 MS 5u s
e rinterf
a c
ewi thme mo ryma p.............................3 2

v
2
.37 Addi
ti
onalde
vic
esimp
lemente
dinthes
imu
lat
or(
ani
mat
ions
)..................3
3
2
.38 Si
mula
tio
no fs
tepp
edmo t
ori
nEmu 8085...........................3 4
2
.39 Sc
ree
nshotofMicr
opr
oces
sorSi
mulat
or3...........................3 6
2
.40 Ti
mingdiag
ramofADDM i n
str
uct
ion ............................3 7

3
.1 Ite
rati
ve&I ncreme nt
a ldevelop
me ntmo de
l..........................4 0
3
.2 High -
leveloperationo ft
h esi
mu l
a t
o r.............................4 1
3
.3 Load i
ngi nst
ructi
o nsintome mo ry ..............................4 1
3
.4 Procedu reofloadinginstruct
ionintome mo ry.........................4 2
3
.5 Inst
ructione xe
c uti
onf l
o wchart...............................4 3
3
.6 Blockd i
a gr
amo fthemi cropr
ocesso r.............................4 4
3
.7 8-bi
t r
egisterdiagram ....................................4 5
3
.8 16-bitr
e gis
terdiagram ...................................4 6
3
.9 Inst
ructiond es
ign .....................................4 6
3
.10 Inte
r v
al defi
ningt heset ofavai
la
b leaddres
s e
s.........................4 9
3
.11 Me mo rya r
chit
e c
tu r
e....................................4 9
3
.12 Me mo rya r
chit
e c
tu r
einc ub i
cexpressedincubicfo
rm......................49
3
.13 Me mo rywr i
teo perat
ion...................................5 0
3
.14 Me mo ryreado perati
o n...................................5 1
3
.15 Fund ame ntala
rch i
tectureofastack..............................5 1
3
.16 Stackdes i
gn........................................5 2
3
.17 Stackpu sho pe
ration ....................................5 3
3
.18 Stackpo po per
a t
ion.....................................5 3
3
.19 Evaluati
o no fe
x p
r es
si
o nA+B+C ..............................5 4
3
.20 Evaluati
o no fe
x p
r es
si
o nA×B+C–D×E ..........................5 4
3
.21 Arit
h meticlogicunitarch i
tec
ture...............................5 5
3
.22 Flowcha rtofsubtract
ionp rocedure..............................5 6
3
.23 Fir
st c
o mp il
errunp roced ur
e.................................5 9
3
.24 Secondc o mpil
e r
'sruna ndma chineco degener
a t
ion ......................6
0
3
.25 Userinterfacedesignlayo ut.................................6 1
3
.26 Ma i
nme nuo ptions.....................................6 2
3
.27 Registe
r, Sta
cka ndMe mo rymapi nter
facel
a y
ou tde
si
gn.....................6
2

4
.1 High-l
eveloperat
ionof thesi
mu l
at
or.............................6 4
4
.2 In
struct
ionexecut
ionp rocedur
e ...............................6 5
4
.3 Clockgenerat
or,descri
ptio
no f
thesi
gnal...........................65
4
.4 Si
mu lat
ionproces
se sdepic
ti
ngthecl
ockt
hre
ad.........................6
6
4
.5 Clockcla
ssdiagr
am.....................................6 7
4
.6 Regist
ercl
assdia
gram....................................6 8
4
.7 Memo ryclas
sd i
agram....................................7 0
4
.8 Reado pe
rati
onp r
o cedure..................................7 0
4
.9 Writeoperat
ionproc ed
ure..................................7 1
4
.10 St
ackme mo rydi
agra m ...................................7 2
4
.11 ALUc las
sd i
agra
m .....................................7 3
4
.12 Microproce
ssorcl
assd i
agram ................................7 4
4
.13 Gladeuseri
nterf
ace.....................................7 9
4
.14 ContentofXMLf ilep r
oducedbyGlade............................79
4
.15 Comp il
eroutputsho wninthet
extboxwi
dge
t.........................81

5
.1 Conte
ntoff
ir
st.
asfi
le.
Thescr
iptl
oadregi
ste
rAHwi thv
alue45dec,r
egi
st
erBwit
hval
ue30dec.
Theni
t
addsr
egi
st
erALa ndAH,andsubt
ract
sthevalu
eBfromregi
st
erAL...............8 5
5
.2 Compil
at
ioncomma nd–f
ist
.a
sfil
econtai
nstheas
sembl
ysourcec odet
obetr
ansl
at
edint
ob i
nar
y
f
orm ...........................................8 6

v
i
5
.3 Cont ent of t
hef irs t.
bcfil
e..................................8 6
5
.4 Exampl e2r esults......................................8 8
5
.5 Exampl e2r esults.Not ic
eALr egi
s tercont a
ins6 6 .......................8 9
5
.6 Stacka pproa chs olv i
ngthee x pres
s ion.Not icethea ddr es
s0 x
00inthes tackandt hecontentofAL
regis
ter..........................................9 0
5
.7 Bitsub sti
tution. Bits0u pt o8r epr es e
nt t
her egiste
r.Thef i
rs
trowisa ne mptyr e
g i
ste
r.Thes ec
ond
rowt r
ie stoi nsertnu mb er3 00a ndt helastrows ho wsthea ct
ualval
u estored ...........9 0
5
.8 Thel eftima g eshowst hec ontent of Bre g
ister(
6dec)a ndtheima geont herighthands i
dethec ar
rybi
t
setto1 ..........................................9 1
5
.9 Bc orrectlystores5i tera
tionsa sther eg
isterCwa sloade dwithdecimal val
ue5 ..........9 2
5
.10 ALr egisters tor
e sthes umof Bv alu etha t
isp er
for medi ne ac
hitera
tion.AHr egi
steri
su s
edt ost
ore
thenu mb erof i
tera ti
ons ...................................9 2
5
.11 Thehi g her8b i
tsc ont ai
nv alue0 Dha ndt helowe r8b i
tsthetra
nsfer
redv alue50h.........9 3
5
.12 Thea ddr essl ocation0 x100 0s t
ore sABCDa ndt hea ddress0x0001s t
or e
sEF0 0..........9 4
5
.13 Theg ra phs howst her el
ationb etwe e nthefreque ncya nddu ra
ti
onof s
imu l
ationof Sample1 ....9 9
5
.14 Theg raphs howst hereache dd el
a ysa tal
l f
reque nciesbyS ample1................9 9
5
.15 Theg ra phs howst her el
ationb etwe e nthefreque ncya nddu ra
ti
onof s
imu l
ationof Sample2 ....1 0
1
5
.16 Theg ra phs howst her eac
he dd elay satallfrequenciesfromb yS ample2 .............1 0
1
5
.17 Theg ra phs howst her el
ationb etwe e nthefreque ncya nddu ra
ti
onof s
imu l
ationof Sample3 ....1 0
3
5
.18 Theg ra phs howst her eac
he dd elay satallfrequenciesb yS a
mple3................1 0
3
5
.19 Errorpr ogre ssi
onf ora lls
a mpl e
s...............................1 0
4
5
.20 Screens hot showi ngt hesta t
eof me mor ya f
tert
hes i
mu l
ati
on.Theint ere
stedlocati
onsinsidethere
d
box............................................1 0
7

6
.1 MI
CP-
SIMu
seri
nte
rfa
ce..................................1
10

v
ii
Li
sto
fTa
ble
s
2
-1 Compu
tera
rchi
tect
ureandOrgani
sat
ionc
urr
ic
ulu
m...................... 9
2
-2 Summa
ryofr
e v
iewedsi
mu l
at
ors...............................3 7

5
-1 Ti
mingst
ati
st
ic
sifsi
mu l
ate
dscri
pt(usi
ngre
g i
st
ers)......................9 5
5
-2 Ti
mingst
ati
st
ic
sof s
imul
a t
edscr
ipt(
usi
ngstack
) .......................9 6
5
-3 S1
,S2andS3areass
emblyscr
ipt
sandonlycont
ainNOPi
nst
ruc
ti
ons..............9
7
5
-4 Sa
mple1measure
dv a
lues..................................9 8
5
-5 Sa
mple2measure
dv a
lues..................................1 0
0
5
-6 Sa
mple3measure
dv a
lues..................................1 0
2

v
ii
i
Cha
pte
r1

I
ntr
oduc
ti
on

1
.1 Wha
tisaMi
cropr
oce
ssor
?
AMicr
oproc
ess
orist
hehea
rthofever
ycomput
erba
sedsys
tem.Itproces
sesal
lda
tawit
hintha
tsyst
ema
ndcontr
ols
al
lde
vic
esconnec
tedtoi
t.Thus,itisa
ls
ocal
ledthecen
tralpr
ocess
inguni
t(CPU).Thes y
ste
m wi
thacent
ral
pr
oce
ssi
ngunit
,i
nput/
out
putdevi
ceandamemorys
tor
agecanbevis
u a
li
sedasi
nFigu
re1-1.

Memory
CPU I/O Devices
unit

Fi
gur 1:Compu
e1- terb
ase
dsy
ste
m

TheCPU c ontr
olsandprocess
esallda t
asentbyinp utdevicessuc
ha sak ey
board,mouseorthermome te
r.Iffor
ex
ampl e
,thetemperat
urerea
chesthecriti
calv
alu
e, theCPUha storeac
ttothene wsit
uati
onandpe r
formrequired
st
eps.Incompu te
rscie
ncethesestepsa r
ec a
ll
edi nst
ructi
onsa ndarestore
di ntheme moryunit.As e
q ue
nceof
i
nstruc
ti
onsthatperf
ormsthespeci
fi
edt as
kiscal
ledac omp ut
erprog
ram( St
okes,2
0 07
,p.11).I
ntheab oveexample
t
heCPUf et
chestheinst
ruct
ionspecif
ical
l
ywr i
tt
ent oha ndlethecri
ti
calte
mpe r
atur
ev a
luefr
om theme moryu nit
.
Thisi
nstr
ucti
onu s
uall
yasetofi
nstr
uc t
ionscoul
dfore xa
mpl eincr
eas
ethespeedofafantoredu
cethetempe r
atur
eor
si
mplyacti
vat
ea nal
arm.

1
.2 Wha
tisSi
mul
ati
on?
Si
mulati
onist
hei mit
ati
onof theoper
ati
onofarea
l-
worldproces
sors y
ste
moverti
me( Banksetal
.,
2009,p.
3).The
pr
ocessofimita
tionalwa y
sinvolve
sc r
eat
inganart
if
ici
alhist
orywhi chist
heno bs
erved.Theo ut
comesofthe
obs
ervat
ionar
et henana l
yse
da ndusedinthere
alsys
tem.S i
mulat
ionismost
lyu se
dt odescri
beabehavi
ourofa
modelofar e
alort heoret
ica
ls y
ste
m( sys
temtob eimple
me nted
) .Themodelthenena b
lesustoask“whatif

qu
esti
onsabouttherea
l oper
ati
onofthesys
tem.
Simulati
onha sb ee
na roundforatleast2000year
s.Bo a
rdg a
me ssuchasChe s
s(intheWe s
t)andGo( intheEas
t)
wereu se
da ssi
mu lat
ionof war
far
eforhu ndr
edsofyears.
Howe ver,s
imula
tiongai
nsmoreimport
anceint
heb egi
nni
ng
th
of20 c
entur
y ,wherei twasmainlyassoci
ate
dwitht headventoffli
ghtsimul
ati
on.Inthenewera wherethefi
rs
t
compu ter
sstar
tt oeme rge
, ac
ompu terbase
ds i
mulat
ionaris
esalongsi
de.Regar
dle
ssofti
me,si
mu l
ati
onhasb e
enone
ofthepos si
blea pproa
c hestoovercomeapr oble
m( e.
g.,pl
anec ra
shesdu etopil
otinex
peri
enc
eort hene edf
or
i
mpr ovedd ec
isionma ki
ng)( S
okolowskiandBanks,2
0 09,p.2
4 8
) .

1
1
.2 Whyus
eSi
mul
ati
on?
S
imul
at
ionisave
ryimpor
tantpa
rtofre
sear
chands
yst
ema
nal
ysi
s.Mc
Hane
y(2
009
,p.4
1-4
3)po
int
edo
utf
iv
e
i
mpor
tant
adva
nta
gesov
erot
herdes
ignt
echni
que
s.

 S
imula
ti
onAllowsExpe
riment
ati
onwit
houtDisr
upt
ion
st oExi
st
ingSy
ste
ms.Impl
ementi
ngnewide
astoan
e
xis
ti
ngsyst
emma ybecostl
yorimpos
si
bletoachi
eve
.Forexamplei
ncarmanuf
act
urewhe
repr
oduct
ioni
s
r
unconst
antl
y,i
mple
me nti
nganewuntes
tedfe
atur
ema yca
usepr
oducti
onto.
 AConc
eptCa
nBeTe s
te
dPriort
oIns
tal
l
ati
on.S
imu
lat
iont
est
ingma
yre
vea
lunf
ore
see
nde
sig
nfl
awsa
nd
a
ll
owst
hedes
igne
rtoi
mprov
ethemodel
.
 Spee
dinAn a
lysi
s.Thisisoneoft hemos timportantadvanta
gesofsimulati
on.Aft
eramode lha sbeen
deve
loped,i
tispossi
bletorunthesimu l
ate
dsys
tema tspeedsmu c
hhigherorinsomecasesa
tlowerspeeds.
Forexample,inami c
roproces
sormov ingdat
af rom oner e
gis
tertoanotherisdonei nafract
ionofa
micr
osecond.Toa ni
ma t
ethisproc
essthesimul
at
ionwou ldberunatamu chlowerspe
edsothattheproc
e s
s
canbecaptur
e dbytheuser.Inl
ong-te
rmpr oc
essessuchastheEart
hrevolv
ingaroundtheSunthespeedof
si
mu l
ati
onisincr
easedandthesimulat
ioncanbeaccomplis
hedinafewseconds.
 For
ceSyste
m Def
i
niti
ons
.Thedevel
opmentofsimul
at
ionforc
esthede
sig
ner
stoimple
me ntaful
lydef
ined
modelincl
udi
ngallit
sexpe
ctedpar
amete
rsthatar
er e
quir
edtooper
ateit
.Ift
hesyst
em hasincomple
te
def
ini
ti
onstheout
putoft
hesimul
at
ionwil
lofcour
sebeinc
orre
ctands
uchamodels
houldnotbeusedasan
ana
lys
istool
.
 Enhance
sCreati
vi
ty.Desi
gni
ngamodelmightreveals
ever
alposs
ibl
esol
uti
onstoaprobl
em.Onesol
uti
on
mightbemor eexpensi
vebu
twil
lwork
.Theot heronema yre
quir
eimple
me nt
inganewtec
hnol
ogya
ndis
l
essexpens
ivecompa r
edtot
hef
ir
sts
olut
ionbutissomewhatr
isk
y.

Si
mu l
at
ionisnotafl
awle
s sapproac
hwhi c
he ns
urest
hatt
hesyst
emwi l
lbeha
vecorr
ect
lyine
verys
it
uati
on.
Ita
ls
oha
s
i
tslimit
ati
onsa nd di
sadv a
ntages
.Ne ver
thel
ess
,thenu mberofa dvant
age
shi g
hlyoverc
omet henumbero
f
di
sadva
ntages
.There
for
e, theli
stofdi
sadv
antag
esisc
onsi
dera
blyshor
terMcHaney(2009
):

 Cos
to fd
evel
opment.Model
sofcompl
exsystemarever
ydif
fi
cul
ttocre
ateandoft
enitisave
rye
xpens
ive
met
hodofa nal
y s
is
.Inaddi
ti
on,asof
twareandinsomecase
shardwar
ehast obeava
il
abl
eorpur
chas
ed.
Pe
rsonnelt
rai
ninglea
rni
ngcur
veex
pense
sa r
eals
oass
oci
ate
dwithcos
tofdev
elopment
.
 TimeCo ns
umin
g.Crea
ti
onofacompl
i
cat
edmodeli
stimecons
umingandi
nmos
tca
sesda
tac
oll
ect
ion,
anal
ysi
sandre
port
genera
ti
onwi
l
lre
qui
rec
ons
ide
rabl
eamountof
timet
oo.
 Dif
fi
cul
tyinInt
er
pre
ti
ngResu
lt
s.Beca
useoft
hest
ati
st
ic
alna
tur
eofmode
lst
hes
imu
lat
ionha
stob
eru
nma
ny
t
imesbeforei
ti
sposs
ibl
etoachi
evere
li
abl
edat
a.
 I
napprop
ria
teUseo
fModell
i
ngS
imu
lat
io
n.I
nappr
opr
ia
teu
seofmode
ll
ings
imu
lat
ionwhe
nana
nal
yt
ic
al
s
olu
tionwouldb
ebes
tsu
ite
d.

1
.3 Si
mul
ati
oni
nEduc
ati
ona
lCont
ext
Micr
oprocess
orarchit
ectu
rea sas ubj
ectist
aughtata nu ndergr
aduat
el evelatmos tunive
rsiti
esintheUK.The
cont
entofthesu
bjectispr
imarilyf
ocuse
donc omputerhardwa r
earchi
tect
u r
ea ndlow-l
evelpr
og ra
mmi ng.I
npracti
ce
i
tisadiff
icul
tsubj
ecttoteac
ha si
tcover
salargear
eafrom b as
iclogi
cgatestoc omplexdigi
talci
rcui
ts.Pr
iortothe
micr
oprocess
orarc
hitect
urethes t
udentshou
ldha veawor kingknowledgeofdi git
alcir
cuit
s( ta
ughtinelect
roni
cs
cour
ses
),somebackgroundinu nder
sta
ndings
e mic
onductorsandak nowledgeof atl
eas
tonehig h-l
eve
lprogra
mmi ng

2
l
ang
uag
eisb
ene
fi
ci
al(
Wik
iboo
ks,
201
0).
Aty
pic
alu
nde
rgr
adu
atec
our
ses
yll
abu
swo
uldi
ncl
ude
:

 c
ompu
ters
tr
uct
ure–pr
oce
ssor
,me
mor
y,I
/O,
bus
es,
cloc
k.
 da
tar
epr
ese
nta
ti
on–b
ina
rya
ndh
ex.
 me
mor
ysy
ste
m–pr
inc
ipl
esof
memor
yhi
er
arc
hy,
cac
hes
,ma
ina
ndv
irt
ual
memor
y.
 CPU–s
impl
eint
erna
lst
ruc
tur
e,r
egi
st
ers
,ar
it
hme
ti
clog
icu
nit
.
 i
nst
ruc
ti
ons
ets–s
ynt
ax,
sema
nti
cs,
addr
ess
ingmo
des
.
 da
tas
tr
uct
ure–s
tac
kma
chi
ne.
 b
asi
cpr
oce
ssori
mpl
eme
nta
ti
on–b
asi
cst
epsof
exe
cut
ion,
int
err
upt
s.

Atf i
rsts i
ghtami croprocessorma yb es eenb yas t
u dentasab lac k-
b oxwhos econt ent
si sf art ooc omplext o
understand. Te achingt hesu b
jec tproperlyindetailrequ i
resma nyha rdwa rea ndsoftwaretools.Thei ncr
e aseinuseof
microproces sorf orthes olepu rposeofmoni t
ori
nga ndc ontr
olha sb roughtne wt rendsinmi cr oproc es
sore ducati
on
(Edwa r
ds ,1 99 9).The set ypesofami croprocessorsa rec al
ledmi crocontroll
ers(MCU) .Mi croc ontroll
ersha veb een
widelyadopt e db ymos telectri
c a
le ngineeri
ngde part
me nt
sa sat e achingt oolfori t
sr ela
tivelyl ow pr icebutt he
drawbackof theset oolsistheirsimplici
tya ndhardwa relimi t
ati
ons.MCUt ypicall
ycontainsapr oc e
ssorc ode ,memor y
and prog ramma b l
ei npu t/outpu tinterface
.Thes choolofEng inee r
inga tGr if
fit
h Uni vers i
tyi n Au st
ral
i
aha s
succes
sfullya pp lie
doneoft he seMCUs :Mot orol a6 8HC1 18 -
bitmi crocontrol
lerint heirt eachinga ndlearning
process
. Althou g h,themi croproc es
sorisol dtechno logya ndha salimi teda mou ntofRAM, i
twa sr eve
a ledthatitis
rat
hera na dv antagei nt hei ntroductoryc ours
e s.S tudentswe ref orcedt oc onsi
dert heselimi tsi nt heircoding.
Cons e
qu ently ,theywe reencou ragedt ou nder
takeade tai
ledde s
ignr athe rthandirect
lyc odeapr ogram( Edwa r
ds,
1999).
Ont heot herhandt herearemi c
roprocessorde velopme ntsy st
emswhi c
ha restandal
onede vice
st hatcanpe rf
orm
morec ompl e
xop erat
ionsincontra
sttob asicmi crocontrol
lersbu tthedisa
dv a
ntageisthehighpr i
ce. Mostelect
rica
l
engi
ne er
ingde p
a rt
me nt
sintheUKc annota ff
or dpu rchasi
ngt hesesyste
msf oreachstudent,duetolimitedab udget
whichha sb eena ffect
edb yt hec u
rrente conomi cc l
ima t
e.TheEu ropeanUni v
ersi
tyAs soci
ation( EUA)ha s
i
nvesti
g a
tedthei mpactoftheeconomicc ris
isonEu ropeanhig hered uc
ati
ons yst
emss i
nceitsbegi
nni ngi
n2 00
8.The
i
nvesti
g a
tionfocusedonb othpu bl
icandpr iv
a t
ef unding.Ther epor trev
eal
st hattheUKu niver
si
tiesbelongtot he
groupofu nive
rsit
iesthathaveb e
enmos taffectedb ythec ri
si
swhi chr es
ult
sinf ewerst
udypr ogramme sa ndcutsin
t
e a
chingb udget
s( EUA, 2010).Asar es
u ltstudentsa r
ethe nu sual
lya s
si
gnedtoag r
oupa ndthee q
u ipmentisshared
whichshor t
ensthetimeforeachofthestude ntstoe xperi
me ntwiththede vi
ce(Jeon,2000).

1
.4 Me
thodol
ogy
Theini
ti
alpar
tofthisproj
ectst
art
edbyane x
tensi
veresea
rchabou
tmicropr
oces
sora r
chit
ect
ures
.Theinte
nti
onwas
togai
nthefundamentalknowledg
eofthegenera
larchit
ect
ureofmicr
oproc
ess
ors.Afterthi
spre
li
minaryres
ear
cha
si
mplearc
hit
ectu
rewa schosentobea
doptedfortheproj
ect.Moder
nproces
sor
sha veav e
rycompli
cat
eddesi
gnand
wouldrequi
remu chmor etimeforr
esear
ch.The r
efor
e,thei
rcomplex
itywasinappropri
at
eforthescopeofthi
s
proj
ect
.
Simpl
earchi
tect
ureabl
eofdes
igni
ngandimple
me nt
ingwit
hint
het
imel
imi
tswer
eusedar
oundt
he1980
's.Oneof
the
mostpopula
rwa sInt
elMCS -
51(micr
ocont
roll
er8050/8
051)whi
chIdec
ide
dtoadoptduet
oit
sre
lat
ivesi
mpli
ci
ty
andcapa
bili
ti
eswhichf
ulf
il
theini
ti
alr
equi
rementss
etint
heTOR.
Oneof theobject
iv
e softhi
sproj
ectwastodevel
opatool t
hatcoul
dbeu s
edinte
achingint
roductorymi cr
oproces
sor
cours
es.The r
efor
e,ar esear
chwhicha i
msa tsi
mulat
ionu s
edine du
cati
on,par
ti
cularl
yatengine e
ringschoolswas
conduct
e d.Manyu niv
ersit
ie
saroundtheworldhav
eus e
ds i
mulat
ionwit
hinthet
eachingpr
ocessa ndithasprovedto
beoneoft hekeypa rt
sinthelea
rningproc
ess.I
nthereportIhav
ede s
cri
bedrea
l-
li
fee x
ampleswhe resimula
tionhas

3
s
igni
fi
cant
lyi
mpr
ove
dtheov
era
llu
nde
rst
andi
ngof
ther
el
at
eds
ubj
ect
.
I
nCha pte
r2 ,thel
it
eraturerevi
ew,Iha v
eanal
yse
dtheg ener
alinter
nala
rchi
tec
tureofmi c
roproces
sors,memory,st
ack
a
ndc ompiler.Myi ntentionwa stoma k
ethi
spa rtinte
resti
ngforthereaderandi ncludepracti
calexamplesof
i
mplementati
on ofe achp art
.The ref
ore,Ibri
efl
yde scri
bedt hefundamentalarchit
ectur
ene ededf ordeeper
u
ndersta
ndinga ndincludea nexampleofimpl
ementat
ionwi thlogi
cgat
eswhichwa ssimulate
da ndtest
edinS i
mc i
r
t
hecir
c ui
tsimu l
at
or( Arase,2010).Pri
ortosi
mu l
ati
on,Iinde tai
ldes
cri
bethede s
ignproc e
ssrequir
edforb ui
l
ding
s
uchac ir
cuit.Someoft hee xa
mpl eshavebe
ena doptedfrom li
ter
atu
rewhichIa lt
e r
edt osuitthepro j
ectbutI
i
ncl
udedmyowne x
a mples.
Aft
ertherequire
me ntscol
lect
ionpha se,Idesig
nedeachinternalpar
ta nds tar
tedimpleme nti
ngitalongsi
det he
desi
gni
ngphase.Iu s
edwha tseemedt omet hesi
mples
tpossi
b l
eapproacha ndduetothes copeoftheproject
, Iwas
notyet
awareof,themostsuit
ablemode l–It
e r
ati
ve&Incr
eme ntal
mode l.
At eachit
era
tionId evel
opedonep ar
tIh ad
aworki
ngcopyofs oftwa
rereadytos howtomys uper
vis
or.Then,addit
ionall
ya tea
chiterat
ionIanaly
sedthec urr
ent
st
ageofdev
elopme ntandifre
qu i
redIa l
ter
edthedesi
gnandcons e
qu e
ntlytheimplement a
ti
on. Usi
ngthi
sa pproachI
ensu
redtha
tifthesoftwar
eisnotfull
yimpleme nt
ed,
ther
ewou ldsti
llb
eawor ki
ngcopyt opresent
.Idi
dnoti nt
e ndto
useanyspec
ialde v
elopmentenv i
ronmentandIonl yusedclas
sic
a lt
exteditor(vi
m).Al lcodewa scompiledu s
ing
GNUc ompiler–g c
c).
Bef
oreimple
me nt
ingt
heuse
rinte
rfa
ce,
Iexaminedothe
rsimul
ators
oft
wa r
e.Therese
archconsi
st
edofac
cumula
ti
ng
adv
anta
g e
sanddisadv
ant
age
sofwha tt
heu s
erint
erf
aceshoul
dincl
ude.Ther e
vie
wwa sconcer
nedaboutb
othfre
e
si
mulat
orsandlic
ense
dsi
mu l
ator
s.Int
hispar
tIde f
ine
dt heai
msoftheintendeduse
rinter
fac
eanddrewthefi
rst
des
ignl
ayout.
Ide ci
dedtolearngtkmmgui l
i
b r
arywhichistheoff
ic
ialC++i nte
rfaceforGTK+t ool
k it.Thereasonforchoosingthi
s
l
ibraryovera l
ter
nati
veQTi st
hatIdonotha v ea
nye xperi
encewithKDEe nvi
ronme nt .
The r
ea r
ev eryfewexa mple
s
ont heinter
ne tandlea
rni
ngtheGTKl ibr
arywa sadiffi
cul
tt a
skt oaccompli
sh.Dur inglear
ningt helibr
aryIc ame
acrossGladewhichisause
rinter
facedesi
gnersof
twareforGTK+t oolk
itandGNOMEde skt
ope nvironment.Te s
ti
ng
thi
sde sig
ningt oolhasconvincedmet ou seittode signmyi nterf
ace
.Oc casi
ona ll
yIha dt oc onta
cte xper
t
programme rsontheGNOMEI RCc ha
nnelonapa r
ti
cu l
arproble
mwhi chIcou
ldnot identif
yorre s
olvemy s
elf
.

4
Cha
pte
r2

Li
ter
atur
eRe
vie
w

2
.1 I
ntr
oduc
tion
Thel i
ter
atu
rerevi
ewc ha
pteri sdi
videdi ntothreema i
nsecti
onsSimul
ati
onu s
edine ducati
on,Mi cr
oproces
sor
arc
hite
ctur
eandrevie
wofexist
ingsi
mu l
at
ors.Thefir
stpar
tdescr
ibe
showsimulati
onha sbee
na ppli
edineducat
ionat
undergr
aduat
elevel
.Thesecondp a
rtde sc
ribestheel
eme nt
arypar
tsofamicroproce
ssorsucha sreg
ist
ers
,memor y
ari
thmeti
cunitet
c.Eache
leme nti
sdes c
rib
e dindetai
landsi
mplecir
cui
tex
ampl eshavebeende v
e l
opedtoprovethe
the
oreti
calconce
pt.Thel astparta nal
ysesthee xi
sti
ngs i
mu l
at
orsand f
inall
ye valu
atesthe i
radvant
agesa nd
dis
advant
ages.

2
.2 Si
mul
ati
oni
nEduc
ati
on
(
Kas
im&Al
-Au
bidy
,20
07)
TheCompu terEngi
neeri
ngDe p
artmentatPhi
ladel
phi
aUnive
rsi
tyincor
porat
edmicro-oper
ati
onsi
mu l
at
ion
andFPGAi mplementat
ioni
ntoateac
hingtoolf
ortheCompu t
erOrga
nis
ati
ona ndArchi
te
cturecours
e.FPGA(Fiel
d-
progr
amma bl
eg a
tearray)i
saninteg
rate
dc i
rcui
td e
sig
nedtob epr
ogra
mme dbytheendu ser
.AS I
C( Appl
i
cati
on-
speci
fi
cint
egr
atedc i
rc
uit)i
sincontr
astdesi
gnedforap ar
ti
cul
arus
e,ra
therthanforgene
ralpu r
pose
.Accor
dingto
Xili
nx(201
0),advant
agesofus
ingFPGAov erASICare:
 f
ast
ert
ime
-to
-ma
rke
t
 e
li
mina
ti
onof
thehi
ghc
ompl
exi
tya
ndt
ime
-cons
umi
ngd
esi
gnof
ASI
C
 f
ie
ldr
epr
ogr
ama
bil
i
ty
Theunder
graduatecoursecons i
st
sof desi
gningasetofmicr
o-oper
ati
onswhic
ha r
ethe nimplemente
donFPGA.The
mainobj
ect
iveofc ours
eistode signasimpl ecomputercap
ableofex
ecut
ingvari
ousmi cr
o-opera
ti
ons.
Components
su
chasmainme mor y,r
egis
tersaredesig
ne du s
ingVeri
l
ogHDL. Ver
il
ogHDLi sahardwa r
edescri
pti
onl
ang
uageu
s e
d
t
ode s
cri
bedigi
talc i
rc
uits
.Ac ommona pproachistodesi
gneachint
egra
tedcir
cui
tc hipbyu s
inganHDLa ndt
hen
ver
if
ythesy
stem'
sf unct
ional
ityv i
asimulat
ion( Pal
ni
tkar,
2003).
Tos
pec
if
yther
equ
ire
dcompone
ntsas
pec
ial
sof
twa
rewa
sde
vel
ope
dfors
tude
nts
.The
sec
ompone
ntsa
re:
 ma
inme
mor
ysi
ze
 t
ota
lnu
mbe
rof
ins
tr
uct
ions
 t
ypeof
ins
tr
uct
ion-
memor
yre
fer
enc
e,r
egi
st
err
efe
renc
e,i
npu
t/ou
tpu
tre
fer
enc
e
 a
ddr
ess
ingmode
s
 s
tat
usf
l
ags-
car
ryf
l
ag,
zer
ofl
ag

5
Thes
ep a
ramete
rsaret
henst
oredinafi
lewhichisuse
dbyVeri
logHDLt obuil
dthere
qui
reda
rchi
te
ctu
re.
Oncet
he
pr
ogram ha
sb e
enwr i
tt
enthemi c
ro-
operat
ionscanbeent
ir
elysi
mu l
at
edb ythesi
mula
tori
ncl
udedint
heXil
i
nx
Deve
lopmentEnvi
ronment
.It
wa sf
oundforstude
ntst
obepar
ti
cula
rimport
antt
o:
 u
nde
rst
andt
hepr
oce
ss
 c
ompa
ret
heob
tai
nedv
alu
esf
romt
hes
imu
lat
iont
oconf
ir
mwha
tise
xpe
cte
d
Thet e
achingtool
isau s
efu
l pr
act
ic
aladdit
iontocomputere
ngine
eri
ngandcomputers
cienc
ecurr
ic
ula
.Thist
eachi
ng
toolhel
psc omputersci
encestu
dentstofamil
i
a r
isepr
act
ica
ll
ywithcompute
rorgani
sat
ionandarc
hit
ect
uret
hrough
devel
opme ntoftheirowni ns
tr
uct
ions e
t.Studentst
hatuse
dXili
nxb o
ardspe
rformedb e
tte
rwhentheyusedthi
s
teac
hingtool.

(
Chu
dae
tal
.
,20
09)
Anothe
re x
ampleofsi
mulat
ionusedineduca
ti
onwa sappl
ie
dintheComputerSc
ienc
ec our
seatSl
ovak
Techni
calUnive
rsi
tywhereRAM (Random Acc
essMemory)si
mu l
at
orswe
repre
sent
edtostude
nts.RAM r
efe
rsto
rea
dwriteme moryuse
di ncompu
tersasastor
agecomponent
.Thus,RAM i
safundament
alpartofathe
oret
ic
al
comput
erscie
nceandengi
neeri
ngc
ourse.
Theramsimu l
ator
swereus
edinbot
hlect
urer
sandpr
act
ic
alc
ourse
stoexpl
ai
nthef
unct
ionofRAM. S
tudentsus
ual
ly
appr
eci
atetheclar
it
yofex
plana
ti
onandarequi
ckl
yabl
etodes
ignthe
irownRAM pr
ograms.
Stude
ntsarethengi
ven
anas
sig
nme nttosol
veapr
oblemtha
tinc
ludes
:
 c
rea
ti
ngaRAM pr
ogr
amwhi
chs
olv
esapa
rti
cul
art
ask
 e
val
uat
etheRAM c
ompl
exi
tyme
asu
resof
the
irpr
ogr
am
Ov
erape
ri
odof
timet
hea
dva
nta
gesa
nddi
sadv
ant
age
sof
usi
ngRAM i
nsi
mul
at
ionwe
rec
onc
lude
d.
Ad
van
tag
es
 v
isu
ali
sat
ionof
compone
nts
,compu
tat
iona
ndr
esu
lts
 q
uic
kunde
rst
andi
ngof
thec
onc
ept
s
 e
aseof
prog
ramde
vel
opme
nt
 i
mme
dia
tef
eedb
ack
Di
sad
van
tag
es
 hi
ghe
rcou
rser
equ
ire
ment
s(t
eac
her
s's
kil
l
s,c
las
srooms
,eq
uipme
nt)
 a
ddi
ti
ona
lcou
rsepr
epa
rat
ion
 s
imu
lat
iond
oesnotpr
ovi
det
hev
iewof
mor
ecompl
ext
heor
eti
cal
aspe
ctsof
RAM
S
tudentsha
veshownapart
icul
ari
nte
resti
ncre
a t
ingthei
rownRAM prog
ramsa
ndgene
ral
lywerev
erysu
cce
ssf
uli
n
a
chie
vingthegoal
s.Ontheotherhand,thet
he ore
tic
alana
lys
isoft
hecompl
exi
tymeas
ures
,werenotve
rywell
u
nderst
ood.Twoma i
nre
asonswer
econclu
dedforthi
sfai
lu
re.
 nos
imu
lat
ionh
ass
uchc
apa
bil
i
tie
sforr
equ
ire
dthe
ore
ti
cal
ana
lys
is
 s
tude
ntsdonoth
aves
uff
ic
ient
ski
l
lsi
nal
geb
raa
ndr
el
at
eddi
scr
etema
the
mat
ic
alme
thods
I
ntheacade
micyear2008
/2009st
udent
swer
easkedwhet
hers
imu l
at
ionwasahe
lpf
ult
ooli
nthec
our
se.8
5%
a
nswe
redposi
ti
vel
yors
li
ghtl
ypos
it
iv
ely
,8%ne
gat
iv
elyand7
%we r
eindi
ffe
rent
.

(
Mar
ti
n-De
l-
Bri
o,1
999
)
Att
heTe c
hnica
lEng
inee
ringS
chooloft
heUni
ver
sit
yZa
ragosami
cr
ocont
rol
l
ersy
ste
msaretaughti
nthe
s
ubj
ectEl
ect
roni
csIns
tr
ument
ati
on.The8-
bitmic
roc
ont
rol
l
erMot
orolaM68HC11isus
edinthec
las
sro
om.Itisa

6
r
el
ati
vel
ysimpl
edev
icetowor
kwitha
ndcompr
is
esofa
llt
hee
sse
nti
alf
eat
ure
sforac
ompl
et
econt
rols
yst
em:a
memory
,port
s,a
nA/Dconv
ert
era
ndat
ime
r.
The6 8HC11fami
lyc onsi
st
sofmor ethan5 0 de
vic
es,wit
h dif
fer
encesin me
moryand on-
chi
preso
u r
ces
.
MC6 8HC71
1E9isthemos tcommonpar
toft hef
amil
y,int
egr
ati
ng:256byte
sofRAM,8KByt
e sROM,512Byt
es
EEPROM,seri
alas
ynchronousandsy
nchronousi
nter
fac
e s
,A/Dc onve
rte
ra ndpr
ogr
ammabl
et i
mer(Motor
ola
,
1999
).
Inthiscou r
ses t
udentsle
a r
nthef u
ndamenta
lc onc
ept
s( ar
chi
tec
tur
esofi nter
nalblock
s)ofmi c
rocontr
oll
er,
pr
ogrammi nginasse
mb l
ylangua
geandstu
dythegener
alc
onceptofi
nte
rfa
cinginthefi
rs
tsta
ge.I
nthesecondsta
ge
st
udentsappl
ytheirga
inedknowle
dgeinpr
act
is
eu s
ingMotor
ola68HC11EVBU( Eva
luat
ionBoa
rdUniver
sal)boa
rd
i
nthelaborat
orie
sless
ons.
Thede part
me ntha sde vel
opedas oftwares imulatorVisual11b asedon6 8HC11 .Thes imu lat
orintroduce
sthe
arc
hitectureofthemi crocontr
oll
er,al
lowss tudentstopracti
sea s
semb l
yl anguageprog r
ammi nga ndbasicint
erf
aci
ng
concept s
.Visual11a l
lowss t
udentstoe x
ecu tethec odestepbys te
pme thoda ndimme diate
lyi dent
if
yt heres
ult
sof
ever
yi nstr
ucti
on. Thepr ogramcanru ncontinuo us
lyandb reak
po i
ntsca nbea dded.
Ita l
soi ncl
u desaspec i
alf
eat
ure–
ext
erna lperi
pheraldevices.
The s
ede vic
esa ree i
ghtlight
-emitt
ingdiode s,ei
ghtswit
che s,twos ev e
ns eg
me ntdis
play
s
andahe x
adecimalk eyboard.Vis
u al11i ncorporatesac ommu nic
ationt er
mi na
la ll
owi ngc ommu nic
a t
ionofthe
si
mu l
at orwithMot orolaEVBUorwi ththeb oa r
dt hestudentisinte
ndi ngtob uil
d.As semb lypr ogr
amswr it
tenby
st
udent sarecompi l
eda ndthensimu l
a t
edinVi s
ual1 1.Whent heprogra misde bu
gg ed,thema chinecodeg e
nerat
ed
bythes oft
wares i
mu l
atorisdownloadedtot heb oardforit
srealexecut
ion.
Thesoft
wa r
esimul
atorpr
ovi
desast
andar
dMS -
Windowsint
erf
ace,s
imula
tesaproc
ess
orcodeandsomeperi
pher
al
s,
i
nter
rupts
,me moryma pwithRAM,EEPROM,EPROM a ndcommu nic
ati
onwith68HC1 1b oa
rds.I
tdoesnot
i
mplementthewho l
esetofmodul
esav
ail
abl
eonboar
dsasitnoti
ntende
dt ore
plac
ether
e a
lhardwar
e.Thepur
pose
ofs
imulat
ionistoa
ll
ows t
udent
stol
ear
nandpra
cti
cebas
icmicr
ocontr
oll
erconc
epts
.
Tradi
ti
onal
ly
,st
udentshav
eu se
dac omma nd-
li
neori
entedsi
mulat
orsi
nt hepr
act
ic
a lc
las
ses
.Int
rodu
cingVis
ual11
hadaveryg
oodrespons
efromstude
ntsasl
e a
rni
ngthi
stooli
sfa
ste
rthancommand-l
ineori
ent
edsi
mu l
ator
sandbas
ic
conce
ptisu
nder
stoodquic
k e
randbett
er.

(
Mer
at&Chu
ng,
199
7)
Aninnovat
iv
ewe b-bas
eda pproa
chwa susedintheintr
oductoryc ours
etoCompu t
erArchi
te
ctu
reand
Organis
ati
onattheSchoolofElec
trica
lEngine
eri
nga tUniv
ers
it
yofBe l
grade.Thes i
mulat
orcal
le
dECOMPwa s
dev
elopedinprogr
ammi ngla
nguageJ a
va.However,ala
rgenumb e
rofs tudentsenrol
li
ngontothecour
secau
sed
eno
ur mouspr
essur
eont hela
borat
or yequi
pmentands t
af
f.Asaconsequenc ethesi
mu l
atorwasre
prog
rammedto
web-
b as
edenvi
ronment.
Thetransi
ti
ont owebenvi
ronmentbr
oughtsev
eraladvantage
s:
 s
tude
ntswe
rea
blet
opr
epa
ref
orl
abor
ator
yle
ssonsa
thome
 r
edu
cti
oni
nthet
imene
ede
dtos
ucc
ess
ful
l
ycompl
et
ethel
abor
ator
yex
erc
ise
s
 we
b-b
ase
dte
chnol
ogyr
edu
cedt
hec
ostof
ins
tal
l
ati
on,
upda
tesa
ndma
int
ena
nceof
thes
oft
war
e
Thevis
ualsi
mu l
at
orwa sr
aninawe bbrowserandha
dc a
pabil
it
ie
stoini
tia
li
seandcontrolt
hesi
mu la
ti
on.I
nit
ia
ll
y
st
udent
swereaskedtodef
inet
hec l
ockratef
orthesy
ste
ma ndtheacc
e s
stimeforper
iphera
ldevi
cesandmemory.
Theycoul
dalsodef
ineval
uesi
nthema i
nme moryandreg
ist
ers
.EDCOMPi ncl
udesaproces
sor
,mainme mo
ry,i
/o
su
b-sys
temandsomed u
mmype r
ipher
alcontr
oll
ers
.
Mosts
tudentswhousedt
h eappl
ic
ati
onfoundthegra
phica
lus
erint
erf
acev
eryint
uit
iv
ea nde a
sytole
arn.Thel
ect
ure
rs
a
ls
oo b
servedtha
tstud
entswhop r
epar
edforle
ssonsus
ingDCOMPwe r
ebett
erpre
p a
reda ndhadbet
terunder
st
andi
ng
of
thebas
icconcept
sofamicro
proces
sor
.Intr
oduci
ngEDCOMPh adasi
gni
fi
canti
mp ac
to ntheave
ragegra
dewhic
hhas
i
ncr
eas
edfrom7 8%to86%. Addi
ti
onal
ly
,stu
dentswhosucc
ess
ful
l
ypasse
dtheexamincr
easedfrom72%t o85%.

7
(
Fer
ense
tal
.
,20
07)
Limit
ati
onsandd if
fi
cult
iesinconvent
ionalle
c t
uresandvis
ualaid
sledthelec
ture
rsattheUn i
ver
si
tyo fMa ni
toba
,
Canadatocre
ateacustoma ni
mati
o nso
ftwareanduseiti
nthetea
chi
ngproce
ss.
Co mput
erengi
neer
ingi
sav er
yco mpl
ex
subj
ectandconventi
onalme t
hods(wri
ttentex
t,pic
tures
)hadb e
comeveryi
nsuf
fi
cie
ntfors
tudent
s.I
nr e
sponse,many
i
n s
tr
uctor
sstar
tedu s
ingthebenef
itofani
ma t
ion.Aninte
rac
tiv
eanimat
ionwoul
da l
lows
tudent
stoentert
heirownd at
a
andimme di
at
elyseethei
reff
ect
sintheanimati
on.
Th
eseo
bje
cti
vesf
ora
nima
ti
onswe
res
et:
 a
nani
mat
ions
howi
ngt
hei
nte
rna
lfu
nct
ionso
fami
cr
opr
oce
sso
r
 d
eve
lop
inga
nima
ti
oni
nwa
yst
hat
ares
upp
ort
edb
yta
ugh
tth
eor
y
 a
sse
sst
hemo
tiv
ati
ono
utc
ome
sins
tud
ent
s
Ani
mat
iont
hate
xpl
ai
nthecomp
lexi
nte
rna
lop
era
ti
onof
amic
rop
roc
ess
orwa
sde
vel
ope
dtos
upp
ort
tra
dit
iona
lte
ach
ing
met
hod
s.Themaj
orf
eat
ure
soft
heani
mati
ons
oft
war
ear
e:
 c
hang
eth
eco
nte
nto
fre
gis
ter
s,e
nte
rda
tai
ntome
mor
y
 c
ons
tr
uct
mac
roo
rmi
cr
oop
era
ti
ons
 a
nima
tet
hee
xec
uti
ono
fea
chmi
cr
oin
str
uct
ion
Th
eani
mat
ion'
sma
inp
agei
nth
eFi
gur
e2-
1co
nsi
st
sof
thr
ees
ect
ions
:
 t
het
opsec
ti
onsdis
pla
ysapa
nel
toc
onf
i
gur
emi
cr
oan
dma
cro
-op
era
ti
onsa
ndc
ont
rol
sth
eani
mat
iona
nd
e
xec
uti
onofi
nst
ruc
ti
ons.
 Th
emi
ddl
ese
cti
ons
howst
heb
asi
cmi
cr
opr
oce
sso
ran
dal
li
tsc
omp
one
nts
 t
heb
ott
oms
ect
ionss
howst
hea
tt
ach
edme
mor
y

Fi
gur 1:Us
e2- eri
nte
rfa
ceof
int
era
cti
vea
nima
ti
ons
oft
war
efr
om(
Fer
ense
t.a
l,2
007
)

Th
eani
mat
ioni
sba
sedo
nmi
cr
oop
era
ti
ont
hata
red
efi
nedb
yth
eus
er.
Eac
hmi
cr
oop
era
ti
oni
sas
eto
f77b
itsc
all
ed

8
cont
rolsi
gnals(controlv
ecto r
s)a ndareconf
igur
edtoimplementadesi
re
do per
ati
on.Theanimati
ons o
ftwar
eprovi
des
t
h es
tudentwitha no p
portu ni
tyt ole
arntocrea
teandimplementmicr
ooper
ati
ons.Macroo
perat
ionsarebuil
tontopof
micr
ooperat
ionsa nda r
eb in a
rye ncodedinto8b i
ts
,ther
eforethemaxi
mu mn umberofuniquema cr
oinst
ruc
ti
onsis
l
imit
edt o25 6.Th estudentsa reaskedtob ui
l
dama cr
oinst
ruci
tonbyprovi
dingit
sbinar
ye ncode
do pe
rat
ioncode
(opc
od e
),mne mo nic,de
stinati
o n,addr
essi
ngmo de,
numb erofmicr
ooper
ati
ons,or
dere
ds e
quenceofmi cr
ooper
ati
ons
andcondit
ionalcoderegi
sterc onfig
urat
ion.Eachmacro
instr
ucit
ondef
ine
sanu mberofmicr
ooperat
ions,
theyse
quence
andcontr
olvectorforeac
hmi cr
o opera
tio
n.
Theani
ma t
ionuses“
wa t
erfl
owingthr
o u
ghp i
pes”an
a l
ogytoshowthepathstheaddre
ssandd at
ataketh
roughoutt
he
mic
ropr
oc e
ssor
.Fu r
thermore
,t hepropag
ati
ono faddres
sandd a
tacorre
sp ondswit
ha nimat
ionofthecloc
kwh i
ch
vi
sua
ll
yindica
teswhenad d
res
sesandd at
apassint
oa ndthro
ughthev a
riousc o
mp o
nentso ft
hemicropr
o c
esso
rand
memory.Theanal
ogyals
op r
ovide
ssever
alot
heradvanta
ges–theti
merequiredtopropa
gatetheaddr
essanddat
atoit
s
de
sti
nat
ion,thecloc
kh asac on
sta
ntlydef
inedspe e
dl i
mitwh i
chc a
nno te x
cee
dt her equ
ire
da ddr
essandd at
a
pr
opaga
ti
o nti
me .
Du r
ingtheani
ma t
ionst
udentsar
ea bl
etoide
nti
fyconfi
gurat
ionerr
orsb ynot
ingth
ed evi
ceatwhi
ch
t
hefl
owstopped.

S
evera
lstudentsurv
eyswe reconduct
e din2005a nd2 0
06wh er
etheywerea sk
edi ftheani
ma t
ionhel
pedthem wit
h
u
nderst
andingthetopi
c.Inbothsurveysmo r
ethan8 5%ofres
ponse
sindi
cate
dt hattheani
ma t
ionacc
omp l
i
shedthese
t
o
fob j
ect
ive
s.Mo sts
tudents(over80%)r e
spondedp os
it
ive
lyast
owh et
herco mputerani
ma t
ionhel
pedthemtoreal
is
e
t
heint
ernalproc
esses
,thesequencesofevent
sandc lo
ckandtimi
ngo p
erat
ions.Th esur
veysal
soreve
ale
dthatst
udent
s
s
pentli
tt
leornoe xt
rati
mewi t
ht h
ea nimati
on(85 %).Alt
hough,st
udentsindi
catedself
-a
sse
ssedgai
ns,s
tat
is
ti
cal
lyit
h
adnos i
gnif
ica
nt i
mpactont h
eo ver
allpas
sgrad
e.

2
.3 Conc
lus
ion
Compu t
erarc
hitec
tureandorganisa
ti
oni sav eryimporta
ntpa rtoftheCompu ta
ti
onEng i
neeri
ngCu rric
u l
um
(Djordje
vic
,2 005)
.Thej oi
ntIEEE Compu te
rS oci
e t
ya nd ACM Compu te
rEng i
neer
inghasc onc
ludeda n
i
nv e
stiga
ti
onintoc ompute
rarchit
ect
urea ndorgani
sat
ionandi de
ntif
ie
dt hecorer
equi
rementsf
oru nde
rgraduate
progr
a mmes,showni nt
heTa bl
e1 -
1( IEEE& ACM,2 004)
.Thea b
str
actvie
wofthewholecompu te
rma chineis
cover
e dbycompu t
e rar
chi
tec
turewhileimple
me nta
ti
on detai
lsareinc
ludedincompute
rorgani
sat
ion(Cleme nt
s,
2000).

Fu
ndament
alsof Or
gan
isa
ti
ono
fth
e In
ter
fac
ingan
d
Co
mpu
terAr
it
hme
ti
c Ma
inMe
mor
y
c
omput
era
rch
itec
tur
e CPU Communic
ati
on

*organi
sationof t
he *s ingl
evs.mu l
ti
ple *r
epre
sentat
ionof *memor yhiera
rchy *I/ Of unda mental
s:
vonNe uma nn busdatapath i
nte
gers(pos
iti
ve, handsha king,
*mainme mor y
ma c
hine ne
gati
ve) buff
ering
*controluni
t or
ganisat
ion
*inst
ructi
onf orma t *arithme tic *I
/ Ot echniques:
*arit
hme t
icunit *l
atency,bandwidt
h,
al
gor ithmsf or pr
og r
amme dI/O,
*fet
ch/exec ut
ec y
c l
e,impl ementati
on cyc
letime,
addition, subtract
ion, i
nterr
u ptdr iv
en,
i
ns t
ruct
ionde coding per
formance
*inst
ruct
ionset mu l
tipl i
cati
ona nd DMA
andexecution
archi
tect
ure divi
sion *vi
rtualmemor y
*i
nterru pt s
tr
uctur
es:
*regi
ste
ra ndr egi
ster sy
stem,
*rela
ti
onships *repr esentationof ve
c t
ore da nd
f
iles
,
betweenthe realnu mb ers *cacheme mori
es pr
iori
tise d,i
nter
rupt
*progra
mmi ngin archi
tect
ureandthe (fl
oat i
ng -point over-
he ad ,i
nter
rupt
s
*memor y
asse
mb l
yla nguage c ompiler ari
thme ti
c ) andre-en tra
ntcode
i
nterl
eavi
ng
*t
rendsi
ncompute
r *c
onv
ers
ions *b
use
s:c
loc
k,
*me
mor
y
ar
chit
ect
ure
:CIS
C,

9
RI
SC,
VLI
W b
etweenr
eal
and tec
hnologie
ssuc
ha s contr
ol,
addre
ssand
i
nte
gernu
mb e
rs ROM, SRAM, databus
es,
DRAM, EPROM, a rbi
tr
ati
on
*hardwareand
Fla
sh
sof
tware *paral
l
elandser
ial
i
mpl ementa
tionof *rel
ia
bili
tyander
ror i
nterf
aces
ari
thmet
icuni t corr
ect
ion
*ti
me r
s

Ta
bl 1:
e2- Compu
tera
rchi
te
ctu
rea
ndOr
gani
sat
ionc
urr
ic
ulu
m(I
EEE&ACM,
200
4)

Softwaremi cr
op roc
e ssorsimu l
atorsh a
v eb eenwi delya do pt
edine du c
atio
na lc o
nc eptineng i
neeri
ngd epartme ntsat
mo stuniver
sit
iesinth ewo rl
d.Th emo st i
mp o r
tantad va ntagesoverrealmicr
o comp uterpla
tformsarethatsimulatorsare
general
lylessexpensivea ndmo ref l
exibl
ea nda pp r
op riateforintroductor
yc ourses.Add i
ti
onall
y,graphi
c a
l pr
esentation
anda nimati
o nh elpst ob ett
eru nde r
st
a ndt hei nte
rn alp rocessesandf unctional
it
yo fami cropro
c e
ssor( Djordjevi
c,
200 5)
.Awe l
ldesigneds imu l
at
orc anah aveama jora ffectont hequali
tyo fthee ducati
onalprocess.
Us i
ngs i
mu l
ators
al
o ngsi
dec l
assi
cal t
eac hi
ngme t
ho dsc a
ns i
gnif
icantl
yi mp rovethefinalres
ultsa ndu nders
tandingoftheta ughtsub j
ect
(Ch uda,2009,Me r
a tandCh ung ,1997 ).Studentsa reg eneral
l
yv eryenthu si
asti
ca boutu s
ingsimu l
atorsasth eyc a
n
s
imu lat
ea ndt e
s tpro ces
sesp ri
ort othe irrealimp l
eme nt
a t
iono nami c
rop ro
c es
sor( Kasi
m & Al -Aubidy,200 7).An
animationcanh elptov isual
iseandd e
mo nst
ratet h
ei ns tru
c t
ionflowe xec
u t
ion, whi
c hinsomec a
sescanb ep ar
ticular
ly
i
mp or
tanttos omes tu dentswh oc annoti ma g
ineo ru nd e
r s
tandthep roces
sf rom no tes(Ferenseta l
.,2007).Au ser
i
nte r
faceisanimpor tantp artofev e
rys oftwareincludi ngs imu l
at
ors.Ithasb eenfou ndthatstudentsar
emor elikel
yt o
uses i
mu l
ati
onou ts
ideofo bli
gatoryl a
b oratori
esl e
ss onswi t
ha nea s
ya ndi ntuit
iveinter
face( Marti
n-De l
-Brio,19 99
andMe ra
t &Chu ng,1 997).

2
.4 I
ntr
oduc
tiont
oMi
cropr
oce
ssorAr
chi
tec
tur
e
Int
roductiont oMi cr
oproce
ssorAr chite
ctur
ede s
cri
bestheg enera
larchit
ect
ureofmicroproces
sors.TheMOS
Technolog y6502micropr
oces
sorisbee nchose
na sanint
roducti
ontothetopi
cduetoit
sre
lat
ivel
ys i
mpledesi
gn.The
fi
rs
tpartofl it
era
turerevi
ewdisc
ov e
rst he6502a r
chit
ect
u r
ea ndit
sparameter
s.There
stofthechapterdesc
ri
b e
sin
det
ailthemos ti
mportantpar
tsthatt hemi c
roproces
sor–Re g
ist
ers
,ALU,t i
mingandcontrol
,inst
ructi
onsetand
memor y.Ea c
hpa r
thasbeendesi
gna nds i
mu l
atedinSimci
rsimu l
at
or(Arase,
2011)s
oft
waretoprovetheconcept
.

2
.5 Mi
cropr
oce
ssor6502
TheMOSTe chnol
ogy6502isan8-b
itCPUt ha
twasdesi
gnedbyMOSTe chnol
og yi
n1 97
5.Whenitwa
sintr
oduce
d
onthemarke
tthec os
twasl e
ssthatone-
si
xthofthepri
ceofcompeti
ngde s
ignsfrom l
ar
gerc
ompaniessuc
ha s
Motor
olaa
ndIntel
(Wikipe
dia,20
11c).I
twasori
gi
nall
ymadefore
mbeddedsyst
ems .
The6 502hasa16b i
taddre
ssbusandcanacc
essama x
imu
mof64Kbofme mory
.Thespeedoft
hemicr
oproce
ssor
wasthesamea st
heext
erna
lcloc
krate
,whic
hwa sa
round1to2
MHz .
Eve
nt hou
ghotherCPUsuse
dfa
ste
rclock
s,the
6502provedtohaveacompet
iti
veper
for
mancedes
pit
ethel
owspe
ed(Wi
kipedi
a,201
1c).
The6
502
'sr
egi
st
ersi
ncl
ude(
CPUWor
ld,
201
1c)
:
 8
-bi
tac
cumu
lat
or(
A)
 t
wo8
-bi
ti
nde
xre
gis
ter
s(Xa
ndY)
 8-
bit
proc
ess
ors
tat
usr
egi
st
er(
P)
 8
-bi
tst
ackpoi
nte
r(S
)

1
0
 1
6-b
itpr
ogr
amc
ount
er(
PC)
Fi
gur
e2-
1fr
om(
Fol
ty
n,1
997
)showst
hei
nte
rna
lar
chi
te
ctu
reof
650
2mi
cr
opr
oce
ssor
.

Fi
gur 2:I
e2- nte
rna
lar
chi
te
ctu
reo
fMOSTe
chno
log
y65
02mi
cr
opr
oce
sso
r

2
.5.
1Ar
it
hme
ticLog
icUni
tAr
chi
tec
tur
e
TheAri
thmeti
clogi
cunit(ALU)isadi
git
alci
rc
uitt
hatper
for
msa ri
thmeti
candl
ogic
alopera
tions(
Maini,
20 0
7 )
.Iti
s
t
hehearthoftheint
ernalarc
hit
ect
ureofeachmicr
oproces
sor.Theinter
nala
rchi
tec
tureofALU iscompos edof
ar
it
hmeti
cunit
se a
chprovi
dingamathe
ma t
ic
alfu
ncti
on,f
orexamplediv
isi
onors
ubtr
acti
on.Ithast
woinputsandone
out
putf
ortheres
ult(
Figure2-
3).
Fi
gur
e2-3sh
owsthebl
ockdia
gra
mo fALU.AandBarethei
npu
tvar
iabl
esonwhi
cht
heoper
ati
oni
sper
for
med.Th
e
f
ig
urebe
lowcont
ai
nst
hetru
thtab
leo
f a
vai
l
abl
eoper
ati
ons
.Eac
hoper
ati
onisaco
mbi
nat
iono
f3bit
s–S0,
S1andS
2.

1
1
A B

S0 Z
S1 C
S2 ALU
CA

Result

Z - Zero flag
C - Comparison flag
CA – Carry flag
S0+S1+S2 – bit combination determining the operation

Fi
gur 3:3
e2- -bi
tALUb
loc
kdi
agr
am(
God
se,
200
8)

S0 S1 S2 Operation
0 0 0 A+B
0 0 1 A-B
0 1 0 A+1
0 1 1 A-1
1 0 0 A|B
1 0 1 A&B
1 1 0 A~B
1 1 1 A^B

Fi
gur
e2-
4:Tr
utht
abl
ede
ter
mini
ngt
heo
per
ati
onf
or
ALU

Theoper
ati
onisdetermine
db yset
ti
ngS 0,S1andS2inputs
.IfS0=0 ,S1=1a ndS 2=0theALUr ec
ognis
est
hebit
combi
nat
ionandperformssubtr
act
ionA–B.Ther es
ultist
henc opi
edintotheaccumulatorre
gist
er(acc
umula
tor
bas
edarc
hite
ctur
e).ALU a l
soset
st hefl
agstha
tindi
cateastat
eoft hefi
nalre
sult
.Fore xampl
e,addingtwo8-
b i
t
number
slar
geenoughtoproducearesul
t,
thatca
nnotf
itint
oan8 -
b i
treg
ist
er,
wouldcaus
ea noverf
low:
255 + 5 = 4 Carry bit = 1

TheZerofl
agi
sse
twh e
nther
esu
lti
sequ a
ltozer
oandthecompar
is
onfl
agsiss
etbas
edonther
esu
lt.
Ift
heAva
ri
abl
eis
smal
le
rthantheBv a
ri
abl
eandsubtr
acti
ono pe
rat
ionisper
for
medthec o
mp ar
is
onflagi
sse
tto-1.Ift
her
esu
ltof
sub
tra
cti
onisp
osi
ti
vethef
l
agi
ssett
o1a ndift
heres
ulti
seq
ualt
ozeroi
ti
salsose
ttozer
o.
Ana
ri
thme
ti
cuni
tcons
is
tsof
log
icg
ate
swhi
cha
rec
omb
ine
dtog
ethe
rtope
rfor
mar
equ
ire
dfu
nct
ions
ucha
saddi
ti
on.

2
.5.
2AddOpe
rat
ionDe
sig
n
Ta
sk:Desi
gnalo
gicci
rc
u i
tthatwil
lperf
ormana r
it
hmeti
coperat
iona
ddon3-bi
tinp
utv a
ri
abl
esA,BandC.
De
ter
minet
her
equi
rednumberofbi
tsa
ttheout
putwit
hre
gardst
othemaxi
mumpos
si
bleva
luet
hatc
anbepr
oduc
ed

1
2
b
ythei
npu
t.Addi
ti
ona
ll
y,e
xte
ndt
hede
sig
nedc
ir
cui
ttob
eab
let
oadd6b
its
.

Thef
ir
sts
tepi
stodr
awab
loc
ksc
hemeof
3-b
ita
dde
r.

A
Carry
B Addition
Sum
C

Fi
gur 5:Bl
e2- ocks
che
meo
fad
dbl
ock

Thebloc
kc onta
ins3inp ut
sA,Ba ndCa nd2out
pu t
sCarr
yandS um.Anadditi
onof3bit
scanpr
oduc
eamaxi
mum
bi
narynumb ert
ha tr
equire
s2b i
ts(Suma ndCar
ry).Al
lpos
si
bleinpu
tcombinati
onsar
ewrit
teni
ntot
het
rut
htab
le
bel
ow.Eachli
nec orr
espondst
oani npu
tthati
smappedont
othetwooutp
utbits(Car
ry,
Sum).

DI A B C Carry Sum
0 0 0 0 0 0
1 0 0 1 0 1
2 0 1 0 0 1
3 0 1 1 1 0
4 1 0 0 0 1
5 1 0 1 1 0
6 1 1 0 1 0
7 1 1 1 1 1

Figure2-6:Trut
htabl
eof3-
bita
dder.
A,BandCa r
e
th
ei nput
v ar
ia
ble
s.I
nputsa
remappedint
oCarr
yand
Sumo ut
putva
ri
able
s.

Thef
oll
owi
ngc
ondi
ti
onsc
anoc
cur
:
 noneof
thei
npu
tsi
s1,
Sumi
sse
tto0a
ndCa
rryt
o0
 oneof
thei
npu
tsi
s1,
Sumi
sse
t1a
ndCa
rryt
o0
 t
woof
thei
npu
tsa
re1
,Su
miss
ett
o0a
ndCa
rryi
sse
tto1
 a
lli
npu
tsa
re1
,bot
hCa
rrya
ndS
ums
ett
o1

Logi
cal
functi
onforbot
houtput
scanb ewr
it
tendi
rect
lyf
romthea
bovetabl
e.Thelogi
cal
funct
ioncanbewr i
tt
enonl
y
f
oroneofthetwopossi
bl
estat
es.
Ag oodpr
acti
sei
stochoos
ethes
tat
ethatoc
cursf
e we
rti
me s
.Inthi
sc a
sehowever
,
bot
hsta
tesinCarrya
ndS u
moc cur
s4t i
mes.
Theformula
sbel
owdescr
ibe
sthelogi
calf
unct
ionforl
ogicst
ate1.
SUM = ABC+ABC+ABC+ABC
CARRY = ABC+ABC+ABC+ABC

Thei
nputv
ari
ablei
swr
it
tendi
rec
tl
yif
itsl
ogi
cal
1andn
ega
tedi
fi
tsl
ogi
cal
0.Fi
gur
e2-
7cont
ai
nst
hec
ir
cui
tbu
il
dfr
om
t
heabov
eSuma ndCar
ryf
ormul
as.

1
3
Fi
gur 7:Lo
e2- g i
cgat
esper
for
minga
naddope
rat
ion.
No neoft
hei
npu
tsi
s
onandcor
rec
tl
ynoneoft
heo
utput
sisf
la
shing
.

Theabovefigur
eisquit
ecomplexandcontai
nsunnece
ssar
ylog
icgat
es.TheKaurnaug
hma pisus
edtosimpl
if
ylog
ica
l
fu
ncti
ons.Thisproces
sofsimpl
if
yi
ngiscall
edminimal
isa
ti
on.Thepurposeofmini
mali
sati
onist
oreducet
henumber
ofva
ria
blesandthenumb erofl
ogi
cfunct
ionsint
helogi
cexpre
ssi
on.Asaresu
ltoft
histhenumberof
input
sandgat
es
decr
eas
es( Bar
boria
k,A.,
2004).
TheKar
nau
ghmapisagra
phic
sformofmappingt
heval
uesofl
ogi
cfu
nct
ion.
Iti
sat
abl
ewi
thl
i
nesont
het
opa
ndon
t
hesi
deoft
het
abl
e.Eac
hliner
epre
sent
saninputv
ari
abl
e(Fi
gur
e2-8)
.

B
A Group 1

Group 2
0 1 1 0
Group 3
C 0 0 0 0

0 1 1 1
D
0 1 1 1

Fi
gur 8:Ka
e2- rna
ughMa
pwith4var
ia
ble
sandmi
ni
mal
i
sedg
rou
ps
(Ba
rbor
ia
k,2
004)

Fi
gure2-8i
sanexa
mpl
eof4inputmi ni
ma l
i
sati
on.Eachinputv
aria
bleA,B,
Ca ndDcover
sex
act
lyonehal
fofthe
ta
ble
.Eachcel
li
nthet
abl
ere
pr e
sentsthest
ateofaparti
cula
routputva
ri
abl
e(Barb
ori
ak,
2004
).I
ftheci
rc
uitha
s3
out
puts3Kar
naug
hmapswi
ll
b eneededforeac
hv a
ria
ble.
Mini
mali
sat
ionisapr
oce
ssofj
oi
ningt
hesames
tat
es(bi
ts
)intot
hesamegroup.Thegr
oupmusthavear
ect
ang
ula
r
s
hapeandthetheare
amustbeapoweroft
wo(2,4,8,16.
.)(Her
ri
ck,1
99 7
) .Ther
ect
ang
les
ho u
ldbeasl
arg
eas

1
4
pos
si
bl
eandc
annoti
ncl
udez
eros
.
Fig
urebel
owcontainst
heKa r
naughma psforb
othS u
ma ndCar
ryou
tputv
ari
abl
e.Eachofthe3i
nputsA,
Ba ndC
cove
rsonehal
fofthetabl
e.Thedi
str
ibuti
onofsta
tesi
ntheSummaphoweve
rdoesnotal
lowthes
tat
estobej
oine
d
andthu
seachst
aterepr
ese
ntsit
sowngroup.

Group 3
Sum B Carry B
A A

0 1 3 2 0 1 3 2
0 1 0 1 0 0 1 0

4 5 7 6 4 5 7 6
C 1 0 1 0 Group 3 C 0 1 1 1

Group 1 Group 2 Group 1 Group 3


Group 2

Fi
gur 9:Ka
e2- rna
ughma
pof
SUM a
ndCARRYo
utp
utv
ari
abl
es

The
rea
ret
hre
eru
lest
owr
it
ingdownt
hel
ogi
cal
func
ti
onf
romaKa
urna
ghma
p(Ba
rbor
ia
k,2
004
):
 Thev
ari
abl
eiswr
it
tendownd
ire
ctl
yif
itc
ove
rst
hewhol
ear
eaof
oneg
rou
p
 Thev
ari
abl
eisomi
tt
edwhe
nit
cov
ersoneh
alf
oft
hec
hos
eng
rou
p
 Thev
ari
abl
eisne
gat
edwhe
nit
doe
snot
cov
ert
hec
hos
eng
rou
p

Themapsi
ntheFi
gur
e2-
9showthegro
uped1sf
orbot
hCar
ryandSu
m.However
,thedi
st
ri
but
ionof
1si
nSu
mdoe
s
nota
ll
owtogr
oupthe
m,t
helog
ica
lfu
ncti
onca
nnotb
esimpl
i
fie
dandt
hef
ina
lfu
ncti
onis:
SUM = ABC+ABC+ABC+ABC

Car
rycont
rar
ytoS
umc
anb
esi
mpl
i
fie
dsi
ncet
hed
ist
ri
but
ioni
nthema
pca
nfor
mar
ect
ang
les
hap
e.Thes
impl
i
fi
ed
f
unct
ionis
:
C = AC + AB + BC

Thec
ir
cui
ti
nFi
gur
e2-
10s
howst
hef
ina
lga
tee
nga
geme
nt.

Fi
gur 10:Ami
e2- ni
mali
se
dmode
lofl
ogi
cgat
esp
erf
ormi
ngaddi
ti
on.
Twoi
npu
tva
ri
abl
es
(
BandC)a
ndcor
rec
tl
yonl
yCarr
yiss
ett
o1.

1
5
Compa r
edtopre
viou
sc i
rcui
tthenumberofg
atesde
crea
sedby6.I
nprac
ti
c e
,pur
eAND,NOTandORgat
esa
re
r
a r
elyuse
d.Thewhol
e3 -
bitaddi
ti
onfu
ncti
oncanbeacc
ompli
she
dbyen
gagingonl
y5g
ate
s–AND,EXORa
ndOR
adopte
dfrom(Mano,19
93) .

Fig
ure2-11:Addi
ti
onfun
cti
one ng
agi
ngEXOR,ANDandORgat
es.
Al
lth
reeinput
var
iabl
esa
rese
tandbot
hCa r
rya
ndSu
ma r
eco
rre
cly
i
ndi
cat
ingl
ogi
cal
1.

Thecir
cuiti
nFi
gure2-1
1c a
nb ei
nteg
rate
dintoonese
para
teduni
tandsev
e r
aluni
tscanb
ejoinedt
ogetherasshown
i
nFi g
ure2 -
12bel
ow.Usingtheabov
es che
mei ti
sposs
ibl
etocreat
eacircui
tthatwoul
da dd6b i
ts
.Figure2 -
12
showi
ngtheeng
agementoft
heseuni
ts
.Input
sA,B,C,D,E,Far
ethe6inputvar
iabl
es.
Thetheci
rcu
itperf
ormsA+B
+C+D+E+Fope ra
ti
on.

A=0 B=1 C=0


D=1 E=1 F=1

A Carry Carry
B

C
Sum Sum

D Carry Carry

E
F
Sum Sum

Fi
gur 12:Ad
e2- dingt
wo3
-bi
tnu
mbe
rs(
1+3=4
)byu
singi
nte
gra
tedc
ir
cui
ts

Thee xamplehast
heinputse
tto0 10
111.Thu s
,4bit
s(1'
s)ar
eaddedt
oget
herwhi
chpr
oduce
soutpu
t100(
nu mber4
i
nde c
imal)
.Figur
e2-13reu
sesthe3-bi
tadderci
rc
uit
.Howe v
er,
themax
imumposs
ibl
eout
puttha
tcanb
eproduc
edis
6de
c ,
thre
e out
putst
ate
s a
renece
s s
aryt
o i
ndic
a t
ethecor
rec
toutpu
t.

1
6
Fi
gur
e2- 6
13:-b
ita
dde
r.5i
npu
tsa
reset
1andonlyonei
nput
(D)iss
wit
che
dof
f.
1+1+1+1
+1equa
ls5whi
chisinbi
nar
y101.

2
.5.
3Re
gis
terAr
chi
tec
tur
e
Regi
st
eri
sas
malla
mo untofmemoryint
egrat
edintotheCPU. Howe verit
sconte
ntisava
il
ableontheCPU,i
tcanbe
ac
cess
edmor
equickl
ythanfr
om anywhereels
e( Wikipedia,2011a)
.Thel engt
hofr e
gis
ter
sisme as
ure
dinbit
s,f
or
ex
amplean“
8-b
itregi
ste
rora“ 16-
bitre
g i
st
er”.Fig
u re2 -
1 2adopte
df rom (Mano,1993),showsagene
ralbl
ock
di
agr
amofar
egi
ste
r.Numb e
rsdenot
ethenumb erofbitscontai
nedwithinthere
gis
ter
.

1 8
Register A

Fi
gur 14:Bl
e2- ockd
iag
ramof
an8
-bi
tre
gis
ter

ACPUu
sua
ll
ycont
ai
nss
eve
ral
kindsof
reg
ist
ers(
Wik
ipe
dia
,20
11a
):
 da
tar
egi
st
ers–a
reu
sedt
ohol
dnu
mer
icv
alu
es(
exa
mpl
eist
hea
ccu
mul
at
orr
egi
st
er)
 a
ddr
essr
egi
st
ers–a
reu
sedt
oho
lda
ddr
ess
est
hat
areu
sedb
yins
tr
uct
ionst
hat
indi
rec
tl
yac
ces
sme
mor
y
 s
pec
ial
pur
pos
ere
gis
ter
s–hol
dpr
ogr
ams
tat
e;pr
ogr
amc
ount
er,
sta
ckpoi
nte
r
 r
egi
st
ersr
el
at
edme
mor
y–me
mor
ybu
ffe
rre
gis
tera
ndme
mor
yaddr
essr
egi
st
er

Aregis
terc onsi
stsofsmallmemoryunit
scall
edfl
ip-
fl
ops.Thefl
ip-fl
opisc
ompos edoflog i
cgate
stoachie
v eame mory
eff
ect(
Ma no,199 3)
. Eac
hr e
gis
teri
smadeof numb e
roffl
ip-
fl
opswhi char
elogicci
rcuitscapabl
eofrememb e
ringthe
prev
ioussta t
e.Eachflip
-fl
opholdsonebitofi
nformati
on.Joi
ningthesef
li
p-f
lopstogetherproduce
sal a
rgerme mory
cal
ledr
eg is
ter.(Barbori
ak,2004
)Ea c
hregist
erhasal
soassoc
iat
e dspec
ial
controlbi
tswhi chdete
rminestheoperat
ion
tobeperforme donther eg
ist
er.
The s
ebit
sa r
ecal
led–writebi
ta ndrea
dbit.

1
7
2
.5.
43-
bitRe
gis
terDe
sig
n
Tak:De
s si
gna3-bi
tre
gist
erwi
thwri
teprot
ect
ionands
impl
ecl
ock
ing
.Thene
wva
lue
sisl
oade
donl
ywhe
n
pr
ote
cti
onbi
tiss
ettog
etherwi
thi
ncomingcl
ocksi
gnal
.
Eachre
gis
teri
smadeoutof
fl
ip-
fl
ops
.Thef
ir
sts
tepi
stodr
awt
het
rans
it
iondi
agr
am(
Fig
ure2
-15
)whi
chs
howst
he
tr
ansi
ti
onsbet
wee
nt het
wosta
tes
.

011
000 000
001 001
010 010
011 0 1 100
100 101
101 110
110 111
111

Fi
gur
e2-15:Fl
ip-f
lopt
rans
it
iondi
agr
am.Fir
stbi
ti
stheI
np utv
ari
abl
e,s
econd
bi
tdenot
estheWrit
eprote
cti
onbi
tandthel
ast
biti
stheCloc
kti
me .

Onefl
i
p-f
lophol
ds1bi
tofi
nfor
mati
on.Thetwosta
tes0and1area
llt
hepossib
lesta
test
hatt
hefl
ip
-fl
opca
na q
uire
(Fi
gur
e2-
1 5)
.3bit
sar
eus
edtocont
rolt
hest
atei
nthefl
ip-
fl
op.Thest
a t
eonlychangesf
rom0to1if11
1(ILC)iss
et
att
hei
nputandf
rom1to0when011isat
theinp
ut.Eve
ryothe
rcombinat
ionret
ai
nstheprev
iou
ssta
te.
Thefli
p-f
lopholdsaval
uegiv
enb yt
heInput.
Thei nputvari
abl
eiswri
tt
enintothereg
ist
erwhenLo adbi
tissett
o1
(wri
teprotec
ti
onb i
t)andatt
hesametimetheClockequ a
lsto1.Thet
rut
ht a
b l
e(Fig
ure2-16)showsal
ltheposs
ibl
e
st
ate
sfort heregi
st
er.Qn i
sthecurr
entst
ateofther egi
ste
randQn-1 i
sthepr e
vio
uss t
ate
.Inme moryu ni
tsiti
s
i
mpor t
anttofee
db a
ckthecur
rent
sta
te(Qn)backtotheinput(b
ecomespasts
tat
eorQn-1)(Bar
boria
k,20
04 )
.

DI Qn Qn-1 I L C
0 0 0 0 0 0
1 0 0 0 0 1
2 0 0 0 1 0
3 0 0 0 1 1
4 0 0 1 0 0
5 0 0 1 0 1
6 0 0 1 1 0
7 1 0 1 1 1
8 1 1 0 0 0
9 1 1 0 0 1
10 1 1 0 1 0
11 0 1 0 1 1
12 1 1 1 0 0
13 1 1 1 0 1
14 1 1 1 1 0

1
8
DI Qn Qn-1 I L C
15 1 1 1 1 1

Qn – current state I – input


Qn-1 – past state L – load
C – clock

Fi
gur 16:Tr
e2- uthtabl
eofr
egi
st
erb
ase
dont
he
t
rans
it
iondi
agr
am

I
,LandCarethei
npu
tvar
ia
ble
s.Thei
nte
rna
lst
ateof
thef
li
p-f
loponl
ycha
nge
satDI=7a
ndDI=1
1whe
rea
llt
hre
e
i
npu
t c
ondi
ti
onsar
etr
ue.
TheKa
rna
ughma
pbe
lowmi
ni
mal
i
sest
hel
ogi
cfu
nct
ion.

Qn
I
Qn-1
Group 3
0 0 0 0 Group 1

L 0 0 1 0 Group 4
1 1 1 1
C
1 1 0 1

Fi
gur 17:Ka
e2- rnaug
hma
p
Group 2
f
orQns
tat
e

Thea
bov
edi
st
ri
but
ionof
sta
tesc
anb
esi
mpl
i
fie
dandt
hef
ina
lfu
nct
ionsf
ore
achg
rou
par
e:
G1 = Qn-1C
G2 = Qn-1I
G3 = Qn-1L
G4 = ILC

Thec
urr
ents
tat
efu
nct
ionQni
sthe
n:
Qn = Qn-1C + Qn-1I + Qn-1L + ILC

Fi
gur
e2- 18:Asi
mplefl
i
p-f
lophol
ding1bit
ofinf
ormat
ion.Thec
urrents
tat
eis1(s
tate
f
la
shi
ng)
.InputandCloc
kisse
t t
o0andonlyLoadbi
tiss
et1.Thest
atewil
lcha
ngeassoonas
cl
ockbi
thasocc
urreda
tthei
nput

1
9
Thee
xampl
eabov
ecanbeexp
andedt
oholdfor3b
its
,copy
ingt
heg
ate
sanda
tta
chi
ngt
hes
ameCl
ocka
ndLoa
d
i
nput
stoe
achb
lockc
rea
tesa3-
bit
reg
ist
er.

Fi
gur 19:3
e2- -bi
tre
gis
ter
.3I
npu
tbi
tsde
fi
nest
hev
alu
etob
est
ore
dint
her
egi
st
er.

2
.5.
5Cont
rol
andTi
ming
Ac
ontr
oluni
tisacomponentofCPUtha
tmanagesi
nte
rnalpar
tsoft
hemic
ropr
oce
ssora
nde
xte
rna
lI/
Ode
vic
es.
The
ma
inpur
poseofthec
ontr
oluniti
sto(
Abd-El
-Ba
rrandEl-
Re wi
ni,2
005)
 r
eadt
heme
mor
yaddr
esswi
thi
nst
ruc
ti
on
 de
codei
nst
ruc
ti
on
 e
xec
utei
nst
ruc
ti
on
Aprog
ramcou
nte
rre
gis
teri
sapartoft
hec
ont
rolu
nit
.Its
tor
est
heme
mor
yaddr
esst
hatk
eepst
rac
koft
hene
xt
i
nst
ruc
ti
ont
obere
adf
romme mor
y.
Thecl
oc ksyste
m produce
sas equ
enceofcl
ock
sofspe
cif
ie
dfr
eque
ncy.Theseseq
uence
sar
ethenuse
dtoexe
cut
e
i
nst
ruct
ions.Howe ve
r,oneins
truc
ti
oncancons
ist
soft
woormoremic
roins
tr
u c
ti
ons,t
heex
ecu
tionmayt
akemor
e
cl
ock
sunt i
ltheins
tr
ucti
onisfu
ll
yexec
uted.
CPUt i
mingdete
rminest
hespeedofexecu
tionofthest
epsperf
ormedbythecontr
oluni
t.I
tismea
sur
edinHer
tz.
A
cl
ockgener
atori
susedtoge
ne r
atesqua
repu l
sesa
sshowninFigure2-
12(f=2Hz).Oneperi
odise
qualt
oonec
lock
t
ime.Forex
ample,i
f200per
iodsarege
nerat
edin10seconds
,thef
reque
ncyise
qu a
lto:
f = 1 / T = 1 / 20 = 20Hz

2
0
2 periods
V
(volts) 1 period

½ period

log 1

0  
t (sec)

Fi
gur 20:Cl
e2- ocks
igna
lwi
thf
requ
enc
y2Hz

2
.5.
6Cl
ockGe
ner
atorDe
sig
n
Acloc
kg ener
atorisaci
rcu
itt
hatgene
rate
sc l
ockimpul
seswhi
chcontr
oltheint
erna
lsy
nchr
onisa
ti
onamongal
l
i
nte
rnalu
nitsoftheCPU.Moder
nCPUc lockgene
rat
orsmayus
ecry
sta
losci
l
lat
orst
og e
ner
atef
requ
enci
esa
shig
has
2
GHz( CDC4 21x x–Te
xasI
nst
rume
nts,
20 0
7 )
.
Toi
l
lus
tr
atet
hec
onc
eptof
gene
rat
orst
heope
rat
ionof
asi
mpl
eas
tab
lemu
lti
vi
bra
tori
sex
pla
ine
dbe
low.
Theci
rc
uiti
nthef
igu
rebelowisasi
mplea
na s
tabl
efl
ip-
fl
op(a
stab
lemult
iv
ibr
ator
)whe
rene
it
heroft
hes
tat
es(
0or
1)i
sst
abl
e.Theou
tputs
ignal
ista
kenfr
omtheri
ghtsi
deoft
hecapa
cit
orC2.
Thehighert
her es
is
toristhelowe
rthecurre
ntisandt hesl
owe rt
hecapaci
torc ha
rges
.Thetrans
is
tor
sb e
haveas
swi
tches
.Whe nthecapaci
torC1isdisc
hargedthetr
a nsi
st
orT2i scl
ose
da ndt heou t
puti
shigh.Assoonasthe
cap
acit
orC1reachestherequi
redswi
tc
hingvolt
ageofthetrans
is
tor(u
sual
ly0 .
6V)t het
rans
is
torT2opensandthe
cap
acit
orC1isimme di
at
elydis
char
gedagai
nst
theground.

Fi
gur 21:As
e2: tab
lemu
lti
vi
bra
torf
rom(
Venk
atae
t.a
l,2
010
)

Thisisac ir
cuitoftwopart
stha
taree s
sent
ia
llythesa
me.Aft
erasourc
ehasbee
nappl
ie
dtothecir
cui
tthecurr
ent
f
lowst hrought heres
is
terR2tot hecapaci
torC1a ndthr
oughtheresi
st
orR3totheca
paci
torC2whi c
hb oth
acc
u mu l
ateel
ec t
ri
cchar
ge.Thespe
e dofcha
rgingthec
apa
cit
orsi
sreg
ulat
edbyt
heR2andR3reg
ist
ersa
ndobvious
ly
bythesizeofthecapac
it
ors.

2
1
Howe ver
,pract
ical
lynotwoc apaci
torsarethesame( neithe raretheresis
tors
)oneoft heca pac
itor
sc har
ge sfi
rst
.
As sumingthatcapa
cit
orC1ha saccu
mu l
ate
df i
rs
t.Thevoltag eattheb as
eof t
hetrans
is
torT2ra is
esto0.6V,switches
thet r
ansis
toronandimme dia
tel
ydischargest
hecapaci
torC2 .Theou t
putattheri
ghtsi
deof t
hec apaci
torC2i snow
closetoz er
opotenti
alast
hetransi
st
orT2i sswitc
hedona ndc u
rrentfl
owsdownt othezeropot e
ntial
–g round.The
ou tputremai
nszerountil
thecapaci
torC2ha scharge
d( theou t
pu tvol
tagerai
ses
).Thehighvol t
ageatthetransi
stor
T1 'sbaseswitc
hesthetra
nsis
torT1ona nddi s
charg
esthec a paci
torC1 .Thetimetheoutputvolt
agerema i
nshi g
hi s
de pendantonthespeedofchar
gingt
hec apaci
torC1.Thispr ocessisconti
nuous.
Ia
lt
ere
dtheaboveci
rc
uit(Fi
gur
e2-
18)andsi
mulat
edi
ttopr
ovet
hec
onc
ept
.Thec
ir
cui
twa
scr
eat
eda
nds
imu
lat
ed
i
nNIMu l
ti
si
ms of
twar
eproduce
dbyNat
iona
lIns
tr
ument
s.

Fi
gur 22:S
e2- imu
lat
eda
sta
blef
li
p-f
lop(
mul
ti
vi
bra
tor
)

Ins
teadofusi
nghardtra
nsis
torsIuse
dpotent
iomete
rstoa
dju
stt
helengt
hofeachpuls
e.Theout
putta
kenfromthe
node10isshowninFigure2-20.Pot
ent
iometerR103i
ncr
eas
esthedur
ati
onoftheposi
ti
vepul
se,
cont
raryt
oR1 02
whichre
gulat
esthele
ngthofthelowpotent
ia
l( p
uls
e).
Ift
heval
ueofbothpot
enti
ometer
sist
hesamethele
ngthof
bothst
ate
sisthesa
me .

Fi
gur 23:Ou
e2- tpu
tsi
gna
lpr
odu
cedb
yas
tab
lef
li
pfl
op(
node1
0)

2
2
Thedi
spar
it
yatther
is
ingsi
deoft
hepul
seisca
usedbythegr
adu
all
ycharg
edca
pac
it
orov
erape
riodoft
ime
.Thi
s
unwa
nte
dd i
spa
ri
tyca
nb eov
erc
omebyacur
renta
mpli
fi
ertot
heout
put(not
e10
).

Fi
gur 24:As
e2- i
mplecur
renta
mpl
i
fi
erf
rom
(
Lesu
rf,
2000)

I
nFi
g ur
e2-2
3trans
is
torQ3wit
hresi
storR7andR6composeac ur
renta
mplif
ier
.Thetra
nsis
toress
enti
al
lybeh
avesas
t
het
wot r
ansi
st
orsi
nthemult
iv
ibr
ator(swit
chmode).
Figur
e2 -
22showsthecompar
isonofthetwosig
nals
.Therea
d
l
i
neshowsi
sconnec
tedtot
henodenumb er14andt
heblu
eline(normal
is
edoutput
)isconnect
edtothenode14.

Fi
gur 25:Nor
e2- mal
i
sedo
utpu
tsi
gna
l(no
de1
4)

Theou tputoft
hemu l
ti
vi
bra
torisconnec
tedtothebaseoftra
nsis
torQ3(Figur
e2 -
22)
.Thist
ransi
stori
sagai
ninthe
swi
t c
hingmode .Whenthesi
gnalisri
si
ng( ca
paci
torcharg
ing),t
het r
ans
is
torQ3i sc
los
edandt hepotent
ia
latthe
outputishig
h(node14).Assoonastheri
singsi
gnalr
eachestheswit
chi
ngvol
tageatt
hetr
ans
istorQ3itswit
cheson
andthepotenti
ali
nst
ant
lydec
rease
stothelowpotent
ial
.
Thenor
mal
i
sedo
utpu
tisaf
l
ippe
dve
rsi
onof
themu
lti
vi
bra
tors
igna
l.

2
3
Fi
gur 26:Compa
e2- ri
sonof
theo
utpu
tsi
gna
ls

Thecomparis
onb et
weenthetwooutpu
tsiscompar
edintheab
ovefi
gur
e.Asig
nif
ic
a nti
mproveme
nthasbeen
re
ache
db yconnec
ti
ngtheaddi
ti
ona
lampli
fy
ingci
rc
uit
.Thenor
mal
ise
dout
putha
sbeenadjus
teda
tthet
imea
xisb
ya
ofaha
lff
li
ptofit
theast
abl
eout
put.

2
.5.
7Me
mor
yAr
chi
tec
tur
e
Random- ac
cessme mory(RAM)i susedforstor
ingdata
,inst
ruct
ionsa ndres
ult
sdu r
ingexecuti
onofapr ogram.
Me moryisessenti
a l
lyacol
lec
ti
onofregis
ter
sthatcanbeacce
ssedforinfor
mati
onorinfor
ma t
ioncanbewritt
eninto
reg
ist
ers.Ass
u mingt ha
teachregi
st
ercanst
ore8b i
ts(1by
te),t
hesearethe8bit
sthatar
eb e
ingwr i
tt
enoracc
esse
di n
t
heme moryu nit.Ac ombinat
ionofz er
oesandone si
nar egis
terca nrepr
ese
nta nins
truc
tion,analph
anume r
ic
char
act
e roranyot herbi
nar
yinformat
ion(Mano,1982).

input

Read

MEMORY UNIT
address m registers
n bits per register
Write

output

Fi
gur 27:Bl
e2- ockd
iag
ramof
ame
mor
yuni
t(Ma
no,
198
2)

Fi
g u
re2 -
17showsab lockdiagram ofamemoryunit
.Therea retwoc ont
rolsi
gnalsrea
da ndwri
tewhichs
peci
fythe
tr
ansfe
rop er
ati
on.Thet r
a ns
feroperati
onspe
cif
ie
siftheinpu ti
nformati
onist obes t
orediname moryre
gis
teror
whetheri
nformati
onalreadystore
di nthememoryreg
ist
eri st
ob etransf
err
edo ut(Ma no,19
82).Memorycanonly
acce
ptonec ontr
olope r
ationa tatime.Ane xa
mpleofwr i
tecontr
ols i
gnali
sde sc
ribedinFig
ure2-3.Theinput
provi
desthei
nformat
iontob estore
di namemoryuni
tandt heo u
tputprovi
desthedatastor
edint
heme mory
.
Thesi
zeofmemoryi
sdet
ermine
dbythenumberofre
gis
ter
sitcons
ist
sofandthenumb
e rofb
itsi
neachre
gis
ter
.
Eac
hregi
st
eri
sas
si
gnedauni
quememorya
ddre
ss(1,2
,3,.
.upton).Theaddr
essi
sdec
odedandther
equ
iredpa
thto

2
4
t
her
egi
st
eri
scr
eat
ed.
I
fme
mor
ycons
is
tsof
256r
egi
st
erst
hea
ddr
essr
egi
st
ermu
stc
ons
is
tof
atl
eas
t:
log2(256) = 8 bits

t
obea
blet
oac
ces
sev
eryme
mor
yre
gis
terori
ftheme
mor
yha
s10
24r
egi
st
er:
log2(1024) = 10 bits

Ane arl
yform ofr andom acces
sme moryusedma gne
ticcoreme mor
y,whichnow ha
sbeens uppre
ssedby
se
miconductorme mory.Semiconduc
tormemoriesusetheadvant
ageofcapac
it
orst
oholdane le
c t
ri
cc har
ge.
However,thesiz
eofc apaci
tor
sa res
os mal
lthatthe
ydischa
rgeveryqui
ckl
yandmustbecons
tant
lyr e
charg
ed
(r
efr
eshed)(ther
ateofref
res
hisfrom10nst
o100ns)(Wik
ipedi
a,201
1d).
Contr
arytos e
miconductorbasedme mor i
es,
ma gneti
cmemoriesusetheadv
anta
geof magneti
sat
ionoffer
romagne ti
c
mate
ria
l.Onedi r
ecti
onofma g
ne ti
sat
ionrepre
sentsalogi
c0a ndtheotherl
ogi
cal
1.Readi
ngt heinf
ormati
onchang es
t
hedirect
ionofma gneti
sati
onwhi chisforc
edintothe0stat
e. Whentheinf
ormat
ionisread,itist
ransf
err
edintoa n
ex
ter
nalreg i
st
eranda tthesamet imetheme mor yregi
st
erisclear
ed.Thewaytos ol
vethisprobl
emi storeadt he
ex
ter
nalregist
erandwr i
tetheinformati
onb ac
ktot hememoryr egi
st
er.Thi
showever,br
ingsade l
ayinti
me( Ma no,
1982
).Thi sdel
ayisspecif
ie
db ya c
cesstimewhichisthedif
fe
r e
nti
albetwee
nthetimeame moryunitr
ecei
vesare ad
si
gnal
andt heti
mewhe nt hei
nforma t
ionisrea
dfromme mory.
Twore
gis
ter
sareass
ocia
tedwit
hme moryoper
ati
onsme
mor
yaddr
essr
egi
st
er(
MAR)a
ndme
mor
ybu
ffe
rre
gis
ter
(MBR).
Figur
e2 -
20showsthebl
ocksc
he me.

Read

MAR MEMORY UNIT

Write

Address in

MBR

Data Data
out in

Fi
gur 28:Bl
e2- ockdi
agr
amof
ame
mor
yanda
ssoc
iat
edr
egi
st
ers(
Mano,
198
2)

Me
mor
yOp
era
ti
on(
Mano,
199
7)
Whe nthememor
yrecei
vesawr itesi
gna
l,theint
erna
lme morycont
rolint
erpre
tstheinfor
mati
oninMBR a s
i
nformat
iont
obewri
tt
enint
ome mor yatt
headdres
sloc
ati
onspec
if
iedi
ntheMARr egi
st
er.
Thu s
,pr
iortot
hewri
te
oper
ati
ontheMARregi
st
ermu s
tc ont
ai
ntheint
endedaddre
ssandMBRt hedatatobestor
ed.Whenr e
adsi
gna
lis
act
ive
,theMARregi
st
erisre
ada ndthedatast
oredinthememoryattheMAR' saddre
ssaremovedtotheMBR
reg
ist
er.

2
.6 Compi
le
rAr
chi
tec
tur
e
Compil
eri
sac omput
erpr
ogra
mt hatt
ransf
ormssourc
ecodewri
tt
eninapr
ogr
ammingla
ngua
geintoanot
her
compu
terl
ang
uage,v
eryof
te
nt oe
x e
cut
ablebina
rycode(Wik
ipe
dia
,20
11e
).Thetwofu
ndame
ntalpr
inc
ipl
esof

2
5
c
ompi
l
ati
ona
re(
Coop
er&Tor
czon,
200
4):
 p
res
ervi
ngthemea
nin
go ft
hep r
ogr
amb ei
ngco
mpi
l
ed–t
hec
ompi
l
ermu
stpr
ese
rvet
hec
orr
ect
nes
sby
i
mplement
ingt
hemeani
ngofi
tsi
nputpr
ogra
m
 i
mpro
vingt
hei
nputp
rog
ramins
omedi
sce
rni
bl
ewa
y–t
radi
ti
ona
ll
ythei
mpr
ove
menti
sdoneopt
imi
zi
ngt
he
c
odeandbymaki
ngadi
rec
tl
yex
ecu
tab
lefi
l
e

St
ruc
tur
eof
compi
ler
Thef
igu
reb e
lowshowsas
impleb l
ockdiag
ram ofacompi
ler
.Thecompil
eri
sexpe
cte
dt ounde
rst
andt
hes
our
ce
pr
ogr
ama ndcor
rec
tl
ymapi
tfu
nc t
ional
it
yintoat
a r
get
progr
am(Coopera
ndTorcz
on,200
4).

Source
code IR
Target
Font end Back end
program

Compiler

Fi
gur 29:Bl
e2- ockdi
agr
amof
compi
l
er

Font
end–handl
estheinputpr
ogra
mc ode.Itcheck
sthecorr
ectne
ssoft
hesynt
axint
ermsofpr
ogr
amming
l
anguagea
nds e
mantic
s.Ifanerr
orisenc
ou nter
edthefontendshoul
drepor
titi
nasuit
abl
eway.
Thenit
cr
eat
esanimmedia
terepres
ent
ati
on(IR)forthemiddl
e-end.
Mid
dle
-e
n d–prov
idesopt
imi
sat
ionandpe
rfor
manc
etr
ans
for
mat
iona
ndr
emov
alofu
sel
essoru
nre
ada
ble
c
odesuchasc
omme ntore
mptyspac
es.
Bac
ken
d–t r
ansl
atestheIRint
otheta
rgeta
sse
mbl
ycode.Eacht
arg
e ti
nstr
uct
ionha
sacor
respondentIR
i
nst
ruc
tion.Dependingontheta
rge
tpla
tf
ormtheI
Rins
tr
u ct
ioni
srepla
cedbythena
ti
vet
arg
etinstr
ucti
on
f
orcor
respondi
ngma chine
.

Pha
sesof
front
endf
unc
ti
ons(
Wik
ipe
dia
,20
11e
)
 Le
xic
alanal
ys
is–bre
aki
ngthes
our
cec
odet
exti
ntos
mal
lpi
ece
sca
ll
edt
oke
nsf
ori
nst
anc
eke
ywor
ds,
i
dent
if
ie
rsors
ymbol
i
cnames
 S
yntaxana
lysi
s–pars
ingthetokenst
oident
if
ythes
ynt
act
icst
ruc
tur
eofthepr
ogra
m.Thisphas
etypi
cal
l
y
c
reat
esapar
setre
e,whic
hr e
plac
esthel
ine
arseq
uenc
eoft
okenswi
thatr
eest
ruc
tur
eacc
ordi
ngtothef
ormal
g
rammarofthela
nguage
'ssy
ntax
 Semant
ican
a l
ysi
s–addss emanti
cinfor
ma t
iontothepars
etr
eeandbu
ildst
hesymb
oltabl
e.Thi
sphas
e
chec
ksforthetypeer
rorsorther e
qu i
rementofal
lloc
alvar
ia
ble
stobeini
ti
al
is
edbef
oret
heiru
se.I
fa
prob
lemisf
o u
nditre
jec
tstheprogr
amori ss
ueswar
nings
.

Ba
cke
ndph
ase
s(Wi
ki
ped
ia,
201
1e)
 Anal
ys
is–ga
the
rsprog
rami
nfor
mat
ionfromthei
mmedi
at
erepr
esent
ati
on(IR)cr
eate
dbythef
ont
end.Thi
s
pha
seals
oincl
udesdat
afl
owanal
ysi
s,depe
ndenc
yana
lys
is
,al
iasanal
ysi
s,poi
nte
ranal
ysi
sandexc
epti
on
ana
lys
is
.

2
6
 Opti
mis
ati
on -i mmedi
at
er epr
ese
nta
ti
on i
sopt
imi
sed.Fore
xampl
e,de
adc
ode e
li
mina
ti
on,l
oop
t
rans
for
mation,
regi
st
era
ll
oca
ti
on.
 Codegene
rat
io
n–theint
ermedi
atel
angua
geistr
ansl
at
e dint
otheout
putl
angua
ge,usual
lythenat
iv
ema c
hine
l
anguageoftheuse
ds ys
tem.Thet r
ans
lat
ioninvol
vesr e
sour
ceandstor
ede c
isi
ons,suchasde c
idi
ngif
va
ri
a b
leswil
lbef
iti
ntoregi
st
ersandmemor yandschedul
ingappr
opr
ia
temachineinstr
ucti
onsal
ongwith
t
heiras
soci
ate
daddr
essi
ngmodes.

Oneofthemostpopularcompile
rsont heUnix
/Linuxpla
tf
or mistheGNUCompi l
erCol
lect
ion(GCC) .TheGCC
wasdeve
lopedbyRichardStal
lmana ndLenTowe rasapar
t oft
heGNUPr oj
ect.
GCCha sbeenportedint
oawide
va
rie
tyofproce
ssora
rchitec
tures
(Amt el,
ARM, x8
6 -
64,SPARC, MI PS)a
ndisals
oavai
labl
eone mbeddedpla
tf
orms
su
chasS y
mb i
an.Thefontendincludessuppor
tofan u
mb erofprogra
mminglangua
ges(C,C==, J
ava,Ada,
Fort
ran,
Psc
al,
VHDLe t
c.).(
Wi kipedi
a,2011e).

2
.7 I
nst
ruc
tionSe
tAr
chi
tec
tur
e
I
nst
ruc
ti
ons e
tarc
hit
ect
uredef
ine
sdatat
ypes
,ins
tr
uct
ions
,reg
ist
ersaddres
si
ngmodesa
ndmemoryar
chi
te
ctu
re.An
I
SAspeci
fi
esase
tofop-
codes(
ma c
hinel
ang
uage)whi
chdef
inesi
nstr
uct
ionsimpl
eme
nte
donapar
ti
cul
arpr
oces
sor.

Fetch instruction

Decode instruction

Fetch operand

Execute instruction

Store result

Next instruction

Fi
gur 30:I
e2- nst
ruc
tionex
ecu
tionc
ycl
e
(S
navel
y,200
4)

I
nst
ruc
ti
ons
eta
rchi
te
ctu
rec
anb
ede
scr
ibe
dbyf
iv
edi
ff
ere
ntc
ate
gor
ies(
Sna
vel
y,2
004
):
 Op
era
nds
tor
age–de
ter
mine
sthel
oca
ti
onwhe
reope
randsc
anb
ehe
lda
par
tfr
omme
mor
y.

2
7
 Nu
mbe
rof
exp
li
ci
tna
medo
per
and
s–de
ter
mine
sthenu
mbe
rof
ope
randsi
naat
ypi
cal
ins
tr
uct
ion.
 Oper
andloc
ati
on–dete
rmi
neswhetherope
randscanbea
cce
sse
dfr
om me
mor
ydi
rec
tl
yormu
stb
e
t
rans
fer
redt
ointe
rna
lCPUre
gis
ter
sforALUope r
ati
ons
.
 Op
era
ti
ons–ope
rat
ionspr
ovi
dedb
ytheI
SA.
 Ty
pea
nds
iz
eof
ope
ran
ds–de
ter
mine
ssi
zea
ndt
ypeof
eac
hope
rand.

Thr
eemos
tcommont
ype
sof
ISAa
re(
Sna
vel
y,2
004
):
 S
tac
k–ope
randsa
rei
mpl
i
cit
lyont
opof
thes
tac
k.
 Ac
cumu
lat
or–t
heope
randi
simpl
i
cit
lyt
hea
ccu
mul
at
or.
 Ge
ner
alPu
rpos
eRe
gis
ter(
GPR)–ope
randsi
sei
the
rre
gis
ter
sorme
mor
yloc
ati
ons
.
Ex
ampl
eof
ass
emb
lyc
odeof
all
thr
eeI
SAt
ype
s:
A=B+C

Ev
alu
ati
onof
abov
eex
pre
ssi
on:

Stack Accumulator GPR


PUSH A LOAD A LOAD R1, A
PUSH B ADD B ADD R1,B
ADD STORE C STORE R1,C
POP C

Fi
gur 31:Di
e2- ff
ere
ntI
SAa
ppr
oac
hesf
rom(
Sna
vel
y,2
004
)

St
ackadv
anta
gesar
eas i
mplee x
pre
ssi
oneva
luat
ionusi
ngrev
ers
epoli
shnota
ti
ona ndshor
terins
tru
cti
ons
.The
di
sadv
ant
age
sarea
nina
bil
it
yrandoml
ytoac
ces
sthesta
ckwhi
chmakesi
tha
rdtogene
rat
eaneff
ic
ientc
ode.
Accu
mul
atora
dva
nta
gesares
hort
eri
nst
ruc
ti
onsandt
hedis
advant
agei
ssi
ncet
hea
ccu
mul
at
ori
sus
eda
sat
empor
ary
st
ora
get
hememoryt
raf
fi
cist
hehi
ghes
tuse
dinthi
sar
chi
te
ctur
e.
Gener
alpurposer
egi
st
erappr
oachi
seas
ycodege
nera
tionanddatacanbestor
edf
orl
ongpe
ri
odsi
nre
gis
ter
s.The
di
sadv
anta
ge sa
reope
randsmus
tbename
dwhichr
esu
ltsinl
onge
rinst
ruct
ions
.

2
.8 Re
vie
wofEx
ist
ingSi
mul
ator
s
Thepurpos
eofthi
ssubs
ect
ioni
stoa
sse
ssthechos
ens
imul
ator
sandhig
hli
ghtthe
iradva
ntag
esanddis
adv
ant
age
s.
Thesi
mu l
at
orsa
rediv
ide
dintot
womai
ngroupwhic
har
eli
cense
dandopensour
ce.Al
lfe
atur
esar
ethe
nsummari
sed
i
natabl
e.

2
.8.
1GNUSi
m8085
(
Gnu
Sim8
085
,ht
tp:
//g
nus
im8
085
.or
g/)
GnuSim80
8 5i
sagra
phic
alsi
mul
at
or,a
sse
mbl
era
ndde
bug
gerf
ort
heI
nte
l80
85mi
cr
opr
oce
ssori
nLi
nuxa
nd
Windows(GNUSi
m8085
,201
0).
Thes
imu
lat
orha
sthef
oll
owi
ngk
eyf
eat
ure
s(GNUS
im8
085
,20
10)
:
 t
ext
edi
tori
ncl
udi
ngs
ynt
axhi
ghl
i
ght
ing

2
8
 e
asyv
iewof
reg
ist
era
ndf
la
gsc
ont
ent
s
 he
xade
cima
l–d
eci
mal
conv
ert
er
 v
iewof
sta
ck,
memor
yandI
/Oc
ont
ent
s
 s
uppor
tbr
eak
poi
ntsf
orde
bug
ging
 s
tepwi
sepr
ogr
ame
xec
uti
on
 pr
int
ings
uppor
t

Fi
gur 32:GNUS
e2- im8
085Us
erI
nte
rfa
ce

Oneoft
hemaj
oradva
ntage
sofGNUSi
m8085i
sthee
aseofus
e.Thesi
mulat
orha
sav
eryi
ntu
iti
vei
nte
rfa
cea
ndt
he
us
ers
houl
dbea
bletowri
tehi
sowna
sse
mbl
yscr
ipt
swi
thout
anyhes
it
ati
on.

2
9
Fi
gur 33:I
e2- nst
ruc
ti
onk
eyp
ad

Thes i
mu l
atorall
owst heu s
ertowrit
etheirowna sse
mb l
yscr
ipts
,ex
ecut
ethema ndrevie
wt heconte
ntsofthe
re
gis
ters
,me moryors ta
c ki
nt hele
ftpanel(Fi
g ur
e2 -
4).GNUS i
m8085als
opr ovidesandiscapabl
eofs i
mple
debugg
ingb yplac
ingbreakpoint
sint
heas
s e
mb l
ys c
ri
pt.Thepr
ogramca
nbeexecut
e dsimult
aneo
u s
lyandors
tep-b
y-
st
epme thod.Ana ddit
ionalf
eatur
eisani
nstruct
ionkeypad(Figu
re2-
5)thatal
l
owsu ser
stoenteri
nstr
uct
ionsby
cl
ic
kingont heappropr
iatebut
ton.
Eac
hinst
ruc
tionb u
ttonbri
ngsupane wwindowwhe r
eal
linputda
ta(oper
ands
)aree
nter
edbytheu
serandt
he
as
sembl
yins
truct
ionisgener
ate
dautomat
ica
ll
yb ythes
imu
lator
.Thi
sfe
a t
uremaybepa
rti
cul
ar
lyi
mpor
tantt
onew
us
erswhoar
enotfamili
ar
ise
dwitht
heinst
ruc
tionse
t.
Addit
iona
lfea
tur
eisdeci
malt
ohe xconvers
ioncal
cul
at
orloc
atedinthel e
ftpanel
.Thes i
mu l
at
oral
sopr
ovidessi
mpl e
I/
Oc ommu ni
cat
ionwhereda
taaresenttotheport
.Val
uest
oredateac hportcanbee nt
ere
db yt
heuse
randc li
cking
ontheUpdatePortVa
luebut
ton(Figure2-
3 1
)theval
ueisas
sig
nedt othepor t
.Thes i
mu l
at
orof
fer
s2568 -
bitports
.
Thesamecapabi
li
ti
esa
reprov
idedtome mory.Thememoryhas6554a ddres
slocat
ionsandeachl
oca
ti
oniscapableof
st
ori
ng8b i
ts
.
GNUSim808
5isamu l
ti
-pl
at
for
msi
mu l
at
ortha
twasde
vel
ope
dinLinu
xandha
sbe
enpor
tedi
ntoWi
ndowsa
swe
ll
.
Thes
imul
at
orisf
reet
ouseandi
spu
bli
shedu
nderGNUGPLlic
ens
e.

2
.8.
2Gs
im85
(
Gsi
m80
85,
htt
p:/
/gs
im8
5.s
our
cef
org
e.ne
t/)
Gsim85isan8 085simula
torwit
hauserfr
iendlyg r
aphi
cali
nter
fac
e.Theinterf
acei
ncludesaregi
sterandfl
agpanel
sit
uat
edinthebottomof t
hewindow.
Thes i
mu lat
orcontai
ns8genera
lpurposere
gis
ter(A,B,
C,D,E,F,
Ha ndL).The
conte
ntsofspec
ialre
gist
ersPCandSPisal
soa vai
l
a bl
einthebot
tomp ane
l.Theme moryma pissi
tuat
edinthepane
l
ontheri
ghthandside.Eachmemoryl
ocat
ions t
ores8b i
ts
.Thetota
lnumbe rofl
ocat
ionisFFFF( 65536).The
ref
ore
,
thesi
zeofusab
leme moryis64KB.Si
mila
rlyisi
nt heprev
iouss
imulat
orI/Oportsar
ea v
ail
abl
et ot
heu s
e r
.

3
0
Fi
gur 34:Us
e2- eri
nte
rfa
ceof
Gsi
m85

Thesi
mu lat
ordoe snotconta
inat ex
tedit
orwhichsomee x
per
ienceduse
rsmayc onsi
derasadi
sadv
anta
ge.The
i
nst
ruct
ionsaregenera
tedfr
omt heins
tr
ucti
onkeypa
d(Fi
g u
re3-
32)andins
erte
dautomati
cal
lyi
ntos
epar
ater
ow.The
ke
ypadrecogni
sestheins
tr
ucti
ona ndwil
las
kfordat
atoent
erbycl
i
c k
ingonthehe
xk ey
pad(Fig
ure3-
33).
Thesimulat
oral
sohasaca
pabi
li
tyofr
esi
zi
ngt hememoryb
yde f
ini
ngthemax
imum pos
si
bl
eme morya
ddres
s
l
ocati
on.Thepr
ogra
mc a
nbeex
ecute
dbycl
ic
kingonther
unbut
tonorst
epwhi
chexe
cut
esonei
nst
ruc
ti
onperc
li
ck
(s
tepthr
oughmetho
d).

Fi
gur 35:Gs
e3- im8
5Ke
ypa
d

3
1
If
ou ndthesi
mulatorali
tt
ledif
fi
cultt
ou s
e.Al
lins
tr
uct
ionsareenter
edfromtheke
ypa d.
Theuserc
anthenmanuall
y
def
inetheaddre
s swheretheinstruc
ti
onismov e
dintheme mory.Whe nthepr
ogra
mi srea
dytheref
res
hb u
tton
au
toma ti
cal
l
yloadsalli
nst
ruct
ionsint
ome morydef
aul
t(st
artat0000h)
.Thentheuse
rdefi
nest
hest
arta
ddres
swhich
i
sthea ddr
essof
thef i
rs
tinst
ruct
ion.Theprog
ramcanbethensteppedt
ho ug
horrun.
Averyi
mpor
tantf
eatu
retha
twasmiss
edisal
te
rnat
ionofins
ert
edi
nst
ruc
ti
ons.
Howev
er,
theme
nue
ditdoe
sof
fe
ran
opt
iont
oedi
tarow.Ias
sumetha
tthef
eat
urehasb
ee npl
annedt
obeimpl
ement
ed.
Thewr
itt
enscr
iptc
anbesav
edast
extori
nit
sint
erna
l f
orma
tus
edb
ythes
imu
lat
or.
Howe
ver
,whe
nthepr
ogr
ami
s
sa
veda
stext
thesi
mula
torwi
ll
notb
eablet
ore
aditaga
in.
Gsi
m85ca
nb er
uninLinu
xe nv
ironmentandispubl
i
she
dunde
rGNU GPLl
i
cens
e.Wi
ndowsu
ser
smu
sti
nst
al
l
GTK+env
ironmentt
obeabl
etorunitont
hispl
at
for
m.

2
.8.
3Mi
cropr
oce
ssorSi
mul
ator5
(
Mic
ropr
oce
ssorS
imu
lat
or,
htt
p:/
/www.
sof
twa
ref
ore
duc
ati
on.
com/
sms
32v
50/
)
Thissi
mu l
at
orincl
udesasub-
setofafullins
tr
ucti
onsetofacommonmi cr
oproce
ssor.Thesi
mu l
at
oremulat
esan
eig
htbitCPUwhichissi
mil
artothelowe i
ghtbi
tsoft
he80x86fa
mily.
Theprogra
mi nclu
des25
6b yt
esofRAM and
someadvance
dfeat
ures
.Theprogra
mc anberunconti
nuousl
yorst
eppedt
hroug
h.Itals
oincl
udesaCPUc l
ockspe
ed
t
ha tc
anbealt
ere
d.
Theinter
fac
eisdivi
dedintotwopart
s,thema i
npartist
akenbythetextedi
tor(Fi
gure2-2
) .Thetoppa
rtoft
he
windowcontai
nst
hec onve
ntsofge
neral
p ur
poseandspec
ialr
egi
st
ers
. I
nthemi ddl
eiss
itu
atedprogr
amma i
nmenu
short
cru
stt
os a
veorloadafi
leands
cri
pthandl
ingbut
tons(St
op,Runani
ma t
ion).
Thema i
ninte
rfa
cehoweverdoe
snotc
onta
inthememor ymapwhic
hisimp
lement
edinase
par
atewi
ndowass
hown
i
nt hefi
gure
.Ifoundthi
sme morymapveryunders
tanda
bleandeas
ytorea
d.Ital
soal
l
owstheuse
rconve
rtt
he
conte
nti
ntohexade
cimal
ba s
eorASCI
Ichar
acte
rs.

Fi
gur 36:MS
e3- 5us
eri
nte
rfa
cewi
thme
mor
yma
p

3
2
Pe
ri
phe
ral
dev
ice
sca
nbec
onne
cte
dtot
hes
imu
lat
or.
Thes
imu
lat
ori
ncl
ude
sthe
sepe
rip
her
al
sde
vic
es:
 k
eyb
oar
dinpu
t
 t
raf
fi
cli
ght
s
 he
ate
randt
her
mos
tat
 s
nak
eandma
ze
 s
teppe
rmot
or
 me
mor
yma
ppe
r
 7
-se
gme
ntdi
spl
ay
 k
eyb
oar
dandk
eypa
d

Thesimulat
orincl
udesplentyofdevi
ceswhichmakeitsui
ta
blefortea
chingpu r
pose
s .
TheFigur
e2 -
3showsal
lthe
devi
cesthatthesimulat
ori nc
ludes
.Ev e
nt houghthesimul
atordoe snota ni
matet heexe
cut
ionproce
ssithas
ani
ma t
ionpartl
yimplementedinitsperi
pheralde
vic
es.Duri
ngt heexec
u t
ionthatinvol
vesapart
ic
ula
rperi
phera
l
devi
cethedevi
cepic
turechanges(a
nimates
).Thespee
dh oweve
rd epe
nds,onthespeedofthec
loc
kthati
sse
tpri
orto
exe
cuti
on.

Fi
gur 37:Addi
e3- ti
ona
lde
vic
esi
mpl
eme
nte
dint
hes
imu
lat
or(
ani
mat
ions
)

Thesi
mula
toriswri
tt
eninprog
ramminglang
uageDel
phif
orWindowspl
atf
orm.Howe
ver
,thea
ppl
ic
ati
oncanber
un
unde
rWine(soft
waret
hatemula
tesWindowsAPI)onLi
nux.
Thesimula
torr
ele
ase
dunde
rGNU/ GPLli
cens
ewhi
ch

3
3
i
sag
rea
tadv
ant
ageov
erot
herl
i
cens
eds
imu
lat
ors
.

2
.8.
4Emu8086
(
Emu
808
6,ht
tp:
//e
mu8
086
.sof
twa
re.
i
nfor
mer
.c
om/
4.0
/)
Emu8086isan8
086micr
oproce
ssoremula
tortha
trunsonav i
rt
ualmac
hine.Ther
efor
etheemul
at
orbl
ock
sthe
wri
tt
enprogr
amsfr
om a
cces
singrealha
rdware(memory,ha
rd-
dri
ves
)ast heass
emb l
ycodei
sranonavirt
ual
machi
ne.
Progra
msc a
nb eruninst
ep-b
y-s
tepmodeandt
heinst
ruc
ti
onsc
anbee
xec
utedinfor
wa r
dorrev
ers
edi
rect
ion.The
emu l
at
orinc
ludesre
gis
ter
s,memory,
sta
cka
ndfl
agsva
ri
abl
eswhi
chc
anbev
iewedinasepar
atewi
ndowt
hatisshown
totheuse
rattheru
nningst
age
Thei
nte
rfa
ceonl
yc ont
ainsa nadvanc
etexte
dit
orca
pableofsynt
a xhig
hli
ght
ingandli
nenu mber
ing.Thesoftwar
e
al
soi
ncl
udess
omeu sef
ultutori
al
sforbeg
inne
rs.
Thesourcecodeiscompil
edandexec
utedonthee mula
tors
tep-b
y-
st
epmet
hod.Ari
thmeti
ca ndLogicUnit(
ALU)showstheint
ernal
wor koft
hecent
ral
proces
soruni
t( CPU).
Fi
gur
e3-39showsasimul
at
edst
eppedmotor.Thee
xecu
tedi
nst
ruc
ti
onsi
shi
ghl
i
ght
edandthecha
nge
sinr
egi
st
ersa
re
i
mmediat
elyupdat
ed.Del
ayca
nb es
et,t
oslowdownthesi
mula
ti
on.The
rea
re4di
ff
ere
ntdel
ays(ma
x400ms
)orthe
si
mul
ati
onc a
nb es
teppe
dthr
oughbytheuser
.
Thee
mul
at
ori
sca
pab
leofc
rea
ti
ngat
inyope
rat
ings
yst
ema
ndwr
it
eit
sbi
nar
ycodet
oab
oot
abl
efl
oppy
dis
k.Thi
s

Fi
gur 38:S
e3- imu
lat
ionof
ste
ppe
dmot
ori
nEmu
808
6
t
hena
ll
owst
heu
sert
oboot
acompl
et
evi
rt
ual
mac
hiner
unni
ngwi
thonl
ythef
loppyd
isk
.

Emu
808
6come
swi
ths
eve
ral
vir
tua
lex
ter
nal
dev
ice
s:
 r
obot

3
4
 s
teppe
rmot
or
 l
eddi
spl
ay
 t
raf
fi
cli
ght
sint
ers
ect
ion
Thi
sde
vic
esc
anb
emodi
fi
eda
ndc
lone
dast
hei
rso
urc
ecodei
sav
ail
abl
e.

Thesof
twa
rei
sli
mit
edupto14day
soffr
eee
val
uat
ionpe
rio
d,i
fyoucont
inu
etous
ethi
ssof
twa
rea
ft
ert
hee
val
uat
ion
per
iody
oumustpur
cha
sedi
gi
tal
li
cenc
ekeyf
romRegNow/Dig
it
alRi
verc
ompany
.
 Pr
iv
ateLi
cens
e Pr
ic
e: $
19.
95US
D(R
12)
 1Ye
arS
iteLi
cenc
e Pr
ic
e: $
295US
D (
R18
3)
 Pe
rma
nent
Sit
eLi
cenc
e Pr
ic
e: $
125
0US
D(R
775
)

2
.8.
5Mi
cropr
oce
ssor8085Si
mul
ator3
(
MS5
,ht
tp:
//www.
brot
her
sof
t.
com/
mic
ropr
oce
ssor
-80
85-
si
mul
at
or-
124
86.
html
)
Micr
oproc
ess
or 80
85Si
mul
at
or f
eat
ure
sa v
eryu
serf
ri
endl
yand i
ntu
iti
veS
imu
lat
or u
nde
r Wi
ndows
.
Somethef
eat
ure
sar
e:
 Compl
et
etr
ans
par
enc
yof
reg
ist
ers
,RAM me
mor
y,I
OMe
mor
y,s
tat
usf
la
gse
tc.
 I
ncl
udesabu
il
tina s
semble
rtha
ttr
ansl
at
esthegi
venMne
moni
ccodei
ntoma
chi
nec
odef
or8
085
,wi
th
v
eryef
fi
ci
ente
rrorhandl
erandi
nputv
ali
dat
ion.
 S
ing
leS
tepOpe
rat
ionf
ore
ff
ic
ientDe
bug
ging
.
 Hasprov
isi
ontoadd"Inte
r r
uptSe
rvi
ceRou
tine
s"(
ISR)a
ndot
hers
ubr
out
ine
sandf
aci
l
ita
test
he
pr
oced
u r
eofca
ll
ingonea
nother.
 Inc
lude
sprov
isi
onf
orex
por
ti
nga
ndi
mpor
ti
ngme
mor
ymodu
les
,sot
haty
oudon'
tha
vet
oke
ythes
ame
dat
aovera
ndovera
gai
n.
 Pr
ovi
dess
yst
ema
ti
candde
tai
l
edl
i
sti
ngof
thea
sse
mbl
edpr
ogr
amc
odei
npr
int
abl
efor
mat
.
 I
ncl
ude
sanI
nte
rpr
ete
rtha
tal
l
owsEx
ecu
tionof
sing
lei
nst
ruc
ti
ons
.
 Al
l
owst
ovi
ewt
imi
ngDi
agr
amsf
orv
ari
ousi
nst
ruc
ti
ons
.
 I
tinc
ludesal
lthef
eat
uresofthebare8
085hardware(
exce
ptforhardwar
esy
nchr
oni
zat
ionf
eat
ure
sli
ke
r
eady
,h ol
d).
youcanfr
eed ownloa
dMi c
ropr
ocess
or8085Si
mu l
ator3.
0now.
Thesi
mulat
ori
sint
ende
dtos
imu
lat
emi
cr
opr
oce
ssor8
085a
rchi
te
ctu
re.
Thes
oft
war
eha
sau
serf
ri
endl
yint
erf
acea
nd
i
tisf
reet
odownl
oad.

3
5
Fi
gur 39:S
e3- cre
ens
hot
ofMS5

Thef
eat
ure
sof
int
erf
acei
ncl
ude
s:

 c
odi
ngi
npu
tispe
rfor
medt
hrou
ghac
odek
eypa
d.
 theus
erisg
uide
da l
lal
ongbyawe
llde
sig
neda
ndi
nte
ll
ig
ents
oft
war
eandt
husa
lmos
tre
mov
ingt
he
poss
ibi
li
tyt
oma keamis
tak
e
 t
hes
oft
war
einc
lude
sab
uil
ti
nas
semb
ler(
tra
nsl
at
esmne
moni
cint
oma
chi
nec
ode
)
 t
hepa
cka
gei
ncl
ude
sbr
eak
poi
ntsa
nds
ing
les
tepr
unni
ng
 t
rans
par
enc
yof
reg
ist
ers
,ra
mme
mor
y,I
Ome
mor
yan
dst
atu
sfl
ags
Thesof
twar
eisre
lea
sedundershar
ewarel
i
cens
ewhichc
ost
sonly$8
.Thec
rea
tor
soft
hes
imu
lat
ora
lsoof
fe
rsf
ree
upg
rade
stothene
wv e
rsi
onaslongast
heus
erpos
ses
sava
li
dli
cens
e.

3
6
Fi
gur 30:Ti
e3- mingd
iag
ramof
ADDM i
nst
ruc
ti
on

2
.8.
6Conc
lus
ion
Thes i
mu l
at
orr
eviewconsi
s tof5si
mu l
at
orswhich3ofthemarepropri
etar
yand2r e
lea
seda sopensour
ce.Obvious
ly
t
hes ourc
esour
ces i
mu l
at
ora rewri
tt
enforLinuxpla
tf
orma ndli
censedforWindowsplat
form.Theinter
fac
ec ol
umn
speci
fi
esthei
npe r
centag
et heovera
llmarkfortheeas
eofu s
eandl a
y o
u t
.Textedi
tor
,ke ypad,deb
ugging,st
epped
execut
ionandexte
rnaldev
ic e
scolu
mnss peci
fythef
eatur
esimpl
eme ntedint
hes i
mu l
at
or. Pl
atf
ormandLi ce
nseare
als
ov e
ryimpor
tanti
nma kingsuchadeci
sion.

Text Key De
bug
gig S
n t
eppe
d Ext
er
nal An
ima
ti
on Pl
at
fo
rm Li
ce
nse I
nte
rf
ace
e
dit
or pa
d e
xec
uti
on d
evi
ce
s
Open
GNUS
im8
085 ✓ ✓ ✓ ✓ × × Li
nux
s
our
ce
8
5%

Open
Gs
im8
5 × ✓ × ✓ × × Li
nux
s
our
ce
6
0%

Mi
cropr
oces
sor Only Wi
ndows Open
s
imu l
at
or5 ✓ × ✓ ✓ ✓ dev
ices s
our
ce
9
5%

3
7
Only Wi
ndows Pr
iv
ate
Emu8
086 ✓ ✓ ✓ ✓ ✓ dev
ices R12
9
0%

Mi
croproc
ess
or
80
85s i
mulat
or × ✓ ✓ ✓ × × Wi
ndows R
5 5
5%
3

Ta
bl 2:S
e2- umma
ryof
rev
iewe
dsi
mul
at
ors

3
8
Cha
pte
r3

De
sig
nandAna
lys
is

3
.1 I
ntr
oduc
tion
Thischa
pterincludesashorti
ntr
oduct
ionintotheIncrementa
landIter
ati
v edev
e l
opmentmodel
.Thentheove
ral
l
desi
gnandf u
nctional
it
yofthemicr
oproces
sorsi
mu la
torisdes
cri
bed.Thesu bs
ect
ionsar
edevot
edtodeta
il
eddes
ign
andanal
y s
isofindiv
idualpa
rtsoft
hemi c
roproc
e s
sor.Asse
mb l
ylangua
gea ndcompile
rdesi
gnint
rodu
cethesy
ntax
andthecompili
ngprocedure
s.Thela
stpar
tdescr
ibesthedesi
gnoftheuse
rinter
fac
e .
Thepr
oje
ct'
sde
sig
niss
pli
ti
ntot
hre
ema
jors
ect
ions
:
S
imu
lat
ord
esi
gn
 Mi
cr
opr
oce
ssor
 Me
mor
y
 I
nst
ruc
ti
ons
et
 Us
erI
npu
t
 I
/Of
il
e
As
se
mbl
yla
ngu
age
 S
ynt
ax
 Compi
l
er
Us
eri
nte
rf
ace
 Gr
aphi
cal
use
rint
erf
ace

3
.2 I
ter
ati
ve& I
ncr
eme
nta
lMode
l
TheIncr
ement
alde
vel
opmentmodel
isacycl
i
csoft
waredev
elopmentpr
oce
ss.
Thema
ini
deai
stode
vel
opas
yst
em
t
hrou
g hre
peat
edcy
cle
s(i
te
rat
iv
e)insma
llpor
ti
ons(i
ncre
mental)
.
Devel
opme ntinthi
smode lst
artswit
hadevel
opings ma
llv
ersi
onofthepr og
ram.Thepu r
poseofthi
sistohavea
worki
ngpr ogr
ame ve
nt houghitdoesnothaveallther
equir
edfunct
ions,whic
haredevelope
dg r
adual
lythr
ough
cyc
les
.Ata nyti
meawor kingprogr
amc a
nb epre
sentedt
othec u
stomerforfe
edbac
k.Thishasabenef
ic
iala
ffe
cton
t
heov e
ralldevel
opmentasalt
erati
oncanbedonei mmedia
tel
ywi t
houtane e
dforalt
eri
ngahu geamountofcode
(OneStepTe s
ti
ng,2010).

3
9
Start

Finish
Analysis

debug

Testing Design

Coding

Fi
gur 1:I
e3- ter
ati
ve&I
ncr
eme
nta
lde
vel
opme
ntmode
l

Thi
smode
lisd
ivi
dedi
ntof
ourma
jors
tag
es(
Lewa
ll
en,
200
5):
 Ana
lys
is–deci
si
onove
rcha
nge
stob
eimpl
eme
nte
dint
hene
xts
tag
e.Onl
ysma
llpor
ti
onsa
re
i
mplement
eda
tati
me
 De
si
gn–c
hang
est
hat
nee
dtob
edoneb
efor
eane
wfe
atu
rec
anb
ecode
dif
any
.
 Co
ding–compi
l
ingthecodet
oma
kes
uret
hatt
hec
odi
ngi
scor
rec
t.Thec
odei
sof
te
nre
compi
l
eda
ft
er
wr
it
ing afe
wli
nesofcode
 Tes
ti
ng–i nvol
vesrunni
ngtheprogr
amb yusi
ngtestdatai
fitisr
eque
ste
d.I
fanerroroccu
rsthatthe
compil
erhasnotrec
ognis
ed(typ
ical
l
yme mor
yleaks)
,thepr
og r
ammu s
tbede
buggedandeit
hercoding
ordesi
gnsho u
ldbea l
te
red.However
,onl
ysmallport
ionsar
eimplement
edt
hrou
ghac y
cle
.Itisthen
gene
ral
lyveryeas
ytodefi
nethesou
rceoft
heprobl
em.
Thede v
elopmentcontinuesar
oundthisl
oopu nt
ilt
heprogramisfi
nis
hed(Figu
r e3-1
) .TheIter
ati
ve&Incr
ementa
l
approa
chme ansthatthereisarunni
ngpr og
rama tt
hee ndofeachiter
ati
on.Itobviouslydoesnotc
onta
inal
lthe
f
e a
ture
sthathasbeenproposedtobeimplemente
d.Thisgi
vesanopport
unit
ytoe va
luatetheprogr
amaf
tere
achcyc
le
andpossi
blyafee
dbackg a
theredfr
omu se
rsbefor
eiti
sful
l
yc omple
ted.
(
Lewa
ll
en,
200
5)
Ad
van
tag
es
 Ge
ner
ate
swor
kings
oft
war
equ
ick
lya
nde
arl
ydu
ringt
hes
oft
war
eli
fec
ycl
e.
 Mor
efl
exi
bl
e–l
essc
ost
lyt
ocha
nges
copea
ndr
equ
ire
ment
s.
 Ea
sie
rtot
esta
ndd
ebu
gdu
ringas
mal
l
eri
te
rat
ion.
 Ea
chi
te
rat
ioni
sane
asi
l
yma
nag
edmi
l
est
one
.
Di
sad
van
tag
es
 Ea
chp
has
eof
ani
te
rat
ioni
sri
gi
danddonot
ove
rl
ape
achot
her
.
 Probl
emsmayar
isepert
ai
ningtos
yst
ema
rchi
te
ctu
reb
eca
usenota
llr
equ
ire
ment
sar
ega
the
redu
p
f
rontf
orthee
nti
resof
twarel
if
ecyc
le.
 Ca
nbeac
ost
lymode
ltou
se.
 Pr
oje
ct’
ssu
cce
ssi
shi
ghl
yde
pende
ntont
her
is
kana
lys
isph
ase
.

4
0
3
.4 Si
mul
atorDe
sig
n
Thesi
mu l
atordes
ignc ons
ist
sofde s
igni
ngtheover
al
lf
unct
iona
li
tyoft
hesi
mu l
at
or,t
hewayi
tinp
utfi
lei
sre
ad.The
si
mula
torrecogni
sesthefi
leformatandpars
esthei
nst
ruc
ti
onstothemi
cr
oproces
sor
.Fi
gur
e2-3des
cri
best
hehig
h-
l
evel
archi
te
c t
ureoftheopera
tionofthesi
mu l
at
or.

SIMULATOR program.bc
1101100001111
BINARY CODE

Fi
gur 2:Hi
e3- gh-
le
vel
ope
rat
ionof
thes
imu
lat
or

I
tisimporta
nttoa s
cert
ai
nt hetwoter
ms“ mic
ropr
oces
sor”and“s
imul
ator”
.Thet er
ms imul
at
orr e
fer
stothe
i
mplemente
dsoft
waretha
trea
dsthei
nputf
il
eandhandl
est
heu s
eri
nputc
omma nds.Wher
easthemi
cropr
ocess
ori
sa
pa
rtoft
hesimul
ator
.Thesimula
tori
ntopa
sse
stheins
tr
uct
ionst
othemic
roproce
ssorwhi
chthenmovesthe
mt ot
he
memoryandexe
cute
s.

MEMORY
01001011010111010101010
Addr Instruction 10010101010101010101001

0x0000 0100101101011101 SIMULATOR 10010101010101001001001


11110100000011101001001
0x0001 0101010100101010
1010101001010101010
0x0002 1010101010100110

0x0003 0101010101010010

0x0004 0100111110100000

0x0005 0111010010011011

0x0006 0101001010101010

... ...

0xFFFF 0000000000000000

Fi
gur 3:Loa
e3- dingi
nst
ruc
ti
onsi
ntome
mor
y

Thesi
mu l
atorac
cept
sab i
nar
yfi
lewhi
chcont
ai
nsbi
nar
ycodedinst
ruc
ti
ons.Wit
hregar
dstother
ealmachine
,the
bi
nar
yfil
eisnotarealb
inar
yfi
le
.Iti
sacommonte
xtfi
l
ethatcont
ai
nsastr
ingofze
rosandones(
bina
ry)
. Thefil
e
howe
verappear
sasbi
naryt
othes
imul
ator
.
Thef
il
eisrea
dbythesi
mu l
at
orandspli
tint
ogroupsof16bit
s(def
inei
nISA).Eachgr
oupisthenspe
cif
ic
all
yass
igned
memoryspac
esta
rti
ngfr
omt headdres
s0x000
h.Thispartoft
heme morys
hou l
dnotbeaccess
edoralt
eredexp
lici
tl
y
byt
heass
e mbl
yscr
ipt
.It
shouldbeconsi
der
edasprote
ctedandthu
s0 x
00XXisres
erv
edfortheprogr
aminstr
uct
ions.

4
1
Simulator run

Wait Read Instruction

NO NO YES
Transition Terminating
time? instruction?

YES

Load Instruction Load PC


in memory

Start simulation

Fi
gur 4:Pr
e3- oce
dur
eof
loa
dingi
nst
ruc
ti
oni
ntome
mor
y

Thefl
owchartin Figur
e3-4s howstheprocedu r
eofl oadi
ngt heinst
ruc
tionstoredinthef i
letothememor yb ythe
mic
roproc
e s
sor.Themi croproces
sorre a
dsonei nstr
uc t
iona tat i
me.I fthei nst
ruct
ioni snotthet e
rmi nat
ing
i
nst
ruct
ionitisloade
dintome moryatthetr
a ns
iti
ont i
me( clockgenera
tor).Ift
het r
ansiti
ontimeisnotyetreached
t
hemi c
roprocess
orenter
sa nidlesta
tewhe r
ei twa i
tsforthec l
ockgenerator
'strans
it
iont i
me.Whe nthetransit
ion
t
imeisproducedtheins
tru
c t
ionisloade
di nt
ome morya ndt heprocessi
srepeated.Whe nthetermina
ti
nginstr
u ct
ion
i
sencount
e r
edthePCr egi
sterisl
oadedwiththeaddressof thefirs
tins
truc
tion( 0
x0 00
0)a ndthesimul
ati
onstarts
.

4
2
Thes
imu
lat
iont
henc
ont
inu
es:

Start simulation

Read PC

Wait Load MAR

NO Transition Wait
time?

NO
YES

Read Memory Transition


time?

YES
Wait Decode

NO Transition NO End of YES


time? program?

YES
Print Status
Execute
instruction

End simulation

Increment PC

Fi
gur 5:I
e3- nst
ruc
ti
one
xec
uti
onf
lowc
har
t

Inst
ructi
one xecuti
ons ta
r t
swithr eadingt hec ontentoft hea ddre s
ss tor
edint hePCr egist
e r(a ddres
softhef irs
t
programi ns
tructi
on)whi chisloadedi ntot heMAR.The n,theme mor ywa i
tsfort het r
ansit
iont imea ndr e
a dsthe
contentofthea ddressst
oredint heMAR.Thec ontentoft heme mor ylocat
ioni sthe nloadedi ntot heMBR( read
me mor y
).Inthene xts
tepthemi c
ropr ocessorde codesa ndr ecognis
e stheinstruction.Ifthei nstructi
onisnott he
ter
mi nati
nginstructi
on,theinst
ructioni se xec
u t
eda tt hetransiti
ont i
me .Ani ns t
ruc t
ioncanb ema deoutofma ny
microinst
ruct
ionsa ndhowe ver,
ea chmi croinst
ruc ti
oni sexecuteda tthetransit
iont imeitma yt a
k esevera
lclocksto
executeoneinstructi
ons.
Af t
ertheins t
ru c
tionha sb eene x
e c
u t
e dthePCi si
ncr e
me ntedandpoi ntstoane wme mory
addresswhereanothe ri
nstr
ucti
oni sstored.Thepr ocessrepeatsuntilt
het er
mi natinginstr
u c
tionha sbeenreac
he d.At
theendas mallreportofs
t a
tesofallr
e gi
stersands pecif
icme mor ya ddressca
nb epr intedtothes c r
ee n.

4
3
3
.5 Mi
cropr
oce
ssorDe
sig
n
Themi
cr
opr
oce
ssorc
ons
is
tsof
the
sepa
rts
:
 Cont
rol
Uni
t
 Re
gis
ter
s
 Ar
it
hme
ti
clo
gicu
nit
 I
nst
ruc
ti
ons
et
 Me
mor
y
 Me
mor
yst
ack

AX
AH AL

ALU B
C
D
E
H L

MEMORY
MAR
MBR
Control
unit PC

Stack

Fi
gur 6:Bl
e3- ockd
iag
ramof
themi
cr
opr
oce
ssor

Themicr
oproc
essorha
s5g e
neralpurposer
egist
erAH,B,C,D,E.An8-bita
ccumul
at
orregi
ste
rALisus
edtos
tore
t
heres
ult
sofari
thmeti
candlogi
coper a
ti
onsasnootherr
egi
st
erisa
bletodoso.A16-bi
treg
ist
erAXi
smadeoutof
AL(l
owb i
ts
)andAH( highbit
s).I
tsma i
npurposei
stopr
ovi
deaful
l16-
bitmemoryt
rans
fer
.
Speci
alpurposer e
gist
ersLa ndH a reusedtostore1 6-
bitme morya ddresses
.Regis
terMAR( Memor yAddres
s
Regis
ter
)a ndMBR( MemoryBu f
ferRegis
ter
)area ss
ociat
edwithme mor ytos t
oreame mor yaddre
ssandme mory
data
.Theser egi
st
erarenotdir
ectl
ya c
cess
ibl
etotheu se
rb utca
nb ei
ndi r
e c
tlyacces
sonlythroughtheregi
sterHand
L.There g
isterPC( Progra
m Cou nt
er)isuse
dt os t
oretheinst
ruct
ionpr ogram poi
nterwhichpo i
ntstoame mory
l
ocati
onwi ththeprograminstr
ucti
ons.Theusercannotdirec
tl
ya l
te
rt hepoi nt
erandcanonl ytodos othrought
he
contr
olf
lowi nst
ruct
ions.Themicr
oprocess
oral
soc ont
ainsasta
ckwhi c
hi sanotherwayofstori
ngandprocessi
ngdat
a
comparedtoa cc
umu l
atorandregi
ste
rbasedmachines.

4
4
3
.5.
1Cont
rol
andTi
mingDe
sig
n
Theclockg e
nerat
oriscont
ainedwithi
ntheCont r
olUni t(Figur
e3 -6).I
tde t
erminesthespeedofinst
ruct
ion
ex
ecut
ion.Incr
easi
ngordecr
easi
ngthespee
dofs i
mula
tionisdonethroughthi
selement.Thecont
roluni
tisusedto
ge
nera
tet wos t
ate
s1a nd0 ,whichdete
rminesthecu r
rentst
a t
eoft hemicroproc
e s
sor
.Thewhol einst
ruct
ion
ex
ecut
ioniscontr
oll
edbytheClockunit
.Eachsta
teca
nb eprint
e dtothescr
eendeter
mi ni
ngtheoper
ati
onthathas
bee
npe r
formedduri
ngthecl
ockti
me .
Thevalueoft
hespeedisexpre
ssedinHert
z.
Re
qui
re
men
ts
 a
cce
ptaf
lo
ati
ngpo
int
snu
mbe
rtod
ete
rmi
net
hei
nit
ia
lspe
edof
simu
lat
ion
 c
ons
tant
lyr
una
lon
gsi
det
hes
imu
lat
ion(
thr
eadi
mpl
eme
nta
ti
on)

3
.5.
2Re
gis
terDe
sig
n
Regi
ste
rsareusedtotemporar
il
ystoreinformati
oninb inaryfor
mat
.Theinf
ormati
onstor
edinregi
st
ersi
sthen
pre
paredtobeproces
sedbythemicroprocess
or.Ther
ea rediff
ere
ntt
ype
sofre
gist
ers
.Genera
lpur
poseandspe
cia
l
re
gis
ters
.Spec
ialr
egis
ter
shaveanadditi
onalfunct
ionfore x
amplemaybeus
edwhe nacc
essi
ngex
ter
nalmemoryor
re
sult
sofar
it
hme t
icoper
ati
onsa
rest
or e
di ntheaccumul
ator.
Re
qui
re
men
ts
 8
-bi
tre
gis
ters
iz
e
 wr
it
epr
ote
cti
on
 i
nte
rna
ll
ythev
alu
eiss
tor
edi
nbi
nar
yfor
mat
 r
egi
st
era
blet
oloa
dandr
etr
iev
eva
lue

De
si
gn
Al
lre
gis
ter
sare8-
bitwi
deandt
husthebi
gge
stpos
si
bl
enumbert
hatca
nb est
ore
dis2
55orFFi
nhe
xade
cima
lfor
mat
.
Wri
tepr
otect
ionbi
tmustb
esetpr
iort
hewri
ti
nganewva
luet
othere
gis
ter.

B register

0 1 1 0 1 1 1 1

Fi
gur 7:8
e3- -bi
tre
gis
terdi
agr
am

Figur
e3 -
7c onta
insaregi
s t
erthatstor
estheval
ue0110111
1whi c
hi s111i
ndec i
malfor
mat.16-
bitre
gist
eris
const
ruct
edo utoftwo8-
bitregis
ter
s.Forexa
mple:t
here
gis
ter
sandLa ndHwhichtoget
hera
recap
ableofst
ori
nga
16-bi
tval
u e
.Whe nthemicroproce
ssoracc
esse
sthememory
,Hs t
andsforhi
ghe
r8-b
itsandLforl
ower8b i
tsofthe
me moryaddres
s(Figu
re3-
9 ).

4
5
16-bit memory address

H register L register

0 1 1 0 1 1 1 1 0 1 1 0 1 1 1 1

Fi
gur 8:1
e3- 6-b
itr
egi
st
erdi
agr
am

3
.5.
3Ins
truc
tionSe
tDe
sig
n
I
nst
ruc
ti
onsetde
fi
nest
heoper
ati
onstha
tthemic
roproc
essori
sabl
etope
rfor
m.Thede
sig
noft
hei
nst
ruc
ti
ons
eti
s
mai
nl
ybase
donthemic
ropr
oce
ssorI
ntel
MCS -
51inst
ruct
ionse
t.
Re
qui
re
men
ts
 a
ri
thme
ti
candl
ogi
cope
rat
ions
 r
egi
st
era
ndme
mor
ytr
ans
ferope
rat
ions
 c
ont
rol
fl
owi
nst
ruc
ti
ons
De
si
gn
I
nst
ruc
ti
ons
etde
sig
ncons
is
tsof
def
ini
ng:
 t
hes
iz
eof
ins
tr
uct
ion
 ope
rat
ions

Eachins
tru
c t
ioncons
is
tsoft
woparts
: operati
onandoperand.Thelengt
hofthei
nstr
u c
ti
onis16bi
ts
,wheret
hefi
rst8
bit
srepr
esenttheoper
ati
onandt
hel owe r8b i
tstheoper
andifitisre
quir
ed.Si
nce8b i
tsa
reavai
l
abl
etodist
ing
uish
theoper
ati
on, t
herei
sama xi
mum numb e rofdif
fer
entopera
tionswhic
his256.Thisnumberofi
nst
ruc
ti
onsisl
arge
enoughtoaccommodateal
lt
hepl
anne dinstruc
ti
ons.

instruction

operation operand

0 1 1 1 0 0 1 0 0 0 0 0 0 1 1 1

Fi
gur 9:I
e3- nst
ruc
ti
ond
esi
gn

Forexa
mple,i
nFigu
r e3-9
,theopera
ti
onsi
s(011100
10)2whi
chisareg
ist
ert
rans
ferope
rat
ionst
hatmov
es,t
he
oper
and(0
00 0
111
)2intoALreg
ist
er.
Insy
mboli
cfor
mtheope
rat
ionwou
ldbewri
tt
enas:
AL ← direct value

a
ndi
ntheAs
semb
lyl
ang
uag
e

4
6
MOV AL,%7d

The
rea
ref
ourt
rans
feri
nst
ruc
ti
ons
:
 MOV
 S
TA
 PUS
H
 POP
The
rea
redi
ff
ere
ntMOVi
nst
ruc
ti
onswi
tha
nex
ampl
eande
xpl
ana
ti
ons
:
 r
egi
st
er–r
egi
st
ert
rans
fer MOV AL,B -
copi
esv
alu
eBi
ntoALr
egi
st
er
 r
egi
st
er–di
rec
tva
luet
rans
fer MOV B,%34D -
mov
esd
ire
ctv
alu
e34i
ntor
egi
st
erB
 r
egi
st
er–me
mor
ytr
ans
fer MOV %M,B -c
opies8b
itsf
romBr
egi
st
eri
ntoame
mor
y
l
ocat
ion%M
 r
egi
st
er–me
mor
yfu
llt
rans
fer STA AX -
copi
es16b
itsi
ntomemor
yfr
omAXr
egi
st
er
c
ompose
dofAHa ndAL
 r
egi
st
er–s
tac
ktr
ans
fer PUSH %S,AL -
copi
esv
alu
eALont
othes
tac
k
 me
mor
y–r
egi
st
erf
ul
lt
rans
fer MOV AX,%M -
copie
s16bit
sst
ore
dint
heme
mor
yloc
ati
on%M
i
ntoAXreg
ist
er
 me
mor
y–r
egi
st
ert
rans
fer MOV %M,AL -c
opie
s8bit
sfr
omALre
gis
teri
ntot
he
l
ower8bi
tsi
ntheme
moryl
ocat
ion%M
 s
tac
k–r
egi
st
ert
rans
fer POP %S,B -
popsva
lueou
tfr
omt
hes
tac
ktot
he
r
egi
st
erB
Regi
ste
rAL,AH, B,C,D,
E,LandHc a
nb eu
sedinever
ytrans
feri
nst
ruct
ion.However,whe
n1 6bit
sarer
equi
redt
o
st
oreorre
tri
evedat
afr
omthememoryonl
yAXr eg
ist
eri
scapabl
eofacce
ptingandst
oring16-
bitv
alues
.TheSta
ckis
re
prese
ntedby%S,memor
yby%Manddi
rec
tval
uesby%xxD.
As s
emblyl
anguagesynt
axandsemanti
csi
sdesc
rib
edlat
er
i
nthischa
pter
.

Ar
it
hme
ti
candl
ogi
cope
rat
ions
:
 ADD–a
ddi
ti
on[
+] ADD AL,B -sumstheval
uesst
ore
dinr
egi
st
erBa
ndAL,a
nd
st
orest
here
sul
tinAL
 S
UB–s
ubt
rac
ti
on[-
] SUB AL,D -sub
trac
tsthev
alu
eDf r
om t
hev
alu
est
ore
dinAL
andst
orest
here
sul
tinAL
 MUL–mu
lti
pl
ic
ati
on[*] MUL AL,L -mu l
ti
pli
cat
ionofregi
st
erALa
ndL,a
ndr
esu
lti
s
copi
edint
oALr eg
ist
er
 DI
V–di
vi
son[÷]
i DIV AL,AH -di
vi
desALb
yAHr
egi
st
era
ndc
opi
est
her
esu
lti
nto
AL
 I
NC–i
ncr
eme
nta
ti
on[++] INC B -
inc
rea
sesv
alu
eint
her
egi
st
erBb
y1
 DEC–de
cre
ment
ati
on[-
-] DEC L -
dec
rea
sesv
alu
eint
her
egi
st
erLb
y0
 NOT–l
ogi
cal
not
[~] NOT C -
rev
ers
esb
itsi
nther
egi
st
er
 ORL–l
ogi
cal
or[] ORL AL,L -
per
for
mslogi
cal
ope
rat
ionORonALa
ndLr
egi
st
er
a
ndres
ult
stor
edi
nAL
 AND–l
ogi
cal
and[&] AND AL,B -pe
rfor
mslogi
caloper
ati
onAND onAL a
ndL
r
egi
st
erandr
esu
ltst
ore
dinAL

4
7
 XOR–l
ogi
cal
exc
lus
iveor[^] XOR AL,D -pe
rformslogi
calope
rat
ionEXOR onALa
ndL
r
egi
st
e randr
esul
tst
ore
dinAL
Onl
yALre
gis
teri
sca
pab
leofpe
rfor
minga
ri
thme
ti
candl
ogi
cope
rat
ions
.Ther
esu
ltsofe
ver
yope
rat
ioni
sst
ore
din
t
heALr
egi
st
er.
S
tac
ksu
ppor
tst
hes
ear
it
hme
ti
candl
ogi
cope
rat
ions
.St
acki
nre
pre
sent
edb
yins
ymb
oli
cfor
mby%S.
 ADD ADD %S -
sta
cka
ddi
ti
on
 S
UB SUB %S -
sta
cks
ubt
rac
ti
on
 DI
V DIV %S -
sta
ckdi
vi
si
on
 MUL MUL %S -
sta
ckmu
lti
pl
ic
ati
on
 AND AND %S -
sta
ckANDf
unc
ti
on
 ORL ORL %S -
sta
ckORf
unc
ti
on
 XOR XOR %S -
sta
ckEXORf
unc
ti
on

Cont
rol
fl
owi
nst
ruc
ti
ons
:
 DJ
NZ-
decrement
andj
ump DJNZ B,jump1 -de
creme
ntsthev
alu
eofregi
st
erBby1a
ndj
umpi
f
i
fnotze
ro note
qual
zerotot
headdr
essj
ump1
 CJ
NE–c
ompar
efi
rs
ttwooper
andsCJNE AL,%3d,jump1
a
ndj
umpinnotequ
al -compar
esva
luei
nreg
iste
rALwit
h3andi
fthe
rea
re
notequ
alj
umptotheaddre
ssj
ump1
 CJE–compa
refi
rs
ttwoope
rands CJE B,%02h,jump1
andj
umpifequ
al -compa
resva
luesi
nregi
st
erALwi
th2a
ndi
fthe
y
ar
eequa
ljumptothea
ddres
sju
mp1
 J
Z–j
umponz
ero JZ jump1 -j
umpi
fze
rof
l
agi
sse
t
 J
NZ–j
umponnot
zer
o JNZ jump1 -
jumpi
fze
rof
la
gisnot
set
 J
C–j
umpi
fca
rrys
et JC jump1 -
jumpi
fca
rryf
l
agh
asb
eens
et
 J
NC–j
umpi
fca
rrynot
set JNC jump1 -
jumpi
fca
rryf
l
agi
snot
set

Addi
ti
ona
lins
tr
uct
ions
:
 CLR–c
lea
rfl
ag CLR CA -
cle
arsc
arr
ybi
t
 CLR–c
lea
rre
gis
ter CLR AL -
cle
arsr
egi
st
er(
set
stoz
ero)
 NOP–noope
rat
ion NOP -
noope
rat
iondu
ringonec
loc
kti
me

Thec
ompl
et
eins
tr
uct
ions
etc
anb
efou
ndi
nAppe
ndi
xBwi
thi
tsa
ssi
gne
dbi
nar
yorh
exa
dec
ima
lnu
mer
icf
orma
t.

3
.5.
4Ex
ter
nal
Memor
yDe
sig
n
Memoryi
susedtotemporar
il
ysavedat
athatmayb eretr
ieve
da taa
lte
rsta
ge.Si
nce
,theins
tru
cti
onoperat
ionis8-bi
t
wi
deandtheopera
ndc anals
oa c
quir
eu pto8b i
ts,therequir
ednumb e
rofb i
tsa
ttheme moryloc
ati
onis1 6.The
memorya
ddres
sisuniqu
elydef
inedbyusng2×8b
i its.
Whe rea
s,al
lt
heregis
ter
sar
e8-bi
twide,t
woregi
stersmu s
tbe
us
edtoac
cesst
heme mory.Allt
heposs
ibl
ea ddr
esslocat
ionscanbeexpr
essasani
nter
vals
howninFigure3 -
10.The

4
8
f
ir
st8bit
sar
ecal
le
dhig
herbi
ts(
H)a
ndt
hel
owe
r8b
itsa
rel
owe
rbi
ts(
L).Ame
mor
yaddr
essi
str
adi
ti
ona
ll
y
e
xpre
sse
dinh
exa
deci
mal
for
mat
.
Ma
the
mat
ic
all
yex
pre
sse
dea
chme
mor
yaddr
essxi
sfr
omt
hei
nte
rva
l:
x  <0; ) ∩ (; FFFF>

H∩L

 

(FFFF)

H
L

Fi
gur 10:I
e3- nte
rva
lde
fi
ni
ngt
hes
etof
ava
il
abl
eaddr
ess
es

Theforma
tofanaddre
ssis(XXXX)1,whe
6 reXЄ<0 ;F>.
Examp
lesofc
orr
ecta
ddr
ess
es:3
333
,CCCC,
FF2
3,2
210
.
Deno
t i
ngt
hehe
xad
e ci
malnumeri
cfo
rma t
:0x
3333
,0x
CCCC, 0x
FF23an
d0 x
2210.
Re
qui
re
men
ts
 me
mor
yaddr
essc
ompos
edof
16b
its
 e
achl
oca
ti
ont
oac
commoda
te1
6bi
ts
 WRI
TE–s
tor
einf
orma
ti
onf
romr
egi
st
era
tap
art
ic
ula
raddr
ess
 READ–r
etr
iev
eda
taf
romas
pec
if
ica
ddr
ess

An
aly
si
s
Memoryar
chit
ect
ureisbas
edonthe3
-di
me nsi
onals
pac
e(Figu
re3-
11)
.Wher
etheXandYaxi
sde
fi
nethea
ddr
ess
a
ndtheinf
ormat
ionisst
oreda
ttheZaxi
s.TheFig
ure3-
12showst
hememor
yarchi
te
ctu
rei
nacub
icf
orm.

Y 01 1
01 10
101 010
01 11
01 10
{A0,32} 001 010
32 01 0
01
10

01
10

01 01
01
10

1 01 01
1 01 01 01
00

10 1 1 1
10 10 10 01
01

00 10 01 01
01 01 01
01

01 1 1 0
10 00 01
11

0 00 01
01
10

01
A0 X 01 01
01 01
011 101
1 01
10 01
00 01
01 01
0
Z=16

Fi
gur 11:Me
e3- mor
yar
chi
te
ctu
re Fi
gur 12:Me
e3- mor
yar
chit
ect
urei
ncu
bic
expr
ess
edi
ncu
bicfor
m

4
9
TheXaxisdef
inest
hehigher8b i
tsa
ndt heYa x
ist
helower8b i
tsofanaddre
ss.
TheZa xiscanholdu pt o1 6bi
tsat
eac
haddress
.Thu s,t
heu nionofa l
lpos si
bl
eX andY v alu
esc anproduceupt o655 3
6c omb inat
ions.Each
combi
nat
ionholds16bit
swhichis655361 6=104857 6bi
tsavai
l
ablei
ntheme mory
.He nce,1b y
tec ontai
ns8b i
ts
,
1046576÷8=1 31072bytesor ≈131KBof memory.Toil
lus
trat
ethesi
zeofme mor
y,print
ingthec haract
erval
ues
f
romeachposs
iblel
oca
tion(eachl
ocat
ionc ont
ai
ns2charac
ter
s)wo ul
dfi
l
l upove
r2 0p
agesinthisreport.
Twos pe
cia
lregi
st
ersa
reinv
olve
dwit
hme moryr
eadandwr
it
eoper
ati
onswhi
charetheMBRa ndMAR.Theme
mor
y
buff
erreg
ist
er(MBR)i sus
edtost
oretheval
uetobewri
tt
enandval
uesre
tri
evedfrom me
moryandtheme
mor
y
addr
essre
gis
ter(MAR)isuse
dtost
oret
headdre
ss.
Wr
it
eop
era
ti
on
LOAD MAR → LOAD MBR → WRITE

MICP MAR MBR MEMORY

write_mar()

write_mbr(value)

write_signal()

get_address()

return_address()

get_value()

return_value()

Fi
gur 13:Me
e3- mor
ywr
it
eope
rat
ion

Themicr
oproce
ssorwrit
estherequi
redaddressintoMARr eg
ist
erandt hevalu
etobestor
edint
otheMBR. Thena
wri
te
_si
gnal(
)issenttotheme mory.
Theme mor ythe
ntak
escontroloverthewri
ti
ngproce
dure
.Firs
tl
y,i
tre
tri
eve
s
t
heval
uestor
edintheMARa ndusesi
tasapo i
ntertothememorylocat
ion.Then,i
tre
tri
eve
stheva
luefr
omtheMBR
andwri
te
sthememor yatthere
quir
edlocat
ion( MAR) .

5
0
Re
ado
per
ati
on
LOAD MAR → READ

MICP MAR MBR MEMORY

write_mar()

read_signal()

get_address()

return_address()

write(value)
return_value()

Fi
gur 14:Me
e3- mor
yre
adop
era
ti
on

Toretr
ievethedatast
oredatapart
ic
ulara
ddressint
heme mor
y,t
hemicr
opr
oces
sorwrit
estherequir
edaddre
ssi
nto
t
heMARa ndsendsareads
ignal
totheme mory.Thememorythe
ndis
pat
che
sag e
t_si
gnal
()whic htel
l
stheMARt o
re
tur
nt hevalueitc
ont
ains(memoryaddre
ss)
. Thememorythe
nusest
heMAR'sva
luetodet
erminetherig
htmemory
l
ocat
ion,re t
rie
vestheda t
aa ndwr i
tesitintotheMBR.TheMBR t he
ni mpli
ci
tlyretu
rnst hev a
luetothe
micr
oprocessor.

3
.5.
5St
ackDe
sig
n
Thest
a cki
soffi
rst
-i
nfirs
t-
outdatastr
uct
ureanditi
sanalt
ernat
ivewayofdat
aproce
ssi
ng.Theinf
ormati
oni
sstor
ed
i
nlast
-infi
rs
t-ou
tma nnerwherethela
sti
tempu s
hedontothestackisatt
hesameti
methef i
rs
tit
emtob er
etr
iev
ed
fr
omthes t
ack(Mano,1993).Av er
ysi
mpli
fie
dmode lof
astackisshownint
heFigu
re3-15
. Thest
ackpoi
nte
ral
wa y
s
hol
dstheaddres
soflas
tl
yinse
rtedit
em.
Theoper
ati
onassoc
iate
dwiththestac
kareinse
rti
ona nddel
eti
onofi
te
ms( Mano,1993)
.Theopera
tionofi
nse
rti
on
i
scall
edPUSHa ndt heoper
ationofdel
etioniscall
edPOP.The s
eoperat
ionareonl
ysimula
tedandnome mory
del
et
ioni
sperf
ormed.Theoper
a ti
onsonl
yincre
me ntordec
rementt
hest
ackpoint
er(a
ddres
s).

Top of the stack

0
Stack pointer 3
5
Bottom of the stack 10

Fi
gur 15:Fu
e3- nda
ment
ala
rchi
te
ctu
reof
a s
tac
k

5
1
ThestackinFig
ure3-15cont
ai
ns8tra
yswhi
chcanbefi
l
ledu
pwithval
ues
.Thest
ackpoi
nte
rissi
mplyareg
ist
ert
hat
conta
instheaddres
softhelas
tl
yins
ert
edit
em.Si
nce,t
hest
ackhas8tr
aysandt
hus8me moryloc
ati
onsthest
ack
point
ermu st
atle
astcont
ain3bi
tst
obeabl
etor
etr
iev
eall
dat
aval
ues:
log2(8) = 3 bits

Re
qui
re
men
ts
 a
blet
ost
orea
tle
ast
64i
te
ms
 e
achl
oca
ti
onh
olds8b
its
 a
blet
ope
rfor
msi
mpl
ear
it
hme
ti
candl
ogi
cope
rat
ions
 a
blet
opu
sha
nit
emont
othes
tac
kfr
oma
nyr
egi
st
erord
ire
ctl
y
 a
blet
opopa
nit
emo
utf
romt
hes
tac
ktoa
nyr
egi
st
er

De
si
gn
Thesta
ckwil
lbeimpl
ement
eda
sas t
anda
lonecompone
ntc ont
rar
ytoi
mpl
eme
nta
ti
ona
sapa
rtofme
mor
y.The
des
igni
ssi
mil
art
othememor
yde
scr
ibe
dinthepr
eviou
ssub-
chapt
er.

address item
0x30 00000000
0x28 00001110
0x20 11111111
Stack pointer
0x10 0x18 10000000
0x10 11010000
0x08 11010111
0x00 10110101

Fi
gur 16:S
e3- tac
kde
sig
n

Thestackpoint
ercanmoveu pordowna longsi
dethesta
ck.Howe ve
r,whenitre
ache
sthebottom ofthesta
ckit
ca
nnotmov efur
the
rdowna ndsta
ysatthebot t
ompo si
ti
on.Thesamerulea
ppli
eswheni
trea
chesthetopofthest
ack
(s
tac
ki sf
ul
l).Ther
equi
reme nti
stobeabletostorea
tleas
t64ite
msa ndthus6
4tray
sisa
vai
labl
einthetr
ay.Itwi
llbe
t
heresponsi
bi
lit
yoft
heusertoensur
ethatthestackl
i
mi t
sarenotex
ceeded.

Pu
sho
per
ati
on
Thefl
owc harti
nFigur
e3-17showingtheprocedur
eofcal
li
ngthePUSHope ra
ti
on.
Whe ninse
rti
nganewit
emonto
t
hestac
k ,thest
ackcheck
swhe t
he rt
hereisavai
la
blespa
ce.Ify
es,i
taddsthenewi
tem onthetopoft
hesta
ckand
i
ncre
me ntsthest
ackpoi
nters
oi tpoi
ntsatthenewite
m. I
fthest
acki
sful
l,
noitemi
saddedontothest
acku
nles
san
i
temhasb eenpoppedoutf
romthes t
ack.

5
2
PUSH

YES
Stack full?

NO

Add new item Operation finished

Increment stack
pointer

Fi
gur 17:S
e3- tac
kpu
shope
rat
ion

Po
pop
era
ti
on
POPf uncti
onr e
tri
evesa nit
emf r
omthest
ack(Figure3-2
0). Thenthesta
ckchecksi
fthest
ackpoi
nte
rhasre
achedthe
bott
omof thest
ack.I
f no,thesta
ckpoi
nte
risdecrementeda ndpoint
satthenextit
emb el
ow.Whenthest
ackpoi
nter
rea
chedt hebott
omof thesta
ckandpopfunct
ioniscal
ledthei t
emisst
ill
retr
ieve
db utnodec
rement
ati
onofthest
ack
poi
nterispe r
for
meda ndt hesameit
emisr
e t
ri
evedwhe neverthepopfunct
ioniscal
l
ed.

POP

Pop item out

YES
Bottom of
Operation finished
the stack?

NO

Decrement stack
pointer

Fi
gur 18:S
e3- tac
kpopope
rat
ion

S
tac
kisa
blet
ope
rfor
msi
mpl
ema
the
mat
ic
sandl
ogi
cope
rat
ions
:
 a
ddi
ti
on,
sub
tra
cti
on,
mul
ti
pl
ic
ati
ona
ndd
ivi
si
on

5
3
 AND,
ORa
ndEXOR

Thee
xampl
esof
sta
ckpe
rfor
mingma
the
mat
ic
ala
ndl
ogi
cope
rat
ionsa
rea
dopt
edf
romMa
no,
199
3.
Thema
the
mat
ic
ale
xpr
ess
ion1
2+2+1
4,wou
ldb
eca
lcu
lat
edonas
tac
kass
howni
ntheFi
gur
e3-
19.

PUSH 12 PUSH 2 PUSH 14 PUSH + PUSH +

14 14 14
2 2 16 16
12 12 12 12 28

Fi
gur 19:Ev
e3- alu
ati
onof
expr
ess
ionA+B+C

Theaboveex
amplee v
aluat
esthee x
pressi
onA+B+C. First
ly,a
llt
hre
ev a
lue
sarepu s
hedont hes t
ack.Thea ddit
ion
oper
ati
on(+)isthencall
edtwice.Thef i
rs
tti
mei tsumst hela
stit
eminser
tedwit
ht hefol
lowingitem( 14+2 )
. The
st
ackpoi
nte
risthendecr
eme nte
da ndtheres
ultofA+Bi spla
cedontot
hestac
k( v
alue2isrewrit
ten).Notic
e, t
hatthe
val
ue14iss
til
lpres
entinthestac
kb utisnomo reacc
essibl
enorrequi
red.
Thesecondtimet headdit
ionope rat
ionis
cal
le
dthest
acksumsthevalues16and1 2whicheval
uatethebott
omof t
hestac
ktothev a
lue2 8.
Now, thisexpress
ion
hasbee
ncal
cula
tedandcanb epoppedo utoft
hes t
ack
.
Anot
hermor
ecompl
i
cat
ede
xpr
ess
ioni
s:2×3+1
70–8×1
3
Not
ic
etha
tmu
lti
pl
ic
ati
onmu
stb
eev
alu
ate
dpr
iort
oaddi
ti
onors
ubt
rac
ti
on.

PUSH 2 PUSH 3 PUSH × PUSH 170 PUSH +

3 3 170 170
2 2 6 6 176

PUSH 8 PUSH 13 PUSH × PUSH -

13 13 13
8 8 104 104
176 176 176 72

Fi
gur 20:Ev
e3- alu
ati
onof
expr
ess
ionA×B+C–D×E
Theexpr
essi
onshowninthea
bov
efi
gur
eismor
edi
ff
ic
ultt
oev
alu
atea
smu
lti
pl
ic
ati
onmu
stb
eev
alu
ate
dbe
for
e
addi
ti
onandsub
trac
ti
on.
Re
ver
sepol
i
shorpos
tf
ixnot
ati
onma
ybe
comeu
sef
ulwi
the
val
uat
ingt
hise
xpr
ess
ion:

5
4
AB*C+DE*-
i
nwhiche
veryoper
andf
oll
owsi
tsope
rands
.Thenot
ati
ons
howst
heor
derhowt
heope
randsa
ndope
rat
ionsa
re
pl
ace
dont
othest
ack
:
([
AB*
]C+)(
DE*
)-

3
.5.
6Ar
it
hme
ticLog
icUni
t
ALUi
sac
ompone
ntof
mic
ropr
oce
ssort
hat
per
for
msa
ri
thme
ti
candl
ogi
cope
rat
ions
.

Microprocessor
Main Bus
Zero flag
Arithmetic and
Logic Proccessor
Comparison flag
+ - × ÷ ~ |
& ^
Carry / Borrow flag

temp2

temp1

Fi
gur 21:Ar
e3- it
hme
ti
clog
icu
nit
arc
hit
ect
ure

TheALU c ont
ainstwotempor
aryre
gis
terwher
etheoper
andsfortheintendedopera
ti
ona r
es t
ored.Whe nan
oper
ati
onisper
formedbot
hoper
andsar
ereadf
romthet
empora
ryregi
st
ersa
ndt heoper
ati
onispr
oceeded.Theres
ult
ofanoper
ati
onistra
nsf
err
edtothemai
nb ust
otheALreg
ist
er.Reg
ist
erfl
agsassoc
iat
edwit
ha r
it
hme t
icopera
ti
ons
ar
e:
 z
erof
la
g–de
ter
mine
swhe
the
rthet
wov
alu
esa
ree
qua
l
 c
ompar
is
onfl
ag–accompl
is
hedbysub
tra
cti
on.I
fther
esul
tisg
reat
ert
han1thefl
agispos
it
ive
.Ift
heyar
e
e
qua
lthefl
agisse
ttozer
oa ndi
ftheres
ulti
snegat
iv
ethefla
gisnega
ti
ve.Pos
iti
ve:0000
0001,Equ
al:
0
0000
000,Neg
ati
ve:1
1111
111
 ca
r r
y/borr
owf l
ag–showsanover
flowofareg
ist
er.Forex
amplei
fthetwov a
lues250and2
5 0areadd
e d.
Thee x
pe c
tedres
ulti
s500.Si
ncetheALr e
gis
tercanonl
yhold8bitstheact
ualre
sulti
s88.Noti
fi
cat
ion
aboutt
hiseventi
sdonet
hroug
hthi
sf l
agwhi
chisse
tto1.Thes
amepr oc
e d
ureappl
ie
sformul
tipl
i
cati
onand
su
b t
rac
tion.

5
5
SUBSTRACTION

Load temp1

Load temp2

NO
Temp2 = temp1? temp1 - temp2

YES

NO YES
temp2 > temp1?
Set zero flag

Comparison = 0 Set carry flag

NO
Register
Load stack Comparison = -1
operation?

YES

Load AL

Operation finished

Comparison = 1

Fi
gur 22:Fl
e3- owc
har
tof
sub
tra
cti
onpr
oce
dur
e

Thesubt
rac
ti
onpr ocedureisshownintheabovef i
gure
.TheALU' stemporaryreg
ist
ertemp1a ndtemp2a refi
rst
ly
l
oade
dwiththerequir
edv al
u e
s.Thenthesubt
ract
ionisperf
ormedtemp1-temp2.Ift
heresul
tisnega
ti
veandt husthe
t
emp2isbigg
erthanthete mp1,thecarr
yfl
agissetandthec ompa
ris
onflagisse
tto-1.Ift
her e
sul
tofsubtr
a ct
ionis
ze
ro,
thezer
oflagisse
t a
ndt hecompari
sonfl
agissett
o0 .I
ftheval
uesar
enot equa
l,t
heprocedurer
ecognis
esthatthe
t
emp1isbi
ggerthanthetemp2a ndset
sthecompa r
is
onf l
agto1.Thelast
conditi
onistodete
rminewhe t
hertheresul
t
i
stobel
oadedintotheALr egis
terorpushe
dont hestac
k.
Ex
ampl
es:
temp1 = 12;
temp2 = 11;
result = temp1 – temp2; 1 = 12 - 11
Flags: Comparison = 1
Carry = 0
Zero = 0

5
6
temp1 = 10;
temp2 = 12;
result = temp1 – temp2;
253 = 10 – 12 (overflow)
Flags: Comparison = -1
Carry = 1
Zero = 0

temp1 = 10;
temp2 = 10;
result = temp1 – temp2;
0 = 10 – 10
Flags: Comparison = 0
Carry = 0
Zero = 1

3
.6 As
sembl
ySy
nta
xandCompi
le
r
TheAs s
embl
yla
ngua
gedefi
nesthesy
ntaxandthecompil
ergivesase
mant
icmeani
ngtothesy
nta
x.Thesynt
ax
def
inest
hegr
ammat
ic
alst
ruc
tur
eof as
ente
nce(i
nthi
sproj
ecti
tisali
ne)
.These
manti
csr
efe
rstot
hemea
ningoft
he
voc
a b
u l
ar
ysy
mbol
sar
rang
edwithi
nthats
tr
uct
ure(j
Guru
,2011).

3
.6.
1As
sembl
yLa
ngua
geSy
nta
x
Asse
mb l
yla
ng ua
geisalow-l
evelprogr
ammingla
nguag
eformi
cropr
oce
ssor
s.Thesynt
axi
nthi
spr
oje
ctwil
lf
oll
owt
he
conve
nti
ons.
TheAs semblyla
ngu a
g ei
nst
ruc
ti
onsar
ebase
dontheISAi
mplementa
ti
onofthemi
cr
oproc
ess
or.
Thel
is
t
ofal
li
nst
ruct
ionsca
nb efoundinAppe nd
ixB.
TheAs
semb
lyl
ang
uag
efol
l
owst
het
radi
ti
onc
onv
ent
ionsa
ndu
sest
heI
nte
l'
ssy
nta
x:
mnemonic destination, source

whe
rea
stheAT&Ts
ynt
axd
est
ina
ti
ona
nds
our
cea
res
wappe
dpl
ace
s.
Re
qui
re
men
ts
 di
rec
tva
lue
sinde
cima
lorh
exa
dec
ima
lfor
mat
 a
ll
owi
nde
nta
ti
oni
ncode
 c
omme
nts
 c
ase
-i
nse
nsi
ti
ve

Whenadi
rec
tval
ueise
nter
ed,
itmus
tbef
oll
owedbyalet
terdenot
ingit
snu
me r
icf
ormat
.Thet
wop ossi
blenumeri
c
f
ormsa
reav
ail
abl
e:D–decima
landH–hexade
cima
l.Ea
chv al
ueente
reddi
rec
tl
ymusthav
eapre
cedingchara
cte
r%
whi
chde
note
sadir
ectv
alu
e:
MOV AL, [%][VALUE][D/H]

Thenu
mbe
rshou
ldnot
bel
ar
gert
han2
55orFFi
nhe
xade
cima
lfor
mat
.
Ex
ampl
eof
loa
dingr
egi
st
erALwi
thad
eci
mal
val
ue:
mov al,%14d

a
ndi
nhe
xade
cima
l:
mov al,%40h

5
7
Comme
ntsc
anb
eadde
dtot
hes
our
cec
odes
epa
rat
edb
yas
emi
col
on:
; program loads register AL
; with a value 30h
mov al,%30h ; loading occurs here
; end of program

Codei
nde
nta
ti
oni
simpl
eme
nte
d,s
othe
rei
snodi
ff
ere
nceb
etwe
en:
mov b, %200d;comment

a
nd
mov b, %200d ; comment

Thel
ang
uag
esy
nta
xisc
ase
-i
nse
nsi
ti
vea
ndt
hust
hei
nst
ruc
ti
ons
:
MoV B,%210d

a
nd
MOV b,%210d

ha
vet
hei
dent
ic
alme
ani
ng.

3
.6.
2Compi
le
rDe
sig
n
Acompi
lerisacomput
erprog
ram whic
htra
nsf
ormssourc
ec odewr
it
teninaprog
rammi
ngl
ang
uag
eint
oanot
her
c
ompute
rlangua
ge,mos
tcommonlyint
oexe
cuta
blema
c hi
necode(Wi
kipedi
a,2
010e
).
I
nthispr
oje
ctt
hecompil
erg
ene
rat
esma
chi
nec
odeu
nde
rst
oodb
ythei
mpl
eme
nte
dsi
mul
at
or.
Thema
inpu
rpos
eof
t
hecompil
eri
stot
rans
for
m:
mov %al,30h

i
nto
10110101110000

whi
chi
sthef
orma
tint
erna
ll
yunde
rst
oodb
ythemi
cr
opr
oce
ssor
.
Re
qui
re
men
t
 s
ynt
axe
rrorc
hec
kca
pab
il
it
ie
s
 g
ene
rat
ingma
chi
nec
odef
romas
our
cef
il
e

Twospe
cia
l k
eywor
dsa
rere
qui
redt
ode
ter
minet
hes
tar
tandt
hee
ndofapr
ogr
am.
The
yar
eBEGI
NandEND.
The
pr
ogr
amlayouti
ssi
mpl
y:
BEGIN
<instructions>
END

5
8
Co
mpi
l
ingp
roc
edu
re

Compiler run

NO
File exists?

YES Print error

Contains NO
Compilation finished
BEGIN
END?

YES

Increment current line

Current line NO
<
total lines

YES

Read next line Current line = 0

NO Does
line contain
branch?

YES

Save in branch table

Fi
gur 23:Fi
e3- rs
tcompi
l
err
unpr
oce
dur
e

Thecompil
err
e a
dsthef
il
etwic
e.Onl
yoneinstr
uct
ioni
sal
lowedpe
rli
ne.Inthefi
rs
trea
d,thecompil
ersee
ksforthe
j
umpb ra
nches.Ifajumpb r
anchi
sfound,thebranc
hna meandposi
tionissave
dintoab ranc
ht abl
e.Thisis
par
ti
cul
ar
lyimporta
nti
nthesec
ondru
nwhe r
e,whenajumpise
ncount
ere
di t
ische
ckedaga
instt
hebranc
htabl
e.

5
9
Current line = 0

Increment line

Current line
<
total lines

YES

YES Any syntax Syntax NO


Record error
errors? correct?

NO YES

Create file Generate machine code

Is it a NO
jump?

YES

Compilation finished
Exists in
Branch table?

Create file
YES

Generate jump address

Fi
gur 24:S
e3- econdc
ompi
l
er'
sru
nwhi
chg
ene
rat
esma
chi
nec
ode

Figur
e3 -
24des c
ri
b esthes econdrun.Thelinenu mberissettozer
oa ndthefi
lere a
dingcanbep er
formedag a
in.The
l
ineisincr
ementedt os ki
pt heBEGI Nk eywor d.Thent henewl i
neisthenreada ndthesynta
xi schec
ked.Iftheli
ne
conta
insanerroritisrecordeda ndcompilat
ionpr oceedstothenextl
ine.Ift
helinedoe snotconta
inanysyntaxerror
anditisnotaj umpi nstructionapa r
ti
c ul
arma c
hinec odeisgenera
tedforthei nstr
ucti
on.Ifaju mpins
tructi
oni s
encounte
redtheb ranchna mei ssoughtintheb r
anchtable.Ift
hebranchisnotfou ndintheb r
anchtabl
eane r
roris
recor
ded.If
theb r
a nchisfoundaj umpa ddressisgener
a t
edfromtheb ra
nchtable
.
Whent
hecompi
lerrea
chedthela
stins
tr
uct
ioni
tcheck
sifi
thasenc
ounte
redanyer
rorduri
ngtr
ansl
at
ion.I
fthe
rea
re
nos
ynt
axe
rror
sinthesou
rcecode,anewfi
l
eisc
reat
edandthege
nerat
edmachinec
odeiswri
tt
enint
oit.

6
0
3
.7 Us
erI
nte
rfa
ceLa
yout
Theu s
erinte
rfa
cemu stprovideaneas
yac c
e s
sandfl
exibi
l
ity
. Theuserisall
owedtocompilea
ndrunthec
odewr i
tt
en
i
nthetextedit
or.Theinter
faceshoul
dprovideasimpl
enotif
icat
ionabou tcompi
lat
ionerr
orsands
houl
dnotall
owthe
use
rt orunu ncompiledc ode.Alli
nter
nalc ont
entsofthei mple
me ntedr e
gis
ters
,stac
ka ndmemoryshouldbe
di
splay
eda ndupda t
eddu r
ingtheexec
u t
iontoa l
l
owt heusertoimme diat
elyi
denti
fythecha
nges
.Ame s
sageshoul
d
beshowna tt
heen doftheexecut
ioni
nformingtheuserab
outs uc
ces
sfulsimula
ti
on.
Addi
ti
onal
ly
,theint
erf
aceshoul
d provi
debot
h deci
maland he
xadec
imalval
uef
orma
tal
ong
sidei
tsb
ina
ry
re
pre
sent
ati
on.
Anopt
iontoc
ha ng
ethespe
edofs
imul
at
ions
houl
dimplement
ed.
Theu
seri
nte
rfa
cec
ons
is
tsof
fi
vema
inp
art
s(Fi
gur
e3-
24)
:
 Ma
inMe
nu
 Te
xtEdi
tor
 Mi
cr
opr
oce
ssorS
tat
usPa
nel
 Compi
l
erOu
tpu
tBo
x
 Me
mor
yMa
p

Main Menu

Microprocessor status
panel

Text Editor

Memory map

Compiler output

Fi
gur 25:Us
e3- eri
nte
rfa
cede
sig
nla
you
t

Theoutp
utprodu
cedb yt
hecompil
erc
aneit
herbeasynt
axerr
ororasuc
cessf
ulc
ompi l
at
ionands
houl
dbeshownin
t
he“CompilerOutput”panel
.Themicr
oproce
ssorcomponent
s–r eg
ist
ers
,fl
ags,st
acka r
esi
tua
tedi
nt hebox
“Mi
cropr
oces
sorst
atu
sp a
nel”
.Thememorymapconta
inst
hecontent
sofal
lmemoryloca
tions
.

3
.7.
1Ma
inMe
nuLa
yout
Themai
nmenuiscompos
edoff
oursub
-menus
:File
,Si
mul
ati
on,Opt
ionsandHelp(Fi
gur
e3-26)
.TheFi
leMenuis
i
nte
nde
dtoprov
ideast
andar
dfi
l
ehandl
ingopt
ions–New,
Save,
Opena ndQui
t.TheSi
mulat
io
nsub-
menucont
ains

6
1
t
hesimu l
at
oropti
onstosimu
lat
ethescr
i ,Co
pt mpi
leopt
iont
oc ompi
let
hewri
tt
ena
sse
mbl
ycodeandSto
pb ut
ton
al
l
owst heusert
os t
opthesi
mu l
at
ion.TheShowDial
ogbut
tonshou
ldbri
ngupanewwi
ndowthatc
ontai
nsthe
micr
oinst
ruc
ti
onstha
thavebe
enperf
ormeddur
ings
imula
ti
on.
TheOpt i
onss ub-
me nual
lowstheusert
ochangethenumericbas
eforma toft
her e
g i
st
ersa
nds t
ack.Thecontentof
thereg
ist
e r
sforexamplecoul
db eshownindecimalfor
matifFormatDe ci
malissele
cte
d.IfHexadec
imalFormatis
sel
ect
edt hev a
luesareconver
tedintohexa
deci
ma lfor
ma .TheS
t etClo c
kopt i
onwi l
lal
low theusertoinputa
numeri
calvaluedefyi
ngthefreque
ncyoftheint
ernalcl
ockofthemicroproce
ssor.TheRefr
eshopti
onrefr
eshesthe
Stat
uspanel,
StackandMe morymap.

FILE SIMULATION OPTIONS HELP


New Simulate Format Decimal About
Open Step Format Hexadecimal
Save Compile Set Clock
Quit Stop Refresh
Show Dialog

Fi
gur 26:Ma
e3- inme
nuopt
ions

TheHelpmenuc
onta
insa
nopt
ionAb
outwhi
chpopsu
pane
wwi
ndowwi
tht
hea
uthor
'sde
tai
l
sandwe
bsi
tel
i
nkt
o
t
heproj
ect
'
swebs
it
e.

3
.7.
2St
atusPa
nel
andMe
mor
yMa
pLa
yout
Regi
st
erval
uesar
eshowninbot
hhe x
ade
cimalandbi
nar
yf orma
t.Theint
ent
ionistoprov
ideafix
edlay
outfor
re
gis
ter
swher
etheus
eri
snotr
equ
ire
dtosc
roll
downtodet
erminet
heval
ues.
Thereg
ist
ersa
respl
i
tint
othr
eegro
ups.
Thef
ir
stgr
oupcont
ainsgene
ralpurposeregi
st
erst
hatar
emostimpor
tantt
otheu
ser.Speci
alre
gis
ter
sareMAR,
MBR,PCet
c.ar
egro
upe di
nthesecondg r
oup.Thel
astg
roupi
scompos
edofALUfl
ags(c
a r
ry,c
ompari
son)andt
he
t
emp1andt
emp2reg
iste
rswhi
charep ar
toftheALUimpl
ement
ati
on

REGISTERS SPECIAL REGISTERS ALU FLAGS STACK

AL [0x00] 00000000 D [0x00] 00000000 0x04 0x00


AH [0x01] 00000001 E [0x00] 00000000 0x03 0x00
B [0x01] 00000001 0x02 0x12 ←
C [0x11] 00000011 0x01 0x11
0x00 0x01

MEMORY MAP

0x0000 12 32 73 46 32 21 a6 4e 3a af ..........
0x0000 12 32 73 46 32 21 a6 4e 3a af ..........
0x0000 12 32 73 46 32 21 a6 4e 3a af ..AB......
0x0000 12 32 73 46 32 21 a6 4e 3a af .....xc\”.
0x0000 12 32 73 46 32 21 a6 4e 3a af ...s.c.CC.
0x0000 12 32 73 46 32 21 a6 4e 3a fa ..........

Fi
gur 27:Re
e3- gis
ter
,St
acka
ndMe
mor
yma
pint
erf
acel
ayou
tde
sig
n

I
fthedec
imal
opt
ioni
sse
lec
tedi
nthemai
nmenuthehex
ade
cima
lval
ues(
[0x00
])arerewri
tt
eni
ntodec
imalf
ormat
(
[000])i
nbot
hst
acka
ndregi
st
erpa
nel
.I
nthememorypa
nel
thev
eryf
ir
stv
alu
eistheaddre
ssl
oca
ti
oninhex
adeci
mal

6
2
f
ormat(00
00 h–FFFFh)
.Thehexa
deci
malv
alu
einthemi
ddlea
retheact
ualva
lues
tor
edatt
hememoryloc
ati
ons
.
Eachmemoryloca
ti
onholdst
wohe
xade
cima
lval
ues
.TheASCIequ
ival
entoft
hememoryl
oca
tioni
spr
int
edonthe
ri
ghtha
ndside.

6
3
Cha
pte
r4

I
mpl
eme
nta
tio
n

4
.1 Si
mul
atorOpe
rat
ion
Thesi
mu l
a t
ori
sorac ont
aine
rtha
tc ont
ai
nstheimpl
ement
edmic
ropr
oces
sorandthei
nput
/out
putcommunic
ati
on.
Thesi
mu lat
oracc
eptsabinar
yfil
ewi t
hthebcexte
nsi
on.Iti
sas
sumedthatt
hef i
l
econt
ai
nsastr
ingof0'
sand1's
whi
chde f
inest
heins
truct
ions
.Theseins
tru
cti
onsar
epass
edtot
hemicr
oproce
ssorwhi
chdec
odesandex
ecut
eseac
h
i
nst
ruc
tion.

script.bc
000000000000000000
101001010101010100
100101010101010101
100101010101010010
111111111100010101
Simulator
111000000000000000
00011100100100101
100101010100000001
110000111001010101
111111111111111111

Fi
gur 1:Hi
e4- gh-
le
vel
ope
rat
ionof
thes
imu
lat
or

Al
lpr
ogramswr it
tenforthesi
mul
at
ormuste
it
herb
ewr i
tt
eni
nma c
hinecode
,orinas y
mb ol
i
cform whi
chrequi
res
t
hesymboli
cformtob ecompil
edt
oprodu
cet
heequi
val
entma
chi
necode.
Thec ont
entofthecompi
le
df i
l
elook
sli
ke
i
nscr
ipt
.bci
nt heFigu
r e4-1
.
Themi
cr
opr
oce
ssorope
rat
esi
nthema
nne
r:
 f
et
cha
nins
tr
uct
ionf
romt
heme
mor
yuni
t
 r
eadt
hei
nst
ruc
ti
on
 de
codea
nde
xec
utei
nst
ruc
ti
on

Thei
nst
ruct
ionfe
tchi
ngc
ont
inu
esu
nti
lthet
ermi
nat
ingi
nst
ruc
ti
oni
sre
ad.Thee
xec
uti
oni
sthe
nha
lt
edb
ythe
si
mul
at
or(Fi
g u
re4-
2).

6
4

  



Fi
gur 2:I
e4- nst
ruc
ti
one
xec
uti
onpr
oce
dur
e

Eac
hoft hest
epsi
sexe
cutedatacer
tai
ns peed.
Howe v
er,t
hiss
peedbyde
fau
lt,woul
dbethes
peedofthec
omput
er
i
ts
elf
,thespee
dofsi
mu l
at
ionhastobedec r
ease
d.Therat
eatwhic
htheex
ecut
ionisper
for
medisde
ter
minedb
ythe
cl
ockandtimi
ngoft
heimplement
edmicroproces
sor
.

4
.2 Ti
mingI
mpl
eme
nta
tion
Thet
imingdeter
mineswhenaninst
ruct
ionist
obeproces
sed/ex
ecut
ed.Ithasacontrolf
uncti
onovertheope
rat
ionof
t
hemicroproc
essor
.Du etothenatur
eoft hemodel
,themi c
ropr
ocess
orwa itsforas i
gnalpr
oducedb yt
hec l
ock
ge
ner
atortoproces
stheinst
ruc
ti
on.The r
efor
e,t
heimple
me nt
ati
onrequire
sb oth,themicr
oproc
essorandt
hec l
ock
ge
ner
atortoberuninthesa
mepr oc
essatt
hesameti
meormor epre
cis
ely`sequenti
al
ly`.

4
.2.
1Cl
ockRa
te
Clockg e
nerat
orissimulat
edbycla
ssClockwhichc a
nb ef
ou ndintheheaderf
iec
l las
s.
h.Thecl
ockgener
atori
nsi
de
t
hemi croproc
essorcreat
esanins
tanc
eofCl ocktypewhichg ene
rat
escl
oc k
sforexec
uti
onandthusdet
ermine
sthe
speedofsimulat
ion.Eachins
truc
ti
onisexecutedatthetr
ans i
ti
ontime(Figur
e4 -
3)when0haschangedto1( t
he
t
r a
nsit
ionisinthemi ddl
eofthecycl
e),b
u tneverwhen1c hangesto0.Thel e
ngthofti
meofonecycl
eisdefi
ned
whentheg ener
atori
sc r
eat
ed.Exa
mpleofcreat
inganewg e
nerator
:
Clock * bus = new Clock(1.0);

TheClockconst
ruc
torac
cept
sarealnu
mb erwhi
chde
fi
nest
hefrequ
encyatwhi
chthesi
mul
ati
onisi
nte
nde
dtobe
ru
n.Thespeedof1.
0(Hz)exec
ute
samicroi
nst
ruc
ti
oneve
rys
econd.Si
mil
ar
itypa
ssi
ng5.
0(Hz
)incr
eas
est
hes
pee
dof
ex
ecut
ionto0.2s
econdperi
nst
ruc
ti
on.

cycle

1
1
Clock generates
generator
0
0
time
gap half cycle
time (transition)

Fi
gur 3:Cl
e4- ockg
ene
rat
orde
scr
ipt
ionof
thes
igna
l

6
5
The“
ti
meg
ap”c
anb
eac
hie
vedb
y:
 c
rea
ti
ngaf
orl
oop
 c
all
i
ngas
lee
pfu
nct
ion
Howe
ver
,cr
eat
ingaf
orl
oop
for (int i = 0; i < 1000000; i++)

wouldgenerat
etheneededti
meg apbutthes pe
edofite
rat
ionfr
om 0to1 0
0 0
000wou l
db edi
ff
erentatvar
ious
machine
s.Ob v
ious
lyatahi
gh-en
dcomputeritwouldbeex
ecute
dmu c
hfas
tert
hanatalow-e
ndmachine.Ther
efore
,
t
hissolut
ionisnotg ener
icandrequ
ire
st hes i
mu l
at
ortob eadj
ust
edtot hemachinebytheuser( i
nvol
ving
re
compila
tionoft
hesourc
ecode).
Au ni
ver
sals
oluti
ont othi
sprobl
emc anb eachi
evedb ytaki
ngi nt
oa nac
countt
heclockr
ate(fre
quency
)ofthe
compute
rmicropr
oc e
ssor
.Theheaderf
il
eu ni
st
d.hde f
inesthefunct
ionusl
eep(
)whic
hs u
spe
ndsthee x
ecut
ionf
ora
def
ine
dtimeinter
val.Thef
uncti
onrequi
resonep a
rameterwhic
hs peci
fi
est
heti
megapinmicr
ose
c onds(1
s=10 00
000µs)
.Forexampletosus
pendexec
uti
onfor1s e
cond:
usleep(1000000)

However
,thecl
ockcons
tr
uct
orp
ara
met
err
equ
ire
sav
alu
espe
cif
ie
dinf
requ
enc
y,t
her
el
eva
ntt
imeg
api
sthe
n
ca
lcu
lat
edasf
oll
owi
ng:
time_gap = (1/frequency)*1000000

Thedivi
si
oni ssi
mplyaformulatoobta
int
hele
ngthoft
imeta
kenbyonecy
clei
nsec
ondsus
uall
ydenot
edbyTin
el
ect
roni
cs.Thev a
lueTisthenmu l
ti
pl
iedby1000000whi
chprodu
cest
heval
uei
nmicr
ose
conds.Thet
ime
_ga
pis
t
henpasse
dt otheusl
eep(
)functi
onasanar
gument.

4
.2.
2Cl
ockThr
ead
Thec l
ockgeneratorits
elfi
sruninas epa
rat
ethr
eadwithi
nthesameproces
s.Figur
e4-4e x
pla
insther
ela
ti
onb e
tween
thetwothrea
ds .
Thes i
mu la
ti
ont hre
adorthemainthr
e a
ddeter
mineswhenthesimul
ationproce
ssst
art
sandwhenit
i
st e
rminate
d. Thu s,t
erminat
ionofthema i
nthre
addes t
roy
sthegener
ator
'sthr
eadasiswascrea
tedwit
hinthesa
me
process
.Ont heot herhand,ter
mi na
ti
ngthegener
ator
'sthr
eaddoesnothaveanyaf
fec
tont hema i
nthre
adandthus
theproces
scontinu e
s.

Simulation process

simulation
started

clock thread
created

time
simulation
ended

Fi
gur 4:S
e4- i
mula
ti
onpr
oce
ssanddepi
ct
ingthec
loc
k
thr
eada
dopt
edf
rom(Blai
se,
2011)

6
6
Thepu r
poseoft
hecl
ockgenerat
ori
stoindependentl
yfr
omt hema i
nthre
adc ontinuou s
lychangeit
sstat
easshownin
theFigure4-3.
Thesta
tecaneit
herbe1or0. Eachti
methev a
lueischa
ngedthet hre
a dissuspendedforacer
tai
ntime
defi
ne dbythefr
equ
ency.Thismodeles
sent
iall
ysimula
tesacloc
kg e
nerat
or.
Thec onstantswapp i
ngofthetwoval
u e
s
i
sa chievedbyaninf
ini
teloop.Oncetheloopi sente
reditsconte
ntisexecutedov e randov erunti
lthethre
adi s
ter
mi nate
dorthepr
ocesshasfi
ni
she
d .
Thec onte
ntoftheloopsi
mplyperf
ormst hefollowingfourst
eps:
1
. Ge
tst
atu
s–a
cqu
iri
ngt
hec
urr
ent
(ol
d)s
tat
e
2
. Cha
nges
tat
us–c
hang
ingt
hes
tat
e
3
.Sa
vene
wst
atu
s-ov
erwr
it
ingt
hec
urr
ent
sta
tuewi
tht
hene
wva
lue
4
. Ge
ner
ateat
imeg
ap–t
hene
wst
atu
sre
mai
nsf
ort
hispe
ri
odof
time

Theps
eudoc
odef
ort
hel
oop:
for ( ; ; ) {
<<read-status>>;
<<change-status>>;
<<write-new-status>>
<<generate-time-gap>>;
}

4
.2.
3Thr
eadI
mpl
eme
nta
tion
POSIX Thre
a d
s( Pthr
ea ds
)we reu s
e dtoi mplementthene wt hr
eadwhichi sthestanda
rdf orthre
adsonUni x
pla
tf
orms.Pthr
e a
dsdefinesasetoftypes
, f
uncti
onsandconstantswhic
hareimplementedinphtrea
d.hheadera
ndthe
thr
eadl i
bra
ry( Ippol
ito,2 01
1 )
.The t hre
ad ma nag
eme ntc ons
ist
soff ourma i
nf unct
ions pthr
ead_cr
eat
e()
,
pth
read
_exit
(),pthr
ead_a t
tr
_ini
t()
, p
thread_at
tr_de
str
oy()
. Ini
ti
all
ythemain()progr
amc ons
istsofasi
ngleordef
aul
t
thr
ead.Al
lotherthr
eadsmu stbeexpl
icit
lycrea
tedbytheprog r
amme r(Bl
ai
se,2011).

Clock

double * frequency
bool * state
int th;
pthread_t thread;

Clock(double, void * )
void setFrequency(double )
bool getState()
int getFrequency()
static void * clock(void *)

Fi
gur 5:Cl
e4- ockc
las
sdi
agr
am

Ne
wthr
eadi
sst
ore
di het
nt hre
adv
ari
abl
eof
typep
thr
ead
.Thef
unc
ti
ont
ocr
eat
ethet
hre
adi
s
 
     

  


Thefi
rsta
r g
ume nt*t
hreadisau niqueident
ifi
erforthenewthreadret
urnedb ythefunc
tion.Thesecondat
tr
ibut
e
spe
cif
ie
sthet hr
eadatt
ributes
.IfNULLi spass
edde fa
ultv
aluesareused.Thet hir
dsparame t
erth
is-
>Clo
ck:
:cl
ock
def
ine
sthefuncti
ontoe x
ecuteonc ethethre
adisc r
eate
d.Thelastpar
ame t
erspecif
ie
sasinglearg
umenttha
tcanbe
pas
sedtothefunct
ionthatisi
nvo ked.I
tmu stbepassedbyref
erenceasapointeroftpev
y oi
d .
NULLc a
nbeusedif
the
rear
enoa rgument
stob epass
e d(Blai
se,2011)
.
Howe
ver
,thet
hre
adi
senc
aps
ula
tedi
nsi
det
heCl
ockc
las
sandt
hus
,thef
unc
ti
ont
obei
nvok
edi
s,i
tca
nnots
impl
ybe

6
7
ame mb e
rme thoda sPthreads t
andardc
anonlyinvokeag l
obalCfuncti
on.Tor et
aintheimple
me nt
ationtheonly
pos
sibl
es ol
utionisdeclari
ngt heme t
hodassta
tic
.As ta
ticme t
hoddoesnothav earefer
encetoaninstanceofthe
obj
ectitrat
heractsatthec l
asslev
el.Thi
smeansthatt
heme thodcannotac
cessanyofthevari
abl
es,nei
thermethods
def
inedinthec l
ass
.Thepr oblemc anbes
urpa
ssed,whenthepoint
erthi
sispas
sedtotheme t
hodwiththea ddr
esst
hat
poi
ntstotheinsta
nceof theobject
.
pthread_create(&thread,NULL,this->Clock::clock,(void *)this)

I
nsi
det
heme
thoda
sthea
rgu
menti
sof
typev
oid*t
hea
rgu
mentmu
stb
eca
stb
ackt
othet
ypeCl
ock
,whi
chi
sdonea
s
f
oll
ows
:
bool * state = ((Clock *)object)->state

Vari
abl
e poi
ntst
otheact
ualme
mb erst
atev
ari
abl
eoft hei
nst
anti
at
edob
ject
.Si
mila
rlyt
oobta
inf
requ
enc
ythe
addr
essof
vari
ableca
nbecalc
ula
tedmanu
allyf
romthe whi
chhasbee
nas
sig
nedtheaddr
ess
:
double * frequency = (double *)(state-16);

Theacce
sst
otheact
ualme
mbe
rva
ri
abl
esi
sens
ure
dbyt
hepoi
nte
rss
tat
eandf
requ
enc
y.Thes
tat
eint
erc
hang
eis
ar
rang
edasf
oll
owi
ng:
if (*state == 0) {
*state = (bool)1;
} else *state = (bool)0;

The*s
igne
nsu
rest
hat
wec
ompa
ret
hea
ctu
alv
alu
esnot
the
ira
ddr
ess
es.

4
.3 Re
gis
terI
mpl
eme
nta
tion
Eac
hregi
ste
rconsi
st
sofana r
rayoft
ypeFFRSt
ypeandawrit
epr
otec
ti
onbi
tl
oad.FFRScl
as
sisasi
mpl
i
fie
dmodelof
afl
i
p-f
lopusedtost
oreoneb i
t.Thel
engt
hofther
egis
teri
sdet
ermi
nedb
ythele
ng t
hoft
hisa
rra
y.As
ix-
bitr
egi
st
er
woul
dholdinit
sar
raysi
xfl
ip-f
lops
.

Register FFRS
 
FFRS * _register bit value
bit load bit load

setLoad():void setLoad():void
unsetLoad():void unsetLoad():void
loadValue(byte * ):void loadValue(byte * ):void
getValue():byte getValue():byte

Fi
gur 6:Re
e4- gis
terc
las
sdi
agr
am

FFRScont
ainsawrit
eprot
ect
ionbit
.Thi
sbi
tisus
edtoc ont
rolt
hewr i
teoper
ati
on.Be
for
eaf l
i
p-fl
opca
nbeloade
d
thewr
it
ebitb u
tmustbese
tbycalngs
l
i et
Loa
d()me t
hodotherwi
sethenewvalu
eisomit
ted.
Aftert
henewv
alu
eha s
beenl
oade
dt heun
set
Load(
)me t
hod,whi
chu
nset
sthelo
adb i
t,i
scal
l
e di
mplic
it
ly.
Asi
tcanbesee
nintheFigur
e4-6,theReg
ist
erc
las
ssi
mplyac
tsa
sac
ont
ai
nerofe
ightf
li
p-f
lops
.Thena
mesof
met
hodsa
rei
nbothc
las
sesi
dent
ic
al.Cal
li
ngt
hemethoda
sfol
l
ows
_register[3].setLoad()
_register[3].setLoad((bit)1)

i
nvokestheme t
hodst
oredintheFFRScla
ssa
ndwoul
donlyc
hang
etheb
itof
thethi
rdf
li
p-f
lop.As
sumingal
lbi
tsare
bydef
aultse
ttozer
o,t
hefinal
v a
lues
tor
edint
her
egi
st
erwoul
dbe(00
100
000)_or(3
2)`
a.Thecorr
ectwayof
cre
a t
ing
are
gis
terandloadi
ngitwit
hav al
uei
s

6
8
Register a = new Register()
byte val = (byte)100;
a.setLoad()
a.loadValue(&val)

Theme
t dl
ho o
adVa
lue
()a
cce
ptsapo
int
erof
typeb
ytewhi
chi
sade
fi
nedt
ypeof
leng
the
ight
bit
s(u
nsi
gne
dcha
r).
Howe ve
r,theregi
st
ercanonlyhol
dvalue
sinrang
e0a nd1
,theval
uepass
edtothemethodloa
dValu
e()mustbe
conver
tedtot hebinar
yformat.Theconve
rsi
onf r
om deci
maltob i
nar
yforma
ti sper
for
me dbythefunct
ion
dec_t
oBi
n()( dis
cuss
edinthene xtse
cti
on).Fol
lowingproc
edu
reisr e
quir
edtoob t
ainbina
ryformatofthe
i
nformati
on:
byte decval = *val
bit binval[] = “00000000”
dec_toBin(&decval,binval)

Theconver
si
onr equi
resbothvar
ia
blestob
ede c
lar
e dinadv
anceandhavea l
loc
a t
edspace(point
er)
.Thef i
rs
t
par
amet
eristheval
ueinthedeci
malfor
mata
ndsecondp a
rame
teri
sapoint
ertoac har
act
erarr
aywhe r
ethebina
ry
f
ormati
scopi
e d(
eightbi
ts
).Eac
hb i
toft
hebi
nar
yvalueist
henc
opie
dtocorr
espondi
ngfli
p-f
li
pinthereg
ist
er:
for (int i = 0; i < 8; i++)
_register[i].loadValue(binval[i]);

Methodu s
edtoob
tai
ntheval
uest
ore
dinthere
gis
teri
scal
ldg
e et
Value
().
Simi
la
rl
ytheb
itss
tor
edi
nthes
ing
lef
li
p-
f
lopneedstob
emerge
dintoonec
hara
cte
rst
ri
ngandconve
rte
dtode
cimalf
orma
t:
bit binval[] = “00000000”
_parseBits(binval)
byte decval
bin_toDec(binval,decval)
return decval

Mehod_p
t ars
eBi
ts
()copi
est
hev
alue
sst
ore
dint
hef
li
p-f
lopsi
ntot
hea
rryb
a i
nva
l,whi
chi
sthe
nus
eda
sapa
rame
ter
f
ort
heconv
ertf
unct
ionbi
n_t
oDec
().

4
.4 Numbe
rBa
seConv
ers
ions
Conv
ers
ionsamongdif
fe
rentnu
meri
cal
sys
temsi
sthecr
ucia
lpar
toft
hei
mpl
eme
nta
ti
on.
Ide
cide
dtoi
mpl
eme
ntmy
ownf
uncti
onstocov
erta
mongthes
ethr
eenumer
ic
alsy
ste
ms :
 De
cima
l
 He
xade
cima
l
 Bi
nar
y
However
,hi
ghpr ogr
ammi nglanguag
e sc
anhandlei
sonebyt
ethepr
og r
amme rcannotmanip
ula
tewi
thsi
nglebi
tsa
s
t
herenodat
atypethatwou l
dallowstodoso.Inmyimpl
ementa
ti
onde c
imalval
uesaredef
ine
dasade
fine
dtypebyt
e
whic
hisuns
ignedchar.Theele
me nta
rydiff
ere
ncebet
weenbyt
eandbiti
nthisca
seisthatb
iti
sass
umedbina
ryva
lue
s
0and1anyl
ength.Bytehowevercanstor
ead eci
mal
val
ueinr
ange[0
;2 55]
.
Hexa
deci
ma l
val
uesc
anhol
dor
dina
rya
lpha
betl
et
ter
s(A,
B,C,
D,E,
F)a
ndt
huss
imi
l
arl
ytob
ina
ryi
tiss
tor
eda
sst
ri
ng
of
chara
cte
rs.

De
ci
mal
toHe
xad
eci
mal
Con
ver
si
on
Thef
unc
ti
ont
oconv
ert
dec
ima
lva
luet
oahe
xade
cima
lis
void dec_toHex(byte * dec, char * hex)

Thefi
rs
tparamet
eri
sapoi
nte
rtoade
cima
lva
luea
ndt
hes
econdpa
rame
terpoi
ntst
oana
rra
ywhe
ret
hec
onv
ert
ed
dec
imalva
lueisc
opi
ed.

6
9
char * hex_value[3] = “00”

Thevar
ia
ble
smu
stb
ede
fi
nedpr
iorc
onv
ers
ionsa
sthef
unc
ti
onsonl
yde
alswi
thpoi
nte
rs.
Ana
rra
yfo
rab
ina
ryv
alu
eis
def
ine
das
bit * bin_value[9] = “00000000”

Ex
ampl
eof
conv
ers
ion:
byte decimal_val = 111
bit * binary_val = “00000000”
char * hexa_val = “00”
dec_toBin(&decimal_val, binary_val)
bin_toHex(binary_val, hexa_val)
// binary_val = “01101111”
// hexa_val = “6F”

Allpoi
nte
rsmustb
eall
ocat
edpr
iort
hec
onv
ers
iona
sthef
unc
ti
onsa
ssu
mest
hatme
mor
yha
sbe
ena
ll
oca
teda
nddo
notdea
lme mor
yal
loc
ati
on.

4
.5 Me
mor
yImpl
eme
nta
tion
Theext
ernal
me mor ydevi
ceisbas
edona3 -di
me ns
iona
lcubi
car
chit
ect
ure
.Itisi
mple
me nt
edasa3-
dimensi
onalarr
ay
t
hathol
dsb i
tinformati
on.Thedimensionsar
e25 5
x255x16
.Wherethef
ir
st2dimensi
ons(25
5 )s
pecif
ie
stheaddres
s
andl
astdimension( 1
6)thei nf
ormat
ions t
ore
d.Thu s
,themaxi
mu mamo untofbi
tst
hatcanbestoredatasing
le
memoryaddressis16bit
s.
MEM

Byte **** memory


Register * micp_mbr
Register * micp_mar

void read()
void write()

Fi
gur 7:Me
e4- mor
ycl
assdi
agr
am

Me
mor
yes
sent
ia
ll
ype
rfor
msonl
ytwoope
rat
ion:
 r
eadme
mor
y
 wr
it
eme
mor
y
Regi
st
ersas
soc
iate
dwit
hme mor
yope
rat
ionsar
eMARa ndMBR. Howe
ver
,theme
mor
yca
nnotdi
re
ctl
yac
ces
sthe
se
re
gis
ter
s,po
int
ersar
epa
sse
dtotheme
mor ydu
ringt
hei
nit
ia
li
sat
ion:
MEM memory = new MEM(mbr,mar)

Re
ado
per
ati
on
Thepr
oce
ssof
rea
dope
rat
ions

COPY COVERT
READ LOAD TEMP
MEMORY TEMP TO
MAR TO MBR
TO TEMP DECIMAL

Fi
gur 8:Re
e4- adope
rat
ionpr
oce
dur
e
70
Thea
ddr
essf
romMARr
egi
st
eri
sfi
rs
tre
adi
ntot
empor
aryv
ari
abl
eswhe
rede
cima
lva
luei
sob
tai
ned
.
byte mar0 = (byte)((Register *)MICP_MAR)->getValue();
byte mar1 = (byte)((Register *)(MICP_MAR+sizeof(Register))->getValue();

MARr
egi
st
ersi
sa1
6-b
itwi
der
egi
st
ert
hust
wode
cima
lnu
mbe
rar
ere
qui
ret
ofu
ll
ycl
as
si
fyt
hea
ddr
ess
.
Bi
nar
yre
pre
senta
ti
onist
henc
opi
edt
ote
mpor
aryr
egi
st
ersda
t0a
ndda
t1,
whe
reda
t0r
epr
ese
ntst
hel
owe
r8b
itsa
nd
da
t1t
hehi
gher8bit
s.
bit dat0[] = "00000000\0";
bit dat1[] = "00000000\0";
for (int i = 0; i < WORD; i++) {
if (i < WORD/2)
dat0[i] = *memory[mar0][mar1][i]+DEC;
else
dat1[i-8] = *memory[mar0][mar1][i]+DEC;


Theb
ina
ryv
alu
eist
henc
onv
ert
edi
ntode
cima
lfor
mat
andMBRr
egi
st
eri
sloa
ded.
((Register *)MICP_MBR)->setLoad();
((Register *)MICP_MBR)->loadValue(&val0);
((Register *)(MICP_MBR+sizeof(Register)))->setLoad();
((Register *)(MICP_MBR+sizeof(Register)))->loadValue;

Wr
it
eop
era
ti
on
Wr
it
eope
rat
ionpr
oce
ss

COVERT LOAD MBR


READ READ
MBR TO
MAR MBR
TO BINARY MEMORY

Fi
gur 9:Wr
e4- it
eope
rat
ionpr
oce
dur
e

Theaddre
ssi
sre
tri
eve
dfr
omtheMARinthesa
mewa yasi
nthere
adoper
ati
on.
Thev
alu
etob
est
ore
dint
heme
mor
y
i
sloc
atedi
ntheMBR.Theva
luei
ntheMBRisconv
ert
edint
obina
ryf
ormat.
bit binMBR0[] = "00000000\n";
bit binMBR1[] = "00000000\n"
dec_toBin(&mbr1,binMBR1)
dec_toBin(&mbr0,binMBR0)

Fi
nal
l
yal
l16b
itsa
rec
opi
edi
ntome
mor
yinas
imi
l
arwa
yasi
nther
eadope
rat
ion.
for (int i = 0; i < WORD; i++) {
if (i < BYTE)
*memory[mar0][mar1][i] = (byte)(binMBR0[i]-DEC);
else
*memory[mar0][mar1][i] = (byte)(binMBR1[i-BYTE]-DEC);


4
.6 St
ackI
mpl
eme
nta
tion
S
tac
kimpl
eme
nta
ti
onr
eus
esa
lr
eadywr
it
tenc
odef
ort
her
egi
st
erc
las
s.Thes
tac
kisof
typeFI
FO(
fi
rs
tin,
fi
rs
tou
t).
It

7
1
c
ons
is
tsof
ade
fi
nedn
umb
erof
reg
ist
ers
.Thenu
mbe
rof
reg
ist
ersi
sde
fi
neda
tthei
ni
ti
al
is
ati
ons
tag
e.

Stack

Byte **** memory


Register * micp_mbr
Register * micp_mar

void read()
void write()

Fi
gur 10:S
e4- tac
kcl
assd
iag
ram

Stack (int number)

wher
ethepar
amete
rina
nint
ege
rwhi
chde
fi
net
hel
eng
thof
thes
tac
k(nu
mbe
rof
reg
ist
ers
).Thede
fau
ltv
alu
efort
he
mic
ropr
oces
sori
s64.
Thr
eepo
int
ersa
rea
ssoc
iat
edwi
thS
tac
kcl
ass
.
Register * p

whi
chpo
int
sat
thec
urr
enta
ddr
ess
Register * top

de
ter
mine
sthet
opa
ddr
essof
thes
tac
k(a
ddr
ess6
4)
Register * bottom

de
ter
mine
stheb
ott
omof
thes
tac
k(a
ddr
ess0
).Thea
ctu
alv
alu
ess
tor
edi
ntha
tst
acka
rea
cce
ssi
bl
ethr
oug
h
Register * stack

v
ari
abl
e.
Twoele
menta
ryoper
ati
onsa
rea
ssoc
iat
edwi
ths
tac
k–p
usha
ndpop.
Pus
hme
thoda
cce
ptsa
nint
ege
rtob
epu
she
don
t
hetopoft
hest
ack
push(5)

t
heval
ue5isi
nse
rte
dontothest
ackatthec
urre
ntpos
it
ionoft
headdr
esspoi
nte
rp.The
nthes
tac
kc he
ckswhet
her
t
heupperl
i
mithasb e
enre
a c
hedb ycompar
ingthec
urre
ntaddr
esspoi
nte
randtheuppe
raddr
essst
oredintop
v
ari
abl
e.
If (p != top)
p++

I
fthecondi
ti
onistr
ue,t
hecur
rentpoint
erisi
ncr
eme
nte
d.Othe
rwis
enoinc
rement
ati
oni
sperf
orme
dandifanew
v
alueispus
hedontothest
ackitwillrepl
acet
hepr
evi
ousone.Thust
heprog
rammershou
ldens
uret
hatthe
se
l
i
mi t
ati
onsa
rechec
ked.
Popope
rat
ionpopsou
tav a
luethatthepvari
ablepointsat
. I
ftheoper
ati
onshasb
eensu
cce
ssf
ult
headdr
esspoi
nte
rp
dec
rement
ed.Agai
n,i
ftheaddresspoint
erpointsattheb ott
om addr
essitca
nnotmovef
urt
herdownandthusthe
bot
tomofthes
tac
khasbeenrea
c hed.Thi
sconditi
onisc he
ckedb y
if (p != bottom)
p--

a
nde
nsu
rest
hat
poi
nte
riswi
thi
nthes
tac
kli
mit
s.
Whenava
luei
spopp
edo
ut,t
hea
ctu
alv
alu
est
il
lre
mai
nsi
nthes
tac
kbu
titc
annotb
eac
ces
si
bl
eanymor
eby
pr
ogr
ammer
.
Ex
ampl
eof
useof
sta
ckope
rat
ions
:
Stack myStack(10) // 10 values can be stored in the stack

7
2
byte val0, val1, val2
myStack.push(10)
myStack.push(20)
myStack.push(30)
val0 = myStack.pop() // contains 30
val1 = myStack.pop() // contains 20
val2 = myStack.pop() // contains 10
val0 = myStack.pop() // contains 10

4
.7 Ar
it
hme
ticLog
icUni
tImpl
eme
nta
tion
TheALUc ons
ist
sof
twotempor
aryr
egi
st
erste
mp1a ndtemp2.Ther
esu
ltofope
rat
ionsca
ne i
the
rbes
tor
edi
ntheAL
re
gis
terors
tac
k.The
ref
ore
,thei
mple
mentat
ioninc
ludespoi
nte
rstot
hest
ackandALr e
gis
ter
.
TheALUc anpe
rfor
mfou
rar
it
hme
ti
cope
rat
ions–a
ddi
ti
on,s
ubt
rac
ti
on,mu
lti
pl
ic
ati
ona
nddi
vi
si
ona
nds
ixl
ogi
cal
ope
rat
ions–OR,AND,NOT,
NOR,NANDandEXOR.

ALU

Register * temp1
Register * temp2
Register * al
Register * stack

void addition(char )
void subtraction(char )
void multiplication(char )
void division(char )
void log_not()
void log_or(char )
void log_and(char )
void log_exor(char )
void clearCarry()
void clearZero()

Fi
gur 11:ALUc
e4- las
sdi
agr
am
Ari
thmetic ope ra
ti
ons a ddi
ti
on, mult
ipl
i
cati
on and s
ubtr
act
ion ca
n
al
terthefla
gs–compari
son,zeroandcarr
y .TheALU i
mpleme
nta
tioncont
ai
nstwor e
fer
enc
estothest
ackanda
re
gist
er.Botha
rer
equir
edastheres
ultof
allopera
ti
onsi
scopi
edt
oei
theroft
hetwo.
void ALU::addition(char s)
{
byte t1 = temp1.getValue();
byte t2 = temp2.getValue();
byte res = t1+t2;
if ((t1+t2) > 255)
carry = 1;
if (s == 's') // stack operation
(this->s)->push(res);
else // register operation
{
al->setLoad();
al->loadValue(&res);
}
}

Thec
odes
nippe
tshowst
hei
mpl
eme
nta
ti
onof
addi
ti
onf
unc
ti
on.
Op
era
ti
ono
fALU

7
3
Theintendednu mbermu s
tfir
stbeloade
dintothetempora
ryreg
ist
erstemp1andtemp2.I
fthesumof thenumbe ri
s
l
argerthan2 55theca r
rybitissettonoti
fytheu s
eraboutover
fl
ow.Thee x
amplebel
ows howshowt heALU i s
i
mpl e
me nted.Ar e
gis
terandas ta
ckpo i
nte
rmu stbepass
edtothea ti
nstant
ia
tionoft
heob j
ect
.The ntwome thod
l
oadTemp1 ( )andloadTemp2 ()areusedtoini
tia
li
setheinpu
tv a
luesfortheinte
nde
dope rat
ion.Theaddit
ion()
methodwi t
hpa ra
me t
ersdenotest
hatthere
sulti
scopie
dint
othestac
k .
Register * al = new Register
Stack * stack = new Stack(10)
ALU * alu = new ALU(al,stack)
alu->loadTemp1(5)
alu->loadTemp2(10)
alu->addition('s') // push(5+10)
byte val = stack.pop() // val = 15

ALUcanonl
yper
for
m8 -
bitar
it
hmet
iconwhol
enumb
ers
.Di
vi
si
onof
19÷5=3
.8,
pro
duc
esnu
mbe
r3a
sthenu
mbe
r
i
scr
oppedat
thef
loa
ti
ngpointa
nddoesnot
rou
nd.
Negat
iv
enumb e
rsa
renotsu
ppor
tedbutcoul
dbea s
cer
tai
nbychecki
ngt
hest
atu
softheALU f
lag
s.Fore
xampl
e,
su
btr
acti
on(50-60
)produc
esval
ues246andset
sthecar
ryb
it.I
fthi
sva
luei
ssubt
rac
tedf
rom 2
56nu mb
er10is
obt
ai
nedtog
ethe
rwi
thcar
rybi
ti
ndi
cati
ngthe“
si
gn”oft
henumber.

4
.8 Mi
cropr
oce
ssorI
mpl
eme
nta
tion
TheMI CPcl
assact
sasaconta
ine
rwhic
hholdsandli
nkse
ver
ycompone ntoft
heimplement
edmicr
opr
oce
ssor
.Ita
lso
pr
ov i
desi
nst
ruct
iondecodi
ngandex
ecuti
onfunct
ions
.Aver
yb a
sice
x a
mpl eofr
u nni
ngasi
mula
ti
oncanbeachi
eved
def
ini
ngthei
nstr
u c
ti
oninit
sbina
ryf
ormatandst
oreit
asast
ri
ng(str
inginst
ruct
ions)
.

MICP

Register * al,ah, b, c, d, e, l, h
MEM * memory
Stack * stack
Clock * bus
ALU * alu
Register ir
Register st

MICP(int )
void loadInstructions(char [][17])
void wait()
void clock_finish()
void execute()
void read_memory()
void store_memory()
void micpStatus()

Fi
gur 12:Mi
e4- cr
opr
oce
ssorc
las
sdi
agr
am

Aninst
anceofmicr
oproces
soriscr
eate
db ypass
ingare
q u
ire
df r
eque
ncytothecons
tr
u c
tor(5
0Hz )
.Thenasignalt
o
t
heclockgene
rat
ormu stb
es e
nttotri
ggeri
tsopera
ti
on.Thenthemicr
oproce
ssori
sre
adytoloa
dtheins
tr
uct
ionsint
o
memory.Theme mberme t
hodl o
adInst
ruct
ions
()acce
ptsabinarys
tr
ingcontai
ni
ngtheappr
opri
at
eb i
nar
ye ncode
d
i
nst
ruct
ions.
string instructions = “0000000000000000" + "0000000100100100" +
"0000000100100100" + "0000000100100100" +
"1111111111111111”
Micp * microprocessor = new Micp(50); // passing 50Hz to clock
microprocessor->createBus(); // creating clock
microprocessor->loadInstructions(instructions);

7
4
microprocessor->execute(); // execution of loaded instructions

Theinst
ruc
tionar
eloa
dedintome moryatt
hespee
ddefi
nedbytheu
ser(
int
heexa
mpl
e50Hz).
Whenal
li
nstr
uct
ions
havebeenloade
dthemicroproce
ssorisre
adytoexe
cutethe
m.Me mberf
unc
ti
onex
ecu
te(
)prov
ide
sallne
ces
sary
st
epstoacc
omplis
htheex
ecution.

4
.8.
1Ins
truc
tionEx
ecut
ion
Themicropr
oce
s s
orl
oadsthepr
ogr
amc ount
erreg
ist
erwi
thaval
ue0h.Prog
ramc ou
nteri
saregi
st
erwhi
chal
ways
poi
ntsa
tthenexti
nst
ruct
iontob
eexec
utedbythemicr
opr
oce
ssor
.Theval
ueisa
utomati
cal
l
yinc
rement
edaf
te
reac
h
i
nst
ruct
ionhasbeene
xecute
d.
The ntheMAR( Me moryAddr es
sRe gis
ter
)isloade dwiththevalu
ec onta
inedwithinthePCr egi
st
er.MARs toresan
addresslocati
ontob eacces
sb ytheme mory.Ca l
lingread_memor y()themicroprocess
orse ndsasignaltome mory
readwhic hensur
est hatthememor yreadst
hec ontentof MARa nda cce
sstheme morylocat
ion. Thecontents
toredat
theme mor yloca
ti
oni sc
opiedintoMBR( Me mor yBu ff
erRegi
ster
) .
Thec onte
ntisob vi
ouslya1 6-b
itinst
ruc
tion.At
thi
ss t
aget hemicr
opr ocess
orentersaloopthatloopsu nti
li
treachesthete
rminati
ngi ns
truc
tion( 1111111111
1 11111
=e nd).Thec ontentoftheMBRc ont
ainst
hei nstr
u cti
onthatisreadb ythemicroproces
sor, dec
odeda ndexecute
d.
PCr egis
teristhe
ni ncrementedby1a ndtheproce ssisre
peate
d.
Twos peci
alinst
ruc
tionsaredef
inedins
tr
uct
ionbegi
n( 0
00000
0 0
00000
000)andend(1 11
11 1
111111
1 11
1)which
def
inethescopeofthewrit
tens
cript
.Whenthemic
roproc
ess
orrea
dsani
nst
ruct
iont
hatconta
insal
l1'
stheexe
cuti
on
i
simme dia
telyter
mi na
ted.However,t
hememoryisra
ndomlyloa
dedwit
h0'sand1'
sthereisahig
hpr ob
abil
it
yof
ex
ecuti
ngar andominstr
ucti
on.
Theins
tru
cti
onsetiscompose
dof2 29inst
ruct
ions(of256possi
b l
e).There
fore
,theprobab
il
it
yofexecu
tinga
ra
ndominst
ruc
ti
onisal
most90%.Theproba
bil
it
ythatt
herandombitgenera
torgener
atesat
ermi
nat
ingi
nst
ruc
ti
onis
onl
y0.0
015%or1:6553
5.If
thecompi
lerdi
dnotrequi
rethete
rmina
tingins
truc
ti
on,randomaddr
ess
eswoul
dber e
ad
fr
omthememorywit
haprobabi
li
ty1:1
.18exec
uti
ngoneof t
heimpl
eme nte
dinst
ructi
ons.
Twoi
mpor
tant
memb
erf
unc
ti
one
nsu
rest
het
imed
ela
yine
xec
uti
on.
 wa
it
()
 c
loc
k_f
ini
sh(
)

The
set
wof
unc
ti
onse
nsu
rest
hat
eac
hmi
cr
oins
tr
uct
ioni
sex
ecu
tiona
tther
is
ingc
loc
kti
me.
void MICP::wait()
{
while (bus->getState() == 0)
usleep(CLOCK_CHECK);
}

t
hewa i
t()fu
nctionc
onta
insawhil
eloopthatloopsunt
ilt
heclocks
tat
uschangesto1.usl
eep()funct
ionaccept
sasa
p
arameternumb ert
hatspec
if
iesthedela
yt i
mei nmi c
rose
conds.Aswhi l
e()loopcausesahi ghmi c
roproc
ess
or
r
esourc
esdema ndadela
yr e
lea
sessomeoft heseres
ourc
esbynotc hec
kingeverynanosecond.Whe nthewhile
()
c
onditi
onb ec
ome st
ruet
heloopisexi
tedandi ns
tru
cti
oncanb eexe
cut
ed. S
imil
arly
,cl
ock_fini
sh()f
u nct
ionchec
ks
f
orthest
ate0.
Theinstr
u c
ti
onbina
ryf
ormati
sconve
rtedint
oanint
ege
r.The
nthemi
cr
opr
oce
ssore
nte
rsa
nif
/el
ses
tat
eme
ntwhi
ch
cont
ainstheimpl
ement
edins
tr
uct
ionsetar
chi
tec
ture
.
Ex
ampl
e

if (instruction[0] == 1)
{
__no__operation__();

7
5
} else
if (instruction[0] = 150)
{
__loadL();
} else
if (instruction[0] == 129)
{
__register__transfer__('x','a');
}

4
.8.
2Re
gis
terTr
ans
ferOpe
rat
ion
Themethod__re
gis
ter
__tr
ans
fer
__()acce
ptst
wopa
rame
ter
swhi
chf
ir
stonei
sthede
sti
nat
ionr
egi
st
era
ndt
he
se
condp
a r
amet
eri
sthesou
rcer
egi
ste
r.Thu
s
__register__transfer__('a','x')

tr
ansf
ere
sthec
ont
entconta
inedwit
hinAHr egi
st
erint
oALr e
gis
ter
.Howeve
r,8r
egi
st
ers(
AL,AH,
B,C,
D,E,
H,L)
havebe
enimpl
ement
ed5 6dif
fe
rent
trans
ferope
rat
ioncanb
epe r
for
med.I
nsi
deof
eac
hme t
hod
wait();
al->setLoad()
byte temp = ah->getValue();
al>loadValue(&temp);
clock_finish();

Bef
orethet
rans
ferope
rat
ioncanbepe
rfor
me dthecl
ockmustpr
oduc
eaposi
ti
ves
igna
l.Func
ti
onswa
i()wa
it
sfort
he
tr
ans
iti
onti
me .
Whe nt
hiscondi
ti
onbec
ome str
uetheval
uei
sloa
dedi
ntot
heAHregis
ter
.

2
.8.
3Ar
it
hme
ticOpe
rat
ion
Eachari
thmet
icf
u ncti
onha sbeeni mple
me nte
da same mbermethod.Sampl
ec odebelow s
howsmu l
ti
pli
cat
ion
opera
ti
on.Themethoda cc
e ptsonep ar
ame t
erwhichd
enotesare
gis
ter
.Inthi
scas
et hef
ir
streg
ist
erisa
lwa
ysALa nd
theres
ulti
sal
waysstore
di nt hi
sr e
gist
erthusonly7dif
fe
rentr
egis
ter
scanb eu
sed.Addit
ional
lythemul
ti
pl
icat
ion
acce
ptsadi
rec
tva
lueora nindirectmemoryv al
ue.
byte val = al->getValue();
wait()
alu->loadTemp1(val)
clock_finish()
wait()
switch (r)
{
case 'x':
alu->loadTemp2(ah->getValue())
break
. . . // code continues for all o.ther
// registers a, b, c, etc
}
clock_finish()
wait()
alu->multiplication('r')
clock_finish()

Thea
ri
thme
ti
cins
tr
uct
ioni
sma
deou
tof
thr
eemi
cr
o-ope
rat
ions
:
1
)lo
adi
ngALv
alu
eint
ote
mp1ALU
2
)lo
adi
ngXr
egi
st
erv
alu
eint
ote
mp2ALU
3
) pe
rfor
mingt
heop
era
ti
on

7
6
4
.8.
2Cont
rol
FlowI
nst
ruc
tions
JNEinstr
ucti
onisusedtoexpl
ai
nhowc ontrolfl
owinstr
ucti
onsareimpleme nt
ed.JNEinst
ruc
tionisa
nacrony
m of
j
u mpifnotequa
l.I
ni t
spure
stf
ormitcomparesthegiv
env a
luewit
hadi r
e c
tv al
ue.
Ifthi
scondi
tioni
str
uenojumpis
perf
ormedandnextinst
ruc
ti
oninrowisexec
u t
ed.Howe v
er,i
fthecondit
ionisnotful
fi
ll
edtheaddre
ssl
oca
ti
onof t
he
i
ntendedjumpisl
oadedint
oPCr e
g i
st
erande x
ecuti
onconti
nuesfr
omt heloadedaddres
s.
JNC al, %40d, jump

Theme
tho
dac
cept
sac
har
act
erwhi
chd
enot
est
hec
ompa
redr
egi
st
er
__jump__ne__(char r)

switch(r)
{
case 'a': temp1 = al->getValue(); break;
case 'x': temp1 = ah->getValue(); break;
...
}
temp2 = mbr[1].getValue();
pc0 = pc[0].getValue();
pc1 = pc[1].getValue();

Temp1loadsthecont
ent(
val
ue)s
tore
di nthecompare
dreg
ist
er.Temp2v ar
ia
b l
eisus
edtost
oret
hedir
ectval
ue
whic
hisconta
inedwit
hint
hel
ower8b i
tsinthel
oadedJNCinst
ruct
ion.
The nthete
mp2issu
btr
act
edf
rom te
mp1
andi
fther
esul
t i
snote
qual
toze
ro,
theval
uea r
enotthes
ameandjumpmu stb
epe r
for
med
if ((temp1 - temp2) != 0)

Thepcre
gis
teri
sincr
ement
ed(t
hisi
swhe
ninsr
uct
uct
iondir
ect
lychangest
hecont
entofPC)
.Thene
waddr
essi
s
l
oade
dint
oMARa ndmemor
yisr
ead.
NowtheMBFconta
inst
headdre
s sl
oca
ti
on.
pc1++; // go to next address
load_MAR(pc0,pc1); // load it
read_memory(); // reading jump address

Twoc
ondi
ti
onc
anoc
curt
hej
umpl
oca
ti
oni
sei
the
rat
thel
owe
raddr
essa
ndhi
ghe
raddr
ess
.
if (mbr[1].getValue() < pc1)
pc1 = mbr[1].getValue()-1;
else
pc1 = mbr[1].getValue();

I
ftheaddre
ssl
ocat
ionishi
ghe
riti
ssai
dtha
tjumpisper
for
medforwar
d.Thehigher8bit
sarenott
akenint
oaccou
nt
a
sc ur
renti
mpl
e ment
ati
oncompil
erdoe
snotcons
idert
heseb
its
.Thelowe
r8 -
bit
smu st
b edec
remente
db y1t
oma tch
t
her i
ghtj
umpaddres
s.Thedec
rement
ati
onisnee
dedascompil
erdi
dnotconsi
dertheaddedaddr
essi
nstr
uct
ionri
ght
a
ft
e rt
hejumpinst
ruc
ti
on.
pc0 = mbr[0].getValue();
pc1 = mbr[1].getValue()-1;

The
nthePCi
sal
te
redb
ythei
nst
ruc
ti
ona
ndt
hej
umpa
ddr
essi
slo
ade
d.
pc[0].setLoad();
pc[0].loadValue(&pc0);
pc[1].setLoad();
pc[1].loadValue(&pc1);
load_MAR(pc0,pc1);
read_memory();

I
fhowe
vert
hec
ondi
ti
on(
temp1–t
emp2
)ist
rue(
zer
oispr
odu
ced
)thej
umps
hou
ldnot
bepe
rfor
med
if ((temp1 - temp2) < 0)
alu->setCarry();
temp1 = pc[1].getValue()+1;

7
7
pc[1].setLoad();
pc[1].loadValue(&temp1);

Car
ryb
iti
ssettoindi
cat
ethechange.Whentheval
ueinPCregi
ste
risi
ncreme
nt edbyoneandloade
db a
ck.Nowthe
PCpoi
ntsattheme moryaddre
ssthatisl
ocat
edrighta
ft
erthejumpinst
ruc
tion.Theexecut
ionthencont
inu
esas
nor
mal–t
hePCi sincr
ementedandthePCpo i
ntsa
tnewins
tr
u c
ti
ona f
te
rtheaddres
sins
tr
ucti
on.

4
.9 Gr
aphi
cal
Use
rInt
erf
aceI
mpl
eme
nta
tion
Thet womostpopu
larGUIfr
ameworksonLi nuxpl
atf
orma reGTK+a ndQt. GTK+isusedasast
andar
dt ool
ki
tfor
theGNOMEa ndXfceDeskt
opEnvi
ronme ntswhil
eQti su s
e df
orKDE.Qt'sAPIisc
lea
ne ra
ndb e
tte
rdoc umente
r
theGTK+' s
.Qtha sC++b a
sedli
bra
riesanda ls
osu pport
sPe rl
,Py
thon,PHPa ndRub ybase
dde ve
lopemnt.In
compa r
is
ontoQtGTK+ha sCbase
dlibrar
iesandsupportsprogr
ammingl
anguage
ssuchasC++,Jav
a,Perl
,PHPa nd
Python(GTK+Te am,20
09).
There
asonforchoos
ingGTK+overQtist
hatIhavedeve
lopedafewsmall
appli
cat
ionsi
nGTK+. Thi
sconvi
nce
dme
t
ou s
ethisli
bra
ryinthepro
jec
tra
thertha
nlearni
ngtheQtl i
bra
ryfrom s
cra
tch.However
,thewri
tt
enappl
ica
ti
ons
wer
einC, Ide
cidedt
ou s
eC++wrapperca
ll
edgtkmm ins
teadofpureGTK+( Brag
a,200
7).

4
.9.
1GTK+Tool
kit
GTK+i stool
kitforc
reat
inggra
phic
alu
seri
nter
fac
eswi
thcr
osspl
at
formc ompati
bil
it
y(Unix
,Windows,MacOS).I
t
i
swrit
teninprogramminglang
uageCbutal
sohasbi
ndi
ngi
sothe
rpop ul
arlang
uagess
uchasC++,Pyt
honorCshar
p.
GTK+i spu b
lishedundertheGNU LGPL2 .
1whichal
l
owsde v
elopme ntofbothfr
eeandpropri
et
arysof
twa
re
wi
thoutanyli
censefe
es(GTK+Te a
m,2008
).

Theof f
ic
ialC++i nte
r f
aceforGTK tool
kitisgt
kmm.Gt kmm impleme nt
sob j
ectf
eat
uressuchasinhe
ri
ta
nce,
poly
mirphi
sm a nd othertechni
que
s.Gt kmm all
owspro g
ramme r
st o writ
ec ode u
sing C++ t
echni
ques–
encaps
ula
ti
on,de r
iv
ati
ona ndpoly
morphis
m.Inheri
ta
nceca
nb eu s
edtode ri
venewwidget
s.Gktmm a
lsosi
mpli
fi
es
thememoryma nagement.GtkmmC++c odeisal
socl
ear
erandshort
er.Forexa
mpleset
ti
ngab u
ttont
extinCwould
beachi
eved(GTKmm, 2011):

gtk_button_set_text(GTK_BUTTON(button), "sometext")

a
ndt
hea
bov
eco
dewr
it
teni
nC++:

button.set_text("sometext")

4
.9.
2Gl
ade
Gl
adeisau se
rint
erf
acedes
igne
rforGTK+t
ool
ki
tandtheGNOMEde skt
ope nvi
ronment.Theuseri
nte
rfac
es
de
sig
nedinGladear
esavedasXMLfil
esa
ndc
anbel
oadedbyappl
ic
ati
onsdynamic
all
y.Gladefi
l
escanbeusedin
nu
mb erof
progr
ammingla
nguage
s–C,C++Cs
har
p,J
ava
,Per
l,Pyt
honandot
hers(TheGladeProj
ect
,2009
).

7
8
Fi
gur 13:Gl
e4- adeu
seri
nte
rfa
ce
TheGla
deinte
rf
aceisdi
v i
dedi
nto3mainpar
ts
.Ont h
erig
hthandsi
det
her
eisamenuwit
hav
ail
abl
ewi
dge
tswhi
chc
an
bedr
agge
dintoth
ed es
igni
ngare
aloca
tedi
nthemiddl
e.Theri
ghtp
arto
fth
eint
erf
acei
ssh
owst
hewidg
ett
reeo
ntot
op
andt
hebott
omp ar
tcont
a i
nsat
tr
ibu
tesoft
hese
lec
tedwidg
et.

Figur 14:Cont
e4- entof
XMLfi
lepr
oduce
db yGl
ade
The a
bov
e
de
sig
nise
xpo
rte
dint
oanXMLf
i
lewhi
cha
ndcont
enti
ssh
owni
nthef
ig
ure4-
14.

7
9
4
.9.
3Gt
kmma
ndGl
ade
Thei
nte
rfa
ceimple
menta
tionisenca
psula
tedinthecl
assGUI
.Themos
timpor
tantat
tr
ibu
test
hatt
hecl
ascont
ai
ns
ar
etheXMLr e
fer
enc
epoi nt
erwhichpointsattheXMLf i
l
eandthemainwindow wi
dgetGtk
::Wi
ndow.The
i
mpleme
ntat
ionoft
heuse
rinter
facel
oadst
heXMLf i
l
e
try {
refXml = Gnome::Glade::Xml::create("interface/gui2.glade");
} catch (const Gnome::Glade::XmlError & ex) {
std::cerr << ex.what() << std::endl;
}

Exce
pti
onisc
aughti
faner
rorocc
ursdu
ringl
oadi
ngt
hef
il
e.Fore
xampl
eiff
il
edoe
snote
xis
t,t
hepr
ogr
amc
annot
cont
inu
eandexc
epti
oni
sca
ught.
Thi
sme t
hodol
ogyi
sver
yfl
exi
bl
easitse
para
test
hedes
ignf
romthelogi
c.TheGUIc l
as
scont
ai
nspo
int
erswhi
cha
re
ofs
uit
abl
etype
.The
sepoi
nte
rsar
ethenl
oadedwit
hanaddr
essof
theloa
dedint
erf
ace
.
Gtk::Window * main;
Gtk::ImageMenuItem * quit;
refXml->get_widget("main",main);
refXml->get_widget("quit",quit);

r
efXmli
sthei
nter
fac
ethatc
ont
ai
nsa
llt
hewi
dget
s.g
et_widge
t()met
hodse
arc
hesforthewi
dge
tna
med“
mai
n”(
the
mainwi
ndow)andas
sig
nsit
tot
hemai
npoi
nte
r.S
imil
arl
ythebutt
on“
qui
t”i
sass
igned.

4
.9.
4Si
gna
ls
Eve
ntli
ste
nerst
hatpe
rfor
ma c
ti
onst
rig
gere
dbyuse
ra r
ecal
le
dsig
nal
s.S
igna
lisas
impl
efu
nct
iont
hatc
onne
cta
pa
rti
cul
areve
ntt
oawidgeta
ndcal
l
sorper
for
msade
sir
abl
efu
ncti
on.
Ane
xampl
eof
sig
nal
is
compile->signal_activate().connect(sigc::mem_fun(*this,&GUI::on_compile));

s
igna
l_a
cti
vat
e()i
sasig
nal
thati
str
igg
ere
dwhenthe“
Compi
l
e”b
utt
oni
scl
i
cke
d.Ame
mbe
rme
thodon_c
ompi
l
e()i
s
t
heninv
okedandper
for
msthere
quir
edfunc
ti
on.
Ke
yev
ents
igna
l
editor3->signal_key_release_event().connect(sigc::mem_fun(*this,&GUI::on_release));

s
igna
l_k
ey_r
el
eas
e_e
vent
()i
sinv
oke
dea
cht
imewhe
nke
yisr
el
eas
edi
nthet
ext
edi
tor
.

4
.9.
5Inv
oki
ngCompi
le
r
Thete
xte
dit
orc
ont
ai
nst
hec
odet
oco
mpi
l
e.Th
ete
xte
dit
orc
ont
ai
nsat
extb
uff
erwh
ichi
sgr
abb
eda
ndc
onv
ert
edi
ntoa
st
ri
ng.
Glib::RefPtr<Gtk::TextBuffer> buffer = editor3->get_buffer();
Glib::ustring ust = buffer->get_text();
std::string source = ust.raw();

Thef
il
evar
iabl
econta
inst
hei
nforma
ti
onaboutthecur
rent
lyope
nfil
e.Anewtempora
ryv
ari
abl
efnameopenst
hef
il
e
andc
opi
esthecont
entoft
hes
ou r
ces
tri
ngi
ntothefi
l
e.Theconte
ntofthef
il
eisr
ewri
tt
enbyt
hetextbu
ffe
r.
const char * fname = file.c_str();
std::ofstream o;
o.open(fname,std::ios::out);
if (source[source.length()-1] != '\n')

8
0
source += '\n';
o << source;
o.close();

Thent heext
ernalprogr
amcompil
eriscal
l
ed.However
,itwasnotachi
evabl
etoobt
ai
ntheout
putoft
hecompi
le
r
neit
herthere
turnv a
luetheo
utpu
tofthecompil
at
ionpr
ocessi
soutpu
t t
edint
othet
empfi
le
.Thecommandva
ri
abl
e
conta
insthes
he l
lcomma ndt
ocompil
ethefi
lea
ndoutpu
titi
ntote
mpf il
e.
/* compilation */
std::cout << "Compiling .." << std::endl;
std::string command = "compiler/compiler "+file+" > temp";
const char * input = command.c_str();
system(input);

Thes
yst
emc
all
exe
cut
esas
hel
lcomma
nd
compiler/compiler filename.as > temp

The
nthet
empv
ari
abl
eisr
eada
ndt
hec
ont
enti
ssa
vedi
ntop
buf
fe
rva
ri
abl
e.
/* reading compilation status */
std::ifstream output("temp");
char pbuffer[128];
std::string out;
if (output.is_open())
{
while (output.getline(pbuffer,128)
{
out+=pbuffer;
out+='\n';
}
}
output.close();
system("rm temp");
ust = out;
Glib::RefPtr<Gtk::TextBuffer> output_buffer = this->output->get_buffer();
output_buffer->set_text(ust);

Theout
putf
romt hec
ompil
eri
sthenl
oade
dint
otheout
putbox
.Af
te
rtheou
tpu
tha
sbe
enpr
int
edt
hef
il
est
rea
mis
cl
ose
dandag
a i
nthesy
ste
mcall
isca
ll
edtor
emovet
hete
mpfil
e.

Fi
gur 15:Compi
e4- l
ero
utpu
tshowni
nthet
extb
oxwi
dge
t

4
.9.
6Si
mul
ati
on
Si
mulat
ionproc
esse
sisi
mplementedasanotherthre
ad.There
asonf
orc
reat
inganot
herthrea
disthatwhensi
mulat
ion
i
str
igg
erediti
sruncont
inuous
lyandtheu s
erint
e r
fac
ewouldneedt
owai
tuntilt
hesi
mu la
ti
onthreadisf
ini
she
d.This
woul
dc au
sethewindowt ofr
ozenandu sercou l
dnotint
erac
twit
hitunti
lthesi
mu l
ati
onf i
nis
hed.Moreover
,the
i
nte
rfa
cewo ul
dbecomeu na
cces
ibl
eanda nychangesmadeini
twoul
dbeshowna tt
heendof s
imulat
ion.
t = Glib::Thread::create(sigc::mem_fun(*this,&GUI::run),true);

ThetheGli
bpr
ovi
desat
hre
adgtk
+thre
adli
bra
ryb
uil
donthetopofthepthr
eadtha
thasb
eenu
sedi
nthepr
ogr
am
cor
edeve
lopme
nt.
Theru
nfunc
ti
onisr
uninasa
not
hert
hre
adtoavoi
dinte
rfac
efr
eezi
ng.
Them_poi
nte
risapoi
nte
rtot
hemi
cr
opr
oce
ssorc
orea
ndt
hef
unc
ti
onc
rea
teBu
s()c
rea
tesac
loc
k.The
nthe

8
1
i
nst
ruc
ti
ona
rel
oade
dint
ome
mor
ylo
adI
nst
ruc
ti
ons
()a
ndme
thode
xec
utee
xec
ute
sthei
nst
ruc
ti
ons
.
m_pointer->createBus();
m_pointer->loadInstructions(instructions);
m_pointer->execute(&dispatcher,editor3,&c,false);
dispatcher.emit();

a
tth
een
dbe
for
eth
eth
rea
disf
i
nis
hedas
igna
lise
mit
tedr
epr
ese
nti
ngt
hee
ndo
fsi
mul
at
ion.

4
.10 Compi
le
rImpl
eme
nta
tion
Compile
risi
mpl
emente
da sasta
ndaloneprogr
a m.Theexe
cuta
blefi
l
erequi
resanas
sembl
ysour
cefi
lewhi
chhas
ex
tens
ionas.
Thecompi
lerre
adsthi
sfil
eandma psthes
our
cecodeontoi
tsb
inarye
qui
val
ent
.Theout
puti
sabina
ry
st
ri
ngwhichi
swr
it
teni
ntoanewfi
lewiththeex
tensi
onbc.
Ea
cha
sse
mbl
ysou
rcec
odemu
stc
ont
ai
nthet
wok
eywor
dsb
egi
nande
nd.
Thi
sif
enf
orc
eda
ttheb
egi
nni
ngb
y
if (input[0].compare("begin") != 0)
{
syntaxError("'begin' keyword required",0);
return 1;
}

Theabovec
odeappli
esf
ort
hee ndkeyworda
swe l
l
.Thefir
stl
inei
npu
t[0
]mu
stc
ont
ai
nst
hek
eywor
dbe
gin.
Ifi
tdo
es
nott
hecompil
erpr
int
sthee
rroranddoesnotpr
ogres
sfu
rther
.
Thes
ynt
axi
sde
fi
nedi
nre
gul
are
xpr
ess
ions
.Thec
odes
nippe
tbe
lows
howst
hei
mpl
eme
nta
ti
onof
fewi
nst
ruc
ti
ons
.
const std::string syntax[ISA] = {
...
/* 6*/label+"xor[ \t][a][l]"+comma+"[h]"+comme,
/* 7*/label+"xor[ \t][a][l]"+comma+"[%][m]"+comme,
/* 8*/label+"xor[ \t][a][l]"+comma+"[%]([a-f0-9]+)([dh])"+comme,
/* 9*/label+"sta[ \t]+[a][x]"+comme,
/* 10*/label+"mov[ \t]+[%][m][ \t]*[,][ \t]*[a][l]"+comme,
/* 11*/label+"mov[ \t]+[%][m]"+comma+"[a][h]"+comme,
/* 12*/label+"mov[ \t]+[%][m]"+comma+"[b]"+comme,
...
};

l
abe
l i
sde
fine
dregu
larex
pre
s s
ionwhi
chde
fi
nesabra
nchnameandcommeal
lowstheus
erpla
cecomment
s.Thearr
ay
i
ndexofe
achins
tr
ucti
onisi
tsdeci
male
qui
val
entwhi
chisc
onve
rte
dintob
ina
rytoprodu
cethere
quir
edbi
narys
tr
ing.
Theneac
heachl
i
nei
sre
ada
ndk
eywor
dsa
rec
roppe
dou
tint
obr
anc
h_t
abl
ewhi
chc
ont
ai
nst
heb
ranc
hna
mea
ndt
he
l
inenu
mb er
.

for (int i = 0; i < lines; i++)


{
for (int j = 0; j < ISA; j++)
{
boost::regex rx(syntax[j],boost::regex::perl|boost::regex::icase);
eval = boost::regex_match(input[i],match,rx);
string bst = match[1];
if (bst.size() > 0)
{
bst.erase(bst.length()-1);
table[bcounter].branch = bst;
table[bcounter].address =i+bcounter;
bcounter++;
}
}
}

Ea
chl
i
nei
sru
nthr
oug
hal
l25
6ins
tr
uct
ionsi
nthes
ynt
ax[
]ar
ray
.If
ama
tchi
sfou
ndt
heb
ranc
hta
blei
supda
teda
nd

8
2
ne
winf
orma
ti
ona
bou
ttheb
ranc
har
eadde
d.
Thenthesourcecodeisre
ada g
ain.Eachl i
neiscompar
edtothesynt
axandifamachisnotfoundthetheplane
va
ri
ablekee
pstrac
kofe r
ror
sinthecode.Ifall25
6inst
ruc
ti
onshav
eb ee
ntest
edandnoma c
hfoundthenpl
a nei
sset
t
otrueandloopsi
se nde
d.Ifamatchisf
ou ndthesy
ntaxi
ndexi
srec
odedint
otheins
tr
uct
ionvar
iab
leandtheloopis
ex
it
ed.
if (eval == true)
if (i == 256)
{
plane = true;
break;
}
else {
instruction = (byte)i;
break;
}

I
fnomachha
sbe
enf
oundt
hent
her
eisas
ynt
axe
rrora
ndt
hel
i
nec
ont
entt
oge
the
rwi
tht
hel
i
nenu
mbe
rispr
int
edt
o
t
heus
er.

if (eval == false) syntaxError(input[j],j);


else if (plane == true)
{
plane = false;
continue;
}

Thei
nst
ruc
ti
ons
pli
ti
ntot
wop
art
sins
tr
uct
iona
ndope
rand.

string num = match[2];


string base = match[3];
if (base.compare("d") != 1)
{
std::istringstream in(num,istringstream::in);
in >> val;
decVal = val;
dec_toBin(&decVal,binVal);
}

I
fthedir
ectval
ueiscompose
doft wopar
ts–thenumeri
calval
ueandthebase
.Nu mstore
stheac t
ualva
luea
ndt he
b
asethetwopossibl
ebas
esde c
imala
ndhe x
adec
imal
.Ift
heb as
eisdeci
malthest
ri
ngintege
risconvert
edtoi
nteger
a
ndthenc onve
rtedi
ntoit
sbinar
yfor
ma t
.Thesameproc
essappli
edforhe
xadeci
malwithanexc
e pti
onhex_t
oBin()
c
onvers
ionfunct
ion.Al
li
nstr
u c
ti
onsunder
gothesa
meproc e
durebutsomeinst
ruc
ti
onssuchasCLRdonotu seful
l
1
6b i
ts.
I
ftheinst
ruc
ti
onisacontr
olfl
owins
truc
ti
ons uc
ha sDJ NZt hetr
ansl
at
ionismorec
omplic
ate
d.Thefi
rs
tste
pisto
ex
tra
ctthebr
anchnameint
ojmpvari
abl
e.Theinst
ruct
iona ndtheval
uehasal
rea
dybeendec
odedi
ntopre
viou
sst
ep.
Contr
olfl
owins
tru
cti
onmu s
tunde
rgoanothe
rprocedu
r etocreat
eaval
idbra
nchaddr
ess.
Djnz register, %value, jump

string jmp = match[2];


int address = 0;
for (int i = 0; i < bcounter; i++)
{
if (jmp.compare(table[i].branch) == 0)
{
address = table[i].address;
break;
}
} if (address == 0)
syntaxError("jump not found `"+jmp+"`",j);

8
3
Allbranchnameshavebe
e nrecorde
dintob r
anchta
ble(ta
b l
e[]
).Inthi
sca
sethefoundjumpiscompa
redtothe
recor
de done
sandifama
tchisfoundtheaddre
ssofi
srec
orded.I
fthej
umphasnotbe
enfound,t
her
eisane
rrori
nthe
sourcecodeandsy
ntaxe
rrorispri
ntedtotheuse
rspeci
fy
ingthejumpnameandtheli
nenumberwheret
hejumpis
l
oc at
ed.

int current = j;
byte decVal = address;
bit hbits[] = "00000000";
bit lbits[] = "00000000";
dec_toBin(&decVal,lbits);
string addr0;
string addr1;
stringstream h,l;
h << hbits;
h >> addr0;
l << lbits;
l >> addr1;
addr0+=addr1;

Thejumpaddres
sisspec
if
iedi nthev a
riabl
eaddres
s.Hb i
tsandlb
itss
tor
etheact
ualbinar
yaddre
ss.Astheitis
as
sumednoprogr
amislong
e rthan2 5
6instr
ucti
onsonl
ylower8bit
sarec
onver
tedt
obinar
y .
However
,theaddres
sis
16-
bitwi
deandtheDJNZi nstruct
ionrequi
red8-bi
tfortheoper
ati
onand8b i
tsf
ortheopera
ndthejumpa ddr
ess
mustbes
ave
da t
heverynextaddres
slocati
on.
machine_code[ind+1] = addr0;
haveJump = true;
jumps++;

j
umpsv
ari
abl
eke
epst
rac
kof
howma
nyi
nst
ruc
ti
onsweha
veb
eenpr
oce
sse
d.
Thehi
ghandlowbit
smustb
er e
int
erpr
ete
dtost
ri
ngty
pea ndj
oi
nedt
ocompos
ea1
6-b
ita
ddr
esswhi
cht
henr
ecor
ded
i
ntomachi
ne_code
[]whi
chstor
edthecompi
le
dsour
cecode.
string h8(reinterpret_cast<char const*>(binIns));
string l8(reinterpret_cast<char const*>(binVal));
string b16 = h8+l8;
if (haveJump == true)
{
machine_code[ind] = b16;
haveJump = false;
ind++;
} else
machine_code[ind] = b16;

I
nas
imi
l
arwa
yal
lot
herc
ont
rol
fl
owi
nst
ruc
ti
onsa
reha
ndl
ed.
Thelaststepist
oc r
eat
eanewb i
nar
yfi
le
.Thefir
sts
tepcheck
swhet
heranys
ynt
a xe
rrorhasbee
nfou
nd.Ifthi
s
condi
ti
oni str
uet
hecompil
erf
il
eca
nnotb
ec r
eat
ed.
Other
wiseanewf
il
ewit
hext
ens
ionbciscr
eat
edanda
llma
c hi
ne
codei
sc opie
dint
othefi
l
e.
if (sError == true)
return;
ofstream file;
file.open(fileName,ios::out);
for (int i = 0; i < lines; i++)
file << code[i];
file.close();

8
4
Cha
pte
r5

So
ftwa
reTe
sti
ng

5
.1 Fi
rs
tSi
mul
ati
on
Thesi
mu la
torhasimplemente
dbothgrap
hicala
ndt hetextint
erf
ace.Thec odewritt
enintheAsse
mb l
ylangu a
gemu s
t
bet
ransl
atedint
oab inaryf
orm(machine
/simul
a t
orcode )whichisint
e r
nall
yunde r
stoodbythesi
mu l
at
or .Appendix
Bconta
instheInstr
ucti
onsetwher
etheb i
naryencodingisdefi
ned.Although,i
tispos s
ibl
etowri
teprogramsinthe i
r
bi
naryformb yre f
eree
ingtotheinst
ruct
ionsetu si
ngt heirbi
na r
yr epres
ent
ation,itisnotane f
fi
ci
e ntsolut
ion.
However,asimpleAs s
emblycompil
erhasbeende velo
pe dasap artofthispr
ojectitisrec
omme ndedt olear
nt he
Ass
emblylanguagesynt
ax.
Theb
ina
ryc
odei
ses
sent
ia
ll
ya“
tex
tfi
l
e”wi
thas
equ
enc
eof
0'sa
nd1
's.

Figur
e5-1:Cont
entof
first
.a
sfil
e.Thescr
iptl
oadregi
st
erAHwit
hval
ue45dec,
r
egis
terBwi
thva
lue30de
c.Thenitaddsr
egis
terALandAH,ands
ubt
rac
tsthe
v
alueBfromregis
terAL.

Thesour
cefil
emu sthavet
heextens
ion*.as (Ass
emb l
ysour
ce).Thecompi
lerr
eadsthesour
cefi
l
ea ndc
rea
tes
anot
herf
il
ewi t
hthee x
tens
ion*.bc (Bi
nar
yCode ).Thisf
il
econtai
nsasequ
enceof1'sand0'
swhichobv
iou
sly
depe
ndsontheass
emblysou
rcef
il
e.Eachscr
ipt
wr i
tt
eninAss
emblyla
ngua
gemu s
tbefol
l
owt hi
sst
yl
e:

begin
<<instructions >>
end

Twokeywor
da r
eu s
edtodeter
mi net
hest
arta
ndtheendoft
hescr
ipt–beg
ina
nden
d.The
set
wok e
ywordsa
reca
se
se
nsi
ti
veandtheli
necannotcontai
nanyothe
rchar
act
erpri
ororaf
tert
hekey
wor
d.Thei
nst
ruc
ti
onsar
eplac
edin
bet
weenofb
eginandendkeyword.
Ne
xtpr
oce
dur
eist
ocompi
l
ethes
our
cec
odeu
singt
hea
sse
mbl
ycompi
l
er.
Thec
ompi
l
erwi
l
lonl
yac
cep
taf
il
ewi
tha
n

8
5
a
sexte
nsi
on.Try
ingtopa
ssaf
il
ewi
thanyot
herex
tens
ioncau
sest
hecompil
erthr
owinganer
rormes
sageab
ou tthe
i
nva
li
dfil
eext
ensi
onandthec
ompi
l
erwil
lnott
rytore
a dt
hecont
entoft
hefi
leeventho
ughitmaycont
ai
nc orr
e c
t
a
sse
mb l
ysou
rcecode
.
Thec
ompi
l
eri
sru
nwi
tht
hisc
omma
nd.
./comp first.as

Thepa
rame
terpa
sse
dtot
hec
ompi
l
eri
saf
il
etha
tcont
ai
nst
hes
our
cec
ode
.

Fi
gur 2:Compi
e5- l
ati
oncommand–fi
st
.asfi
l
econt
ainst
hea
sse
mbl
ysou
rcec
ode
t
obetr
ansl
at
edintobi
nar
yform

I
fthes
ynta
xiscor
rec
tthecompi
le
rwil
lprodu
ceamessa
geabou
tasu
cces
sfu
lcompi
la
ti
on.Thecompi
l
eral
soproduc
es
anewfi
lewit
hab cex
tens
ion(f
ir
st
.bc
).Thefi
lei
sfu
ll
yrea
dabl
ebyast
andar
dtex
tedi
torandc
anbeexa
minedb yt
he
us
er.

Fi
gur 3:Cont
e5- ent
oft
hef
ir
st
.bcf
il
e

Asitc
anbeseeni
ntheabov
efi
gur
ethef
il
eonlyc
ont
ai
nsas
equ
enc
eof0
'sa
nd1
's.
Thec
ompi
l
erma
ppe
dthewr
it
ten
as
semblys
cri
pti
ntoi
tsb
inar
yre
pre
sent
ati
on.
Thi
sbi
nar
yfi
l
eca
nbepa
sse
dtot
hes
imu
lat
orb
y

./micp-sim first.bc

Thes
imu
lat
ionpr
odu
cest
hiso
utpu
t:
state : 0
state : 1 store memory
state : 0
state : 1 store memory
state : 0
state : 1 store memory
state : 0
state : 1 store memory
state : 0
state : 1 store memory
state : 0
state : 1 MAR loaded addr
state : 0
state : 1 memory read
state : 0
state : 1 MAR loaded addr
state : 0
state : 1 memory read

8
6
state : 0
state : 1 AH loaded directly
state : 0
state : 1 MAR loaded addr
state : 0
state : 1 memory read
state : 0
state : 1 B register loaded directly
state : 0
state : 1 MAR loaded addr
state : 0
state : 1 memory read
state : 0
state : 1 ALU temp1 loaded
state : 0
state : 1 ALU: temp2 loaded
state : 0
state : 1 ALU: Addition performed
state : 0
state : 1 MAR loaded addr
state : 0
state : 1 memory read
state : 0
state : 1 ALU temp1 loaded
state : 0
state : 1 ALU: temp2 loaded
state : 0
state : 1 ALU: Subtraction performed
state : 0
state : 1 MAR loaded addr
state : 0
state : 1 memory read
----------------FINISH-------------------
*************************
AL = 15 [00001111]
AH = 45 [00101101]
B = 30 [00011110]
C = 0 [00000000]
D = 0 [00000000]
E = 0 [00000000]
L =0
H =0
*************************
Comparison: 1
Zero flag : 0
Carry flag: 0

Twof
act
sca
nbec
onc
lude
dfr
omt
hea
bov
eou
tpu
t:
1)Aninstr
u c
ti
oncoul
dbemadeoutoft
woormor
emi
croi
nst
ruc
ti
ons,
thuse
xec
u t
inga
ninst
ruc
ti
on
doesnotneces
sar
il
yta
kesonecl
ockti
me(f
orexa
mpl
eaddi
ti
onins
tr
ucti
onneeds3c l
ock
stoperf
ormt
he
addoperat
ion)
2
)Ev
erymi
cr
o-i
nst
ruc
ti
oni
sonl
yex
ecu
teda
tthet
rans
it
iont
ime(
from0t
o1)
.

Thesecondpar
toftheout
puti
sas
mal
lre
por
tshowi
ngt
hec
ont
ent
soft
her
egi
st
ersa
ndf
la
gs.
Thea
sse
mbl
ysc
ri
pts
per
for
mst he
seope
rati
ons
:
AL = 0dec AH = 0dec B = 0dec

1
)Movesva
lue4
5dci
e nt
oAHregi
st
er AL = 0dec AH = 45dec B = 0dec
2
)Movesva
lue3
0dci
e nt
oBre
gis
ter AL = 0dec AH = 45dec B = 30dec
3
)AddsALandAH AL = 45dec AH = 45dec B = 30dec

8
7
4
)Su
btr
act
sBf
romAL AL = 15dec AH = 45dec B = 30dec

5
.1.
1Da
taTr
ans
ferI
nst
ruc
tions
Datatr
ansf
eri
nst
ruc
ti
onsoccupi
e st
hegrea
tes
tp a
rtofthei
mpl e
mente
dinst
ruct
ionset
.Thereare8r e
gis
ter
samong
whi
c hdat
acanbefr
eel
ymov e
d. Thus,
thenumb e
rofinst
ruct
ionsr
equi
re
dis7×8=5 6.Addit
ional
l
y,echore
gis
ter
ca
na cc
eptadi
rec
tori
ndir
ectv
a l
ue(LandHc annotbeused
)56+8+6=7 0tra
nsferi
nst
ruct
ionsarer
equi
red.
Exampl 1 Loa
e1. dv a
lue70dint
or e
gis
terEandva
lue80dint
oregi
st
erB.The nmov
ethev
alu
einr
egi
st
erBi
nto
re
gis
terDanda
ddre
gis
terv
alu
esCa ndBtoget
her
.Whati
sthere
sul
tofca
lcu
lat
ion?
begin
mov e,%30d
mov b,%80d
mov d,b
mov al,e
add al,b
end

Reg
ist
ersar
efir
st
lyl
oade
dwithappr
opri
at
edeci
malval
ues.Thesi
mu l
at
ordoesnotal
lowar
it
hmet
icora
nylog
ic
ope
rat
ions(e
xce
ptnot
)tous
eotherr
egi
st
ert
henAL.Onesolut
ioni
stomovet
heconte
ntofEi
ntoALandc
all
ADD
i
nst
ruct
iononALandB.

Exampl 2Wr
e1. it
eapr
ogr
amt
hat
stor
esav
alu
e11
hat
ame
mor
yaddr
ess1
0FFh.
The
nre
tri
evet
hev
alu
eba
cki
nto
re
gis
terB.
begin
mov c,%11h
mov h,%10h
mov l,%ffh
mov %m,c
mov b,%m
end

Theexerci
seonl
yr equi
restost
ore8bit
s,thu
sanyregi
st
ercanbeu sedtoac
compli
shthist
ask
.Re g
ist
erCischos
ento
st
oretherequi
redv a
lue.
Re gi
st
erHandLde termi
netheaddres
slocati
ontobeacc
ess
e d.Hholdst
hehigher8bi
tsand
Lthelower8bit
s. Theme moryl
ocat
ionis10FFwhere,
10isthehigher8bit
sandFFthelower8b i
ts
.Theref
ore
,thes
e
va
luesareappr
opriate
lyloade
dintor
egis
terLandH.Movi ns
tr
uc t
ionist
hencal
le
dwhe re%md enote
same mory
t
ransf
er.Theval
u eisre
tri
evedbacki
ntoregi
ste
rBfromtheme moryinasimil
arway.

Fi
gur 4:Ex
e5- ampl
e2r
esu
lts

8
8
5
.1.
2Ar
it
hme
tica
ndLog
icOpe
rat
ions
TheALUperf
ormsthe
sear
it
hmeti
cope
rat
ions:addi
ti
on,s
ubtr
act
ion,mul
ti
pl
ic
ati
onanddiv
isi
ononwholenat
ura
l
numbe
rs(
e.g
.1,2,3..
).Di
vi
si
on16÷5wi llpro
du c
eawholenumb er3a
sthear
chi
tec
tur
edoesnotha
vefloa
ti
ng
numbe
rar
it
hmeti
cimpl
ement
ed.
Ex
ampl
e2.
1
begin
mov al,%30d ; al = 30
mul al,%5d ; al = 30 * 5 = 150
div al,%3d ; al = 150 / 3 = 50
sub al,%30d ; al = 50 – 30 = 20
add al,%5d ; al = 20 + 5 = 25
end

Thef
ir
sti
nst
ruct
ionMOVl o a
dsALregi
st
erwi
thv
alue30d.MULinst
ruct
ionmul
ti
pli
esthec
onte
ntofALb
y5 .DI
V
i
nst
ruc
ti
ondi
videst
hecontentofALby3.S
UBins
tr
ucti
onthensub
tra
ctst
hecont
entofALby30andADDadds5t
o
t
heval
ue.
Theresul
tof
allopera
ti
onsi
sst
oredi
nALandisequa
lto25.
Example2.2Ev al
uatetheexpr
essi
onx=( 35+6 0÷2 3×15+1 )bybothregi
st
erandst
ackme
thod.Bef
oret
he
ex
pres
sioniseval
uate
dit impor
tantt
ome nt
ionthatdi
vis
iona
ndmu lti
pl
icat
ionar
ee v
alu
ate
dpr
ioraddi
ti
onor
su
btra
ction.Theexpr
e s
sionist
heneval
uate
dfroml e
ftha
ndsidetother
ight
.
X=(
35+[
(60÷2
3)×1
5])+1
begin
mov b,%35d
mov c,%60d
mov d,%23d
mov e,%15d
mov ah,%1d
mov al,c ; al = 60
div al,d ; al = 2
mul al,e ; al = 30
add al,b ; al = 65
add al,ah ; al = 66
end

The
rea
rema
nypos
si
bl
esol
uti
on,
fore
xampl
edi
rec
tva
lue
sca
nbeu
sedi
nst
eadof
loa
dinge
achv
ari
abl
eint
ore
gis
ter
:
mul al,%15d
add al,%1d

Fi
gur 5:Ex
e5- ampl
e2r
esu
lts
.Not
ic
eALr
egi
st
erc
ont
ai
ns6
6

Thes
amee
xpr
ess
ions
olv
edont
hes
tac
kre
qui
resas
li
ght
lydi
ff
ere
nta
ppr
oac
h:
begin
clr al
push %60d
push %23d
div %s
push %15d

8
9
mul %s
push %1d
push %35d
add %s
add %s
pop al
end

Fi
gur 6:S
e5- tac
kappr
oachs
olv
ingt
heexpr
ess
ion.
Notic
ethea
ddr
ess0
x00i
nthe
st
acka
ndthecont
entof
ALr e
gis
ter
.

5
.1.
3Re
gis
terOv
erf
low
Cons
ide
rthi
sins
tr
uct
ion:
mov al, %300d

Howev e
r,t
heregis
terisonl
yc apa
bleofst
oringan8-bitval
uetheactu
alv a
luethatwi
llbes
tor
edaft
erexec
utingt
his
i
nstr
ucti
onwillbe4 4d.Thisisduet oove
rflow.Theb i
naryvalu
eof3 0
0i s100101
1 0
0inbinar
y,whic
hi s9bit
s.
Overf
lowoccursatt
hemos tsigni
fi
cantbi
t.Allbi
tsarecopi
edintotheregist
erfr
omthelea
stsi
gni
fi
cantt
othemos t
s
igni
fi
c a
ntbi
t.
If t
henu mberconta
insmorethan8b i
tsal
louts
tandi
ngbitsaresubs
ti
tut
ed.

Overflow Register
8 7 6 5 4 3 2 1 0 dec
0 0 0 0 0 0 0 0 0
1 0 0 1 0 1 1 0 0 300
0 0 1 0 1 1 0 0 44

Fi
gur 7:Bi
e5- ts
ubst
it
uti
on.
Bits0upt
o8repre
sentt
hereg
ist
er.
Thefi
rs
trowisa
n
e
mpt
yre
gis
ter
.Thesec
ondrowtri
est
oins
ertn
umb er3
00andthel
as
trowshows
theac
tua
lval
uest
ored.

Mat
hemat
ic
all
ythemax
imumde c
imalv
alu
ethatc
anbest
ore
dis2
55.Whenabi
gge
rnumbe
rispas
sedt
other
egi
st
er
t
heac
tua
lval
uecanbec
alc
ula
tedast
henewval
ueminu
smaxi
muma l
l
owednumb
erminu
sca
rryb
it.
new – 255 - 1 = actual_value
300 – 255 - 1 = 44

As
impl
erwa
yist
oca
lcu
lat
ethemodu
loof
256
256 mod 256 = 0
257 mod 256 = 1
1123 mod 256 = 99
45640 mod 256 = 72

I
nsi
mil
arma
nne
rsma
the
mat
ic
alope
rat
ionsa
repe
rfor
med:

9
0
mov al,%200d
mov ah,%300d
add al,ah

Ther
esu
lti
s24
4du
etoov
erf
low.

5
.1.
4Ov
erf
lowDe
tec
tion
Twoins
tr
uct
ionsha
vebee
nimpl
eme
nte
dtode
tec
tov
erf
low.
Ins
tr
uct
ionJ
NCi
sana
bbr
evi
at
ionof“
jumpi
fca
rrynot
se
t”a
ndJC“j
u mpif
car
rys
et”
.
Ari
thmeti
clogi
cuni
tha
saspeci
alf
la
gca
ll
edCARRYwhi
chi
sse
tto1whe
nanov
erf
lowoc
cur
sdu
ringa
nar
it
hme
ti
c
ope
rati
on(addi
ti
on,
subt
rac
ti
onandmul
ti
pl
ic
ati
on)
.
Ex
ampl
eof
ove
rfl
owde
tec
ti
on:
begin
clr ca
clr b
mov al,%250d;
overflow: inc al
inc b
jnc overflow
end

CLRinstr
ucti
onc l
earst
heconte
ntofr
egi
st
ersa
nda l
sotheca
rryf
lag.
Inthi
sexampl
ethec a
rryfl
agiscl
ear
edaswel
las
r
egis
terB.Clea
ri
ngt hecarr
yfl
agisi
mport
antbec
auseitmayhavebeenseti
nthepr
evioussimula
tionru
n.Val
uesi
n
t
hemi cr
oproc
essor(reg
ist
ers
,memory,
fl
ags
)remainthesa
mea f
tert
hesimul
ati
onhasfini
shedanda r
enoti
mpli
cit
ly
cl
ear
ed.

Fi
gur 8:Thel
e5- ef
tima
ges
howst
hec
ont
entof
Bre
gis
ter(
6dec)a
ndt
hei
mag
eont
her
ight
hands
idet
hec
arr
ybi
t
s
etto1

Value2 50
disloadedint
oALr e
gis
ter
.Ov er
fl
owi sdete
rminedb ythecontr
olflowinst
ructi
onJ NC.Thisme a
nswhe n
JNCi nst
ruct
ionisencou
nter
e d,t
hemicropr
oc e
ssorcheck
siftheCARRYf lagisset.
Ift
hisc ondi
ti
onistr
ue(nots e
t)it
al
ter
st hePC ( progr
amc ounter
)regis
terwitht headdres
soft heov er
fl
ow l a
bel.I
nt hisc a
seitjumpstof ourt
h
i
nstr
u cti
onINCALa ndconti
nu e
stheexecut
ion.TheBr egi
st
e ri
ssimplyusedtoc a
lcu
lat
et henu mbe
rofite
rat
ions.If
reg
ist
e rBwa snotc l
ear
edthenu mberofi t
erat
ionswo ul
dre mainfrom t
hel ate
stsimulati
ona ndcont
inuedt obe
i
ncreme nte
d.TheJ NCinst
ructi
onit
erat
es6timesa sALregi
sterre
a c
hesoverf
lowwhe nitisincr
emented6ti
me s
.

5
.1.
6Cont
rol
FlowI
nst
ruc
tions
Anothercontr
olfl
owinst
ruct
ioni
sDJNZ( abbr
evi
ati
onof“decr
ementa
ndjumpofnotzer
o”)whi
chde
cre
me nt
sthe
va
lues t
oredinthere
gis
terby1andimpl
ici
tl
ycomparesthi
snewva
luewit
hazer
o.Ifthenewval
uei
sequa
ltozero
t
hent hecondi
ti
oniseva
luat
edastr
ueandnojumpisperf
ormed.

9
1
Ex
ampl 1Wr
e6. i
tea
nasse
mblys
cri
ptt
hatpe
rfor
msanu
mbe
rof
ite
rat
ionswhi
chi
sre
cor
dedi
nar
egi
st
er.
Thes
cri
pt
must
useaDJ
NZi
nst
ruc
ti
on.
begin
clr b;
mov c,%5d
jump: inc b;
djnz c,jump
end;

Ther
egi
ste
rBiscl
ear
edt
oensu
rethatthec
orrec
tnumberofi
te
rat
ionsi
sre
cor
ded.
Ther
egi
st
erCi
sus
edt
ost
oret
he
va
ri
abl
ethatwi
l
lbeus
edt
ocontr
olthenumberofi
te
rat
ions
.

Fi
gur 9:Bc
e5- orr
ect
lys
tor
es5it
era
ti
onsast
her
egi
st
erCwa
slo
ade
dwi
th
de
cimal
val
ue5

Asimi
lari
nst
ruc
ti
ontoDJNZi
sCJNEandCJEwhic
hexpandstheDJ
NZi ns
tr
uct
ionbyi
ncl
udi
ngaus
erde
fi
ned
s
toppi
ngcr
it
eri
a(va
lue
).CJ
NEi
sab
bre
via
ti
onof
“ju
mpifv
alu
e sa
renote
qua
l”andCJE“j
umpif
equa
l”

Example6.2Loadre
gis
terBwithanyval
ueandcl
earALreg
ist
er.
Writ
eaCJNEloopt
hatwi
ll
per
form5i
te
rat
ionson
theBvalu
e.Recor
dthenu mberofthet
otali
te
rat
ionsandi
neachit
era
ti
onsu
mt hev
aluei
nreg
ist
erBa
ndAL.For
exampl
eBisloa
dedwit
h4 0the
n:40+3 9+3 8+37+3 6=185.
begin
clr al
clr ah
mov b,%40d
jump: dec b
add al,b
inc ah
cjne b,%35d,jump
end

Thestoppingcr
ite
riaisadir
ectval
uedef
ine
db ytheuser
.Inthisca
seiti
s3 5d.CJ
NEc ompar
est
heval
uestor
edin
reg
ist
erBt o35dandi ft
heyarenoteq
ualaj
umpi sper
for
me d.Theloopmu s
tincl
udea
na r
it
hmet
ici
nst
ruc
ti
ont ha
t
ensur
estherequ
ire
dc ondi
ti
onwi l
lber
eac
hedasit
ma yendupina ni
nfi
nit
eloop.

Fig
ur 10:ALr
e5- eg
ist
erst
orest
hes
umofBval
uetha
tispe
rformed
i
neachit
era
ti
on.AHregi
st
erisus
edt
ost
oret
henumberofi
tera
tions
.

9
2
5
.1.
7Eng
agi
ngMe
mor
y
Ext
ernal
memorycanb eus
edtostorela
rgedat
aset
sofdat
a.Inass
emblys
cri
ptst
heme moryi
sdenot
edbyas ymbol
ic
char
act
er%M or%m. Theaddres
sisspeci
fi
edinregi
st
erLandH. All
reg
ist
erAL,AH, B,C,
D, EandFc a
nr et
ri
eve
dat
afrom t
heme moryanda l
sov a
luesst
oredinthes
eregi
ste
rc a
nb et
ransf
err
edintomemory.Si
nce,ame mory
l
ocati
onis1
6-b
itwideonl
ylower8b i
tsar
eusedwhenan8-bi
treg
ist
eri
suse
dinme morytr
ans
fer
.Anexampleofanan
8-b
itmemoryt
rans
ferwass
howninDa t
aTransf
erI
nstr
uct
ionpar
t.

Exa
mpl 1 Loa
e7. dr
egi
st
erCwi t
hval
ue5
0ha
nds
avei
tsc
ont
enta
ttheme
mor
yloc
ati
on1
000
h.Re
tri
evet
hev
alu
e
ba
ckfr
omthememor
ytore
gis
terD.
begin
mov c,%50h
mov h,%10h
mov l,%00h
mov %m,c
mov d,%m
end

Int
hisca
sethecont
entof
theme
moryaddre
ss100
0his0d50hwhic
hisc
orr
ect.
Sinc
e,thememoryi
slo
adedbydef
aul
t
wit
hrandom va
lues
.Whe namemor
yt r
ansf
erocc
urswit
hordina
ryre
gis
ter
sonlylower8bit
sarere
writ
tena
tthe
memoryloc
ati
on.

Fi
gur 11:Thehi
e5- ghe
r8b
itsc
ont
ai
nv a
lue0Dha
ndt
hel
owe
r8b
itst
het
rans
fer
red
v
alue50
h

Exa
mpl 2Upg
e7. ra
dethepr
evi
ouse
xampl
eus
inga1
6-b
itme
mor
ytr
ans
fer
.Sa
vehe
xade
cima
lcha
rac
terA,
B,C,
D,E,
F,
0,0i
norderf
romaddre
ss10
00h.
begin
mov ah,%ABh
mov al,%CDh
mov l,%00h
mov h,%10h
sta ax
mov ah,%EFh
mov al,%00h
inc l
sta ax
end

Aspec
ial
ins
tr
uct
ionSTAmus
tbeuse
dwhena16
- b
itmemoryt
rans
feri
sre
q ui
red.STAacc
ess
estheval
uess
tor
edi
n
ALandAHregi
st
ers.
Wher
eALisc
opi
edi
ntol
ower8bit
sandAHint
ohigher8bitsoft
hememoryloc
ati
on.

9
3
Fi
gur 12:Thea
e5- ddr
essl
oca
ti
on0x100
0st
ore
sABCDa
ndt
hea
ddr
ess0
x00
01
s
tor
esEF0
0

Exe
rci
se1Writ
eapr
ogr
amt
hatwi
l
lpr
inty
ourna
mef
romme
mor
yloc
ati
on1
000
hasNAME_S
URNAME(
whe
re_
whi
tes
pac
e).
Exer
cie2 Wr
s i
teaprogr
amthatwi
llpri
nttheAl
phabe
t( l
et
terA-Z)i
ntome
mor
yfr
om l
oca
ti
onf
rom 1
000
h.A
sa
mplesol
uti
onf
orthe
s ee
xer
ci
sesc
anb ef
oundinAppe
ndixB.

5
.2 Si
mul
ati
onAna
lys
is
S
imul
ati
onAnal
ysi
sismai
nl
yc once
rne
dwit
hthes
imul
at
ionproc
ess
ess
ucha
ssi
mul
at
iono
utpu
t,c
orr
ect
nes
soft
his
o
utpu
t.Asmal
las
sembl
yscr
iptwil
lbeu
sedt
ote
stt
hes
imula
tor
.
As
semb
lys
cri
ptwhi
cha
ddst
onu
mbe
rs.
ana_script01.as

begin
mov al,%2d
mov ah,%10d
add al,ah
end

Thefir
sti
nst
ruct
ionmovesval
ue2deci
ntoreg
ist
erAL.
Thesecondi
nstr
u c
ti
onl oa
dregi
st
erAHwi thaval
ue10dec.The
i
nstru
cti
onADD pe rf
ormsanadditi
onofALa ndAH a
ndtheres
ultisstore
dinALr egi
st
er(thecont
entofALi s
re
wr i
tt
enbytheres
ulta
ndisnomor eacce
ssi
ble
) .
Onl
yregi
st
erALiscapableofs
tor
ingt
heresu
ltofanyar
it
hme t
icor
l
ogicoper
ati
on.

5
.2.
1Spe
edAna
lys
is
Thesc
ri
ptconsi
st
sof 5i
nst
ruct
ions-beg
in,
mov,mov,
add,
end.Assu
mingt
hatthemic
ropr
oces
sorcl
ockr
atei
sse
tto
1Hz,
thusonemicr
oinst
ruc
ti
onisexec
utedpe
rse
condt
heta
sksper
for
medbythemicr
oproc
ess
orare
:

1
) Al
li
nst
ruc
ti
ona
rel
oade
dint
ome
mor
y (
5se
c)
2
) MAR(
Memor
yAddr
essRe
gis
ter
)isl
oade
dwi
tht
hea
ddr
essof
thef
ir
sti
nst
ruc
ti
on (
1se
c)
3
) MBR(
Memor
yBu
ffe
rRe
gis
ter
)isl
oade
dandi
nst
ruc
ti
onde
code
d begin (
1se
c)
4
) MARi
ncr
eme
nte
d (
1se
c)
5
) MBRl
oade
dandi
nst
ruc
ti
ond
ecode
d (
1se
c)
6
) MOVi
nst
ruc
ti
one
xec
ute
d mov al,%2d (
1se
c)
7
) MARi
ncr
eme
nte
d (
1se
c)

9
4
8
) MBRl
oade
dandi
nst
ruc
ti
ond
ecode
d (
1se
c)
9
) MOVi
nst
ruc
ti
one
xec
ute
d mov ah,%10d (
1se
c)
1
0)MARi
ncr
eme
nte
d (
1se
c)
1
1)MBRl
oade
dandi
nst
ruc
ti
ond
ecode
d (
1se
c)
1
2)TEMP1r
egi
st
erl
oade
d(ALU) (
1se
c)
1
3)TEMP2r
egi
st
erl
oade
d(ALU) (
1se
c)
1
4)Addi
ti
onpe
rfor
meda
ndr
esu
ltc
opi
edi
ntoAL(
ALU) add al,ah (
1se
c)
1
5)MARi
ncr
eme
nte
d (
1se
c)
1
6)MBRl
oade
dandi
nst
ruc
ti
ond
ecode
d end (
1se
c)

Tot
alt
heor
eti
cal
dur
ati
onof
simu
lat
ion: 2
0se
c

Thest
epsab
ovear
ere
qu i
redt
osucc
ess
ful
lys
imu
lat
ethes
cri
pt.
Thet
heor
eti
cal
ti
mer
equ
ire
dtos
imu
lat
ethes
cri
pti
s
20se
conds(a
sea
chst
atei
sh e
ldf
or0.
5sec
).
Ther
eal
ti
mewasme
asur
edbythetimecommandwhi
chisapr
ogra
mt hatme
asu
rest
imi
ngs
tat
is
ti
csa
bou
tthe
pr
ogr
amgiv
ena
sanar
gument
.Table5-
1cont
ai
nsther
esu
ltsof
fi
veruns.

Simulation Time (sec)


Run 1 20.240
Run 2 19.252
Run 3 19.803
Run 4 20.553

Ta
ble5-1:Ti
mingsta
ti
sti
csif
s
imul
ate
ds c
ri
pt(us
ingreg
ist
ers
)

Runni
ngthes
imu
lat
ioni
nre
adt
imeh
aspr
ove
dtha
tthet
heor
eti
cal
cal
cul
at
iona
rec
orr
ecta
ndt
hes
imu
lat
ionb
eha
ves
asex
pect
ed.
Thes
ames
cri
ptc
anb
ewr
it
tenb
yus
ingt
hes
tac
kme
mor
y
ana_script02.as

begin
push %2d
push %10d
add %s
pop al
end

Thefi
rs
ttwoinst
ruct
ionsl
oadtheva
lue
sont
othes
tac
k.Howeve
r,t
heALUiscapa
bleofar
it
hmet
icope
rat
ionsdir
ect
ly
onthest
ackiti
spossi
blet
osimplypus
hanADDope r
ati
onont
othest
ack(a
dd%s ).There
sul
tca
nthenb epoppe
d
outt
oALr eg
ist
er.
Mi
cr
oins
tr
uct
iona
nal
ysi
s
1
) Al
li
nst
ruc
ti
ona
rel
oade
dint
ome
mor
y (
6se
c)
2
) MARl
oade
dwi
tht
hea
ddr
essof
thef
ir
sti
nst
ruc
ti
on (
1se
c)

9
5
3
) MBRl
oade
dandi
nst
ruc
ti
ond
ecode
d begin (
1se
c)
4
) MARi
ncr
eme
nte
d (
1se
c)
5
) MBRl
oade
dandi
nst
ruc
ti
ond
ecode
d (
1se
c)
6
) Va
luepu
she
dont
othes
tac
k push %2d (
1se
c)
7
) MARi
ncr
eme
nte
d (
1se
c)
8
) MBRl
oade
dandi
nst
ruc
ti
ond
ecode
d (
1se
c)
9
) Va
luepu
she
dont
othes
tac
k push %10d (
1se
c)
1
0)MARi
ncr
eme
nte
d (
1se
c)
1
1)MBRl
oade
dandi
nst
ruc
ti
ond
ecode
d (
1se
c)
1
2)TEMP1l
oade
d(ALU) (
1se
c)
1
3)TEMP2l
oade
d(ALU) (
1se
c)
1
4)Addi
ti
onope
rat
ionpe
rfor
meda
ndr
esu
ltpu
shont
othes
tac
k (
1se
c)
1
5)MARi
ncr
eme
nte
d (
1se
c)
1
6)MBRl
oade
dandi
nst
ruc
ti
ond
ecode
d (
1se
c)
1
7)Va
luepoppe
dfr
omt
hes
tac
k pop al (
1se
c)
1
8)MARi
ncr
eme
nte
d (
1se
c)
1
9)MBRl
oade
dandi
nst
ruc
ti
ond
ecode
d end (
1se
c)

Thet
heor
eti
cal
dur
ati
ont
ime
: 2
4se
c

Themicroinst
ruct
ionsaboveshowtha tt hesimulat
ions houl
dpe rsi
stfortheore
tic
al2 4sec
onds.I
nc ompa r
is
ont othe
prev
iou
se xamplethesi
mu l
ati
onlast
e df orabout2 0seconds.Howe ver,thi
se x
ampleha ssi
xins
tru
ctions2secondsare
addedtothesimulati
ontime( 1secondt oloadthea dditi
onalinst
ructi
ona nd1s econdtoe x
ecut
et heinst
ruct
ion–
popins
tructi
on).Anothe
r2s econdsarer e
qu i
redtoincreme nttheMARr egis
terandloadtheappropri
at
einstruct
ion
(popal
).This,a
ddingonepopi nst
ructiona ctua
llyadds4s econdstothes i
mu l
ati
ontime .

Simulation Time (sec)


Run 1 24.261
Run 2 23.238
Run 3 24.242
Run 4 24.238

Tabl
e5-2:Ti
mi ngs
tati
st
ic
sof
si
mulat
edscr
ipt(us
ingst
ack)

Runni
ngthesi
mulat
ioni
nre
adt
imeh
aspr
ove
dag
aint
hat
thet
heor
eti
cal
cal
cul
at
iona
rec
orr
ect
andt
hes
imu
lat
ion
be
havesa
sexpect
ed.

5
.2.
2Cl
ockRa
teAna
lys
is
Mi
cr
opr
oce
ssorc
loc
kra
tec
anb
edy
nami
cal
l
yal
te
redt
ose
espe
edu
pors
lowdownt
hedu
rat
ionofs
imu
lat
ion.
Ift
he

9
6
cl
ockr
atei
sse
t1Hzonemi c
roi
nst
ruct
ionwil
lbeper
for
medpersec
ond.Ta
ble5
-3c
ont
ai
nst
hes
ampl
esc
ri
ptst
hat
wer
eusedt
omeas
uret
hiss
imul
at
ionti
mea t
dif
fer
ent
cloc
kra
tes(
fre
quenc
y).

S1 S2 S3
begin begin begin
nop nop nop
nop nop nop
nop nop nop
end nop nop
nop nop
nop nop
end nop
nop
nop
end
3 instructions 6 instructions 9 instructions

Ta
bl 3:S
e5- 1,S2andS3a
reas
semblys
cri
ptsa
ndonl
y
cont
ainNOPins
tr
uct
ions
.

NOP( nooperati
on)inst
ruct
ionwe r
eu se
dforte
sti
ngpur
poses
.Thisins
tr
uctiondoesnotper
for
ma nyoperat
ion
duri
ngthecl
ocktime.Dif
fer
entfr
equencie
shav
ebeenchos
entoandsi
mu l
ati
ont i
mehasbeenr
ecor
dedforeac
hra t
e
andeac
hs c
ri
pt.Logi
cal
ly
,theS1scr
iptshoul
dbesi
mulat
edi
ntheshor
tes
tti
mec ompare
dtotheot
hertwosampl
es.
Theor
eti
cal
lyincr
eas
ingthef
reque
ncyb
y1He r
tzs
hou
ldr
edu
cet
hes
imu
lat
iont
imeb
yoneha
lf
.Thef
ormu
lat
o
ca
lcul
at
ethetheor
eti
cal
simul
at
ionti
mei
sasf
ol
lows:

ttheoretical = i / f [sec]

where ttheoretical – length of simulation in seconds


I – number of microinstructions
f – clock rate (frequency) of the simulator

Er
rori
sca
lcu
lat
eda
sme
asu
reds
ampl
emi
nust
het
heor
eti
cal
/ex
pec
tedv
alu
e.

E = ttheoretical – treal [sec]

where treal – measured value


E – error in seconds

Er
rori
nex
pre
sse
dinpe
rce
nta
gei
sca
lcu
lat
edu
singt
hisf
ormu
la:
Ep = [1 – (treal / ttheoretical)] * 100 [%]

where Ep – error in percentage

Sa
mpl
e1
Sa
mplescr
iptnumber1contai
ns3inst
ructi
ons,t
hustheex
pecte
ddu r
ati
onofsi
mu l
at
ioni
s18seconds
.5cycl
esa
re
r
equi
redtoloa
dtheinst
ruc
tionsi
ntome mory,10cyc
lest
oreadanddecodethe
ma nd3cycl
estoexec
utet
hethr
ee
NOPinstr
ucti
ons(i
nstr
uct
ionsBEGI Na ndEND a r
enote x
ecute
d).Intot
altheSampl
erequ
ires19cyc
les
.The
s
imul
ati
ontimeatf
requ
ency1Hzt henshoul
db ear
ound18sec
onds.

9
7
Theme
asu
redv
alu
ebys
imu
lat
ings
cri
ptS
ampl
e1a
res
howni
nTa
ble5
-4.

f [Hz] treal [sec] ttheoretical [sec] E [ms] Ep [%]


1 18.276 18.000 276 +1.51
2 9.228 9.000 228 +2.47
3 6.227 6 227 +3.65
4 4.575 4.500 75 +1.64
5 3.992 3.600 392 +9.82
6 3.239 3.000 239 +7.38
7 2.827 2.571 256 +9.04
8 2.546 2.250 296 +11.63
9 2.236 2.000 236 +10.55
10 2.045 1.800 245 +11.98
11 1.876 1.636 240 +12.77
12 1.731 1.500 231 +13.34
13 1.613 1.385 228 +14.16
14 1.514 1.286 228 +15.08
15 1.439 1.200 239 +16.61
16 1.365 1.125 240 +17.58
17 1.309 1.059 250 +19.11
18 1.262 1.000 262 +20.76
19 1.202 0.947 255 +21.18
20 1.142 0.900 242 +21.19
25 0.941 0.720 221 +23.49
30 0.863 0.600 263 +30.48
35 0.761 0.514 247 +32.42
40 0.681 0.45 231 +33.92
50 0.604 0.360 244 +40.40
60 0.534 0.300 234 +43.82
75 0.488 0.240 248 +50.82
100 0.429 0.180 249 +58.04

Average Error 244 19.82

Ta
bl 4:S
e5- ampl
e1me
asu
redv
alu
es

Theerr
orEise
xpr
ess
edinmill
i
sec
onds(
1se
c=1
000mi
l
li
sec
onds
).Thel
astc
olu
mnEpr
epr
ese
ntst
hee
rrorr
atei
n
per
cent
agef
ort
hegi
venf
requ
ency.
Theg
rap
hbe
lows
howst
heme
asu
reda
ndt
hee
xpe
cte
dva
lue
swi
thr
ega
rdst
othef
req
uenc
y.

9
8
Real and Theoretical Duration
Sample 1
35
30
25
time [sec]

20
15
10
5
0
1 2 3 4 5 6 7 8 9 10111213141516171819 202530 354050 6075100
frequency [Hz]

real theoretical

Fi
gur 13:Theg
e5- rap
hshowst
her
el
at
ionb
etwe
ent
hef
requ
enc
yanddu
rat
ionof
simu
lat
ionof
Sampl
e1

Thegraphintheabovefi
gur ec
orrectl
yshowsthatt
herealval
uesar
esli
ght
lydel
a y
edc omparedtotheex
pecte
dv a
lues
.
Thisdif
fe
renceishoweverinsi
gnif
icantandisha
rdl
ynot i
ceabl
einthegra
pha b
ov e.
Thede la
yc anhoweve
rb ecl
ear
ly
se
eninFigure5-14.Thesimu l
at
ionwa saver
agel
yde l
aye
db y244mswhichisaverygoodresult
.Thehig
hesterr
orwas
re
achedat5Hz( 392ms)a ndthelowe s
t75msa t4Hz( Fi
gure5-
1 4
).Excl
udingthesetwoinaccur
aci
estheaver
age
er
rorisre
ducesby1 7msto2 27ms. Thedela
ya t
allot
herfre
quenci
eswasmoreorlesssimil
ar
.

Time Deviation Error


Sample 1
450
400
350
300
delay[sec]

250
200
150
100
50
0
1 2 3 4 5 6 7 8 9 101112131415161718192025303540506075100
frequency [Hz]

Fi
gur 14:Theg
e5- rap
hshowst
her
eac
hedd
ela
ysa
tal
lf
requ
enc
iesb
ySa
mpl
e1

Sa
mpl
e2
Sc
riptSampl
enu mber2c onta
ins6NOPi nst
ructi
ons.8cyc
lesar
er equ
ire
dt olo
adallt
heins
tru
ctionsint
othe
memory.16c
ycle
storea
df romfromthememor
ya nddecodea
nd6c ycl
estoexe
cut
etheNOPinst
ruc
tions.Thet
ota
l
numberofmi
croi
nst
ruct
ionsist
he ne
qual
to30.
Simu l
at
ionatc
lockr
ate1Hzthenshoul
dbear
ound30s ec
onds.

9
9
f [Hz] treal [sec] ttheoretical [sec] E [ms] Ep [%]
1 29.796 30.000 -204 -0.68
2 15.038 15.000 38 +0.25
3 9.920 10.000 -80 -0.81
4 7.533 7.500 33 +0.44
5 6.258 6.000 258 +4.12
6 5.091 5.000 91 +1.79
7 4.404 4.286 118 +2.69
8 3.891 3.750 141 +3.62
9 3.494 3.333 161 +4.60
10 3.151 3.000 151 +4.79
11 2.893 2.727 166 +5.73
12 2.680 2.500 180 +6.72
13 2.503 2.308 195 +7.80
14 2.326 2.143 183 +7.87
15 2.208 2.000 208 +9.42
16 2.143 1.875 268 +12.51
17 1.976 1.765 211 +10.69
18 1.887 1.667 220 +11.68
19 1.849 1.579 270 +14.61
20 1.840 1.500 340 +18.48
25 1.405 1.200 205 +14.59
30 1.250 1.000 250 +20.00
35 1.087 0.857 230 +21.15
40 0.984 0.750 234 +23.78
50 0.861 0.600 261 +30.31
60 0.753 0.500 253 +33.60
75 0.665 0.400 265 +39.85
100 0.575 0.300 275 +47.83

Average Error 213 12.87

Ta
bl 5:S
e5- ampl
e2me
asu
redv
alu
es

S
amplenu mber2contra
rytotheprevi
oussampleperfor
me dsli
ght
lybe
tte
r.Thegr
aphinFigur
e5 -
15showsthatt
he
r
ealval
uesaremuchclose
rtot heex
pecte
dv al
ues.
Thea ve
rageerr
orwas176mswhichisasi
gnif
ica
ntimprove
me nt
(
71ms )incompari
sontoS ample2.Thisispart
ia
llyc a
usedb yer
ror
satthecl
ockrat
es1Hza nd3Hzwhe r
ethe
s
imulat
ionfi
nis
hedwit
ha2 04msde la
yandinthese c
ondc as
e8 0msear
li
er.
Excl
udi
ngtheset
woc as
esthede
layrai
ses
t
o2 1
3mswhi chisc
ompa re
dt oSample1asig
nif
icant+13%i mprov
ement.

1
00
Sample 2 Real and Theoretical Duration
Sample 2




time [sec]




        
         
 
 


 

frequency [sec]

real theoretical

Fi
gur 15:Theg
e5- rap
hshowst
her
el
at
ionb
etwe
ent
hef
requ
enc
yanddu
rat
ionof
simu
lat
ionof
Sampl
e2

Agai
nt hei nacc
urac
iescanbeha r
dlyidenti
fi
edf ro
m Fi gur
e5 -
15.Figure5 -
16depict
st hede l
aymi l
li
sec
onds.
Comparedt othepre
viouss
ampl
ethede l
ayisveryunstabl
eandhasar ai
si
ngt endenc
y.Anotherinac
c u
racyocc
urre
d
atf
req
ue ncies1Hzand3Hzwhe rethesi
mu l
ati
onwa sfini
shedbe
foretheexpectedti
me.Thef i
gu r
ea l
sorev
eal
sthat
t
wov al
ue sareve
rysmall
(5Hzand4Hz ).The s
ev a
lueshavea16%effe
ctont heovera
llp
erf
orma nce.Excl
udi
ngthes
e
t
wov al
ue sproduc
esa+13%improve
me nti
nc omparis
o ntoSampl
e2.

Time Deviation Error


Sample 2
400

350

300
delay [sec]

250

200

150

100

50

0
1 2 3 4 5 6 7 8 9 101112131415161718192025303540506075100
frequency [Hz]

Fi
gur 16:Theg
e5- rap
hshowst
her
eac
hedd
ela
ysa
tal
lf
requ
enc
iesf
romb
ySa
mpl
e2

Sa
mpl
e3
S
cri
ptS
ampl
e3c
ont
ai
ns1
2NOPi
nst
ruc
ti
ons
.14c
ycl
esa
rer
equ
ire
dtol
oadt
hei
nst
ruc
ti
onsi
ntot
heme
mor
y.2
8

1
01
i
nst
ruct
ionstor
eadt
hembac
kfrom t
hememor
yanddecode
.12cy
cle
sre
qui
reex
ecu
tiontheNOPi nst
ruc
tions.I
n
t
otal54cycl
ess
houl
dber
equi
re
d.Simul
at
orwi
ththef
reque
ncys
etto1Hzsho
uldexec
utethewholescr
iptin54
s
econds.

f [Hz] treal [sec] ttheoretical [sec] E [ms] Ep [%]


1 53.77 54.000 -235 -0.44
2 26.662 26.000 662 +2.48
3 17.845 17.333 512 +2.87
4 13.521 13.000 521 +3.85
5 11.067 10.400 667 +6.03
6 9.105 8.667 438 +4.81
7 7.842 7.429 413 +5.27
8 6.910 6.500 410 +5.93
9 6.163 5.778 385 +6.25
10 5.553 5.200 353 +6.36
11 5.092 4.727 365 +7.16
12 4.700 4.333 367 +7.80
13 4.341 4.000 341 +7.86
14 4.054 3.714 340 +8.38
15 3.794 3.467 327 +8.63
16 3.583 3.250 333 +9.29
17 3.403 3.059 344 +10.11
18 3.335 2.889 446 +13.38
19 3.080 2.737 343 +11.14
20 3.053 2.600 453 +14.84
25 2.389 2.080 309 +12.93
30 2.065 1.733 332 +16.06
35 1.823 1.486 337 +18.50
40 1.607 1.300 307 +19.10
50 1.350 1.040 310 +22.96
60 1.174 0.867 307 +26.18
75 0.986 0.693 293 +29.68
100 0.825 0.520 305 +36.97

Average Error 384 11.6

Ta
bl 6:S
e5- ampl
e3me
asu
redv
alu
es
Themeasu
redv al
uesofSa
mple3areplot
tedinFi
gure5-17.Agai
nasinS a
mple2t hee
rrorc
annotbea
ccu
r a
tel
y
i
dent
if
ie
da sbothli
nesar
ealmos
tequal
.Theb l
uel
ineiscorr
ect
lysl
ig
htl
yde l
aye
dc ompa
redtothere
dli
nethi
sis
ca
use
db yt
hesimulat
orde
lay
.Anota
bledif
fe
renc
eca
nb eident
if
ie
datfr
equenci
es4and5Hz.

1
02
Real and Theoretical Duration
Sample 3
60

50

40
time [sec]

30

20

10

0
1 2 3 4 5 6 7 8 9 101112131415161718192025303540506075100
frequency [Hz]

real theoretical

Fi
gur 17:Theg
e5- rap
hshowst
her
el
at
ionb
etwe
ent
hef
requ
enc
yanddu
rat
ionof
simu
lat
ionof
Sampl
e3

S
amplenumber3ha dve
ryunsta
blevalue
satthel
owf r
equ
encies(
1,2,3,4and5Hz )
.The s
ede l
ayswerehigh
c
ompare
dtotheerr
oratt
hehig
hfrequenci
es.
Themeasu
redval
uesal
lf
romfr
equenc
y5Hzb ec
ome smorest
ableand
a
ndnos i
gni
fi
canter
rori
sreac
hede x
cludi
ng1 9Hzand20Hz .Iti
sals
onoti
ceab
let
hattheerr
orhasdecreas
ing
t
ende
ncywit
hthehi
gherf
req
uency.

Time Devation Error


Sample 3
800

700

600
delay [sec]

500

400

300

200

100

0
1 2 3 4 5 6 7 8 9 101112131415161718192025303540506075100
frequency [Hz]

Fi
gur 18:Theg
e5- rap
hshowst
her
eac
hedd
ela
ysa
tal
lf
requ
enc
iesb
ySa
mpl
e3

Conc
lus
ion
Thef
ina
lgr
aphs
howst
hee
rrorpr
ogr
ess
ionov
era
llt
estf
requ
enc
iesf
ora
llt
hre
esa
mpl
es.S
omes
imi
l
ari
ti
esc
anb
e

1
03
i
denti
fi
ed.Att
hefr
equenc
ies4
,5and6allt
hre
eerr
orsa
resu
dde
nlyi
ncre
a s
edbyasi
gni
fi
cantv
alu
ea ndimmedi
at
el
y
dec
reas
ed.Si
mil
arprog
res
si
onsta
rtsf
rom t
hefr
equ
ency25Hzast
heshapeisb
enti
nthesamema nnerf
ora
llt
hre
e
er
ror
sbu t
atadi
ff
ere
ntdegr
ee.

Error Progression
70
60
50
error [%]

40
30
20
10
0
-10 1 2 3 4 5 6 7 8 9 101112131415161718192025303540506075100
frequency [Hz]

  

Fi
gur 19:Er
e5- rorpr
ogr
ess
ionf
ora
lls
ampl
es

Thefi
gurea l
soreveal
sthedeg reeoferr
ortha tcanb econcludedfr
omt hegraph.Allt
hrees
amplesperf
ormedsimil
ar
ly
att
helowr ates(1,2,3u pto1 5Hz )
.Signif
ic a
ntdiff
erencesstar
teme r
gingfrom 15Hz .S
ample1c onta
inedonl
y3
i
nstr
uct
ionsa ndtheerrorrat
eb ya l
lmeansist hehighestateve
ryfreq
uencywi t
ha nexce
pti
onof 4Hz.Samplenumber
2contai
ned6i nst
ruct
ionsa ndt heerrorr a
teb ecome smor edist
ancedf r
om S ampl
e3e rrorfr
om 25Hz .Sample
number3s howe dt
heb estperformanceou tofa l
lthre
es amples.
Thee rr
ora tt
helowerfre
quencie
swass l
i
ghtl
yabove
Sampl
e2 .Atthehigherfrequ
e nciesmorethan1 8Hzt hedi f
fer
encesig
nif
icantl
yrais
esamonga l
lt
hreesample
s.
Twohy
pot
hes
esc
anb
econc
lude
dfr
omt
hea
bov
egr
aph:
 Mor
eins
tr
uct
ionsc
aus
esl
owe
rer
rorr
ate
swhi
chb
ecome
smor
esi
gni
fi
cant
athi
ghe
rfr
equ
enc
ies(
>20Hz
)
 Hi
ghe
rthef
requ
enc
ies(
>20Hz
)ha
vehi
ghe
rer
rorr
ater
ega
rdl
essof
thenu
mbe
rof
ins
tr
uct
ion.

Theti
mede l
ayismostli
kelytob ecaus
edb ytheprog
ram memoryall
ocat
ionandex
e c
u t
ingi
nst
ruc
ti
onsa tt
he
har
dwarel
e v
elwhichr
esul
tsinsma l
lamountofdel
ay.
Thisdel
aysisa
ccumula
tedasmor
ea ndmorei
nst
ruct
ionsar
e
bei
ngexec
u t
ed.Someer
rorisal
soproduce
db ythemea
sure
menttoolt
hatwasuse
dandal
locat
ingt
hememoryfort
he
si
mula
torandfre
e i
ngi
tatt
heterminat
ion.

5
.3 Re
ver
seCodeEng
ine
eri
ng
RCE( Re
vers
eCo deEngi
neer
ing)i
saproce
ssofde
compil
i
ngthebina
ryfi
l
e s
.Thus
,thepr
oce
ssi
sthee
xac
toppos
it
e
t
oc ompi
la
ti
on. I
nthenexte
xamplewearegiv
enabina
ryfi
les
cri
pt03
.bcandthet
askist
otr
ans
for
mthebina
ryf
il
e
i
ntohumanreadabl
eas
sembl
ylangua
ge.
Tas
k:Thecont
entof
scr
ipt
03.
bci
spr
int
edb
elow.
Dec
ompi
l
ethec
odea
ndde
fi
newha
tthec
odedoe
s.I
tisnot
all
owe
d
t
orunuset
hesi
mu l
at
or.
script03.bc
0000000000000000111100001011100010010110000000001001000111111100100011110011000110010000001100
0010010101000000001001011000100000000010010010000001100110001000000011010100000010011001010000

1
04
0010011001010000001001101011000000100000100100000010110100110000000000000000000010011000111100
1000001000001000100000100100010000101001101011000010100000100100001010011010110000101000001001
00001010110011000000000000000000000101101111111111111111

Asa
nins
tr
uct
ionc
ons
is
tsof
16b
its
,thec
ont
entof
thef
il
emu
stb
espl
i
tint
ogr
oupsof
16b
its
.
Instruction 1: 0000000000000000
Instruction 2: 1111000010111000
Instruction 3: 1001011000000000
Instruction 4: 1001000111111100
Instruction 5: 1000111100110001
Instruction 6: 1001000000110000
Instruction 7: 1001010100000000
Instruction 8: 1001011000100000
Instruction 9: 0000100100000000
Instruction 10: 0110011000000000
Instruction 11: 0011010100000010
Instruction 12: 0110010100000010
Instruction 13: 0110010100000010
Instruction 14: 0110101100000010
Instruction 15: 0000100100000010
Instruction 16: 1101001100000000
Instruction 17: 0000000000001001
Instruction 18: 1000111100100000
Instruction 19: 1000001000000000
Instruction 20: 1001000100001010
Instruction 21: 0110101100001010
Instruction 22: 0000100100001010
Instruction 23: 0110101100001010
Instruction 24: 0000100100001010
Instruction 25: 1100110000000000
Instruction 26: 0000000000010110
Instruction 27: 1111111111111111

Si
ncether
eare27groupwec anass
u methatt
hepr
ogramcont
ainsma xi
mu mof25inst
ruc
tions+2k eywords(be
gin,
en
d) .
Theinst
ruct
ionisdivi
dedint
o2pa r
ts–ope
rat
ionanddi
re c
tv a
lue(whi
chnotalwaysrequi
red
) .Opera
ti
oni s
def
inedbyt
hefir
st8bits
,the
ref
oreitpos
sibl
etomaptheb
inar
ye ncodedins
tr
uct
ionint
oitssymbol
icform.Appendix
Bcontai
nst
heinst
ruct
ion.

1 00000000|00000000 → begin
2 11110000|10111000 → clr ca
3 10010110|00000000 → mov l,%val
4 10010001|11111100 → mov b,%val
5 10001111|00110001 → mov al,%val
6 10010000|00110000 → mov ah,%val
7 10010101|00000000 → mov h,%val
8 10010110|00100000 → mov l,%val
9 00001001|00000010 → sta ax
10 01100110|00000000 → inc b
11 00110101|00000010 → add al,%val
12 01100101|00000010 → inc ah
13 01100101|00000010 → inc ah
14 01101011|00000010 → inc l
15 00001001|00000010 → sta ax
16 11010011|00000000 → jnc addr
17 00000000|00001001 → undefined 1
18 10001111|00100000 → mov al,%val
19 10000010|00000000 → mov ah,al
20 10010001|00001010 → mov b,%val
21 01101011|00001010 → inc l
22 00001001|00001010 → sta ax
23 01101011|00001010 → inc l
24 00001001|00001010 → sta ax
25 11001100|00000000 → djnz b,addr
26 00000000|00010110 → undefined 2
27 11111111|11111111 → end

1
05
Thebi
nar
yins
truct
ionshav
eb e
enma ppedintot
he i
rsy
mb oli
cfor
mb yre
fer
ri
ngt
othei
nst
ruct
ionse
t.Thecor
eofthe
pr
ogr
am hasbe
ende compil
ed1,2andnowi tshoul
db e
c omecle
arera
ndroug
hlyi
dent
if
ywha tt
heprog
ram do
e s
.
Howev
er,t
hedecompila
ti
onisnoty
et f
ini
shed.
Therearetwopr oble
msde note
da sundefi
ned.Inst
ruct
ionsequence0000000000
010 110doe snotexis
tint he
i
nstr
uct
ionset.Onema ya s
sumethat00000000deter
minesthebe g
inoper
ati
onwhi c
hi sthiscas
eincor
rectasthe
se
cond8 -
bitsequencec onta
insals
o1 '
s.Sol
utiontothis
,istoloo katt
hepr ev
iousinstr
u c
ti
on.Thei ns
truc
ti
on
ex
ecute
db ef
oreu ndef
ined1i sj
ncaddr.Ther
efore
,logi
cal
lyundef
ined1def
inesanaddressloca
ti
oninme moryora
br
anch.Anybranchinstr
u c
ti
oncannotholda16-bi
taddre
ssloca
ti
ona ndt
her
eforet
headdressispl
acedri
ghtaft
ert
he
br
anchinst
ruc
tion.
Thef
ir
stc
olu
mnd
efi
nest
heme
mor
yloc
ati
onwhe
ree
achi
nst
ruc
ti
oni
spl
ace
d.
000000000 00000000|00000000 → begin
000000001 11110000|10111000 → clr ca
000000010 10010110|00000000 → mov l,%val 0d
000000011 10010001|11111100 → mov b,%val 252d
000000100 10001111|00110001 → mov al,%val 49d
000000101 10010000|00110000 → mov ah,%val 48d
000000110 10010101|00000000 → mov h,%val 0d
000000111 10010110|00100000 → mov l,%val 32d
000001000 00001001|00000010 → sta ax
000001001 01100110|00000000 → inc b
000001010 00110101|00000010 → add al,%val 2d
000001011 01100101|00000010 → inc ah
000001100 01100101|00000010 → inc ah
000001101 01101011|00000010 → inc l jump1
000001110 00001001|00000010 → sta ax
000001111 11010011|00000000 → jnc addr
000010000 00000000|00001001 → address 1
000010001 10001111|00100000 → mov al,%val 32d
000010010 10000010|00000000 → mov ah,al

000010011 10010001|00001010 → mov b,%val 10d


000010100 01101011|00001010 → inc l
000010101 00001001|00001010 → sta ax
000010110 01101011|00001010 → inc l jump2
000010111 00001001|00001010 → sta ax
000010000 11001100|00000000 → djnz b,addr
000010001 00000000|00010110 → address 2
000011010 11111111|11111111 → end

Sinc
etheme moryl
ocat
ionofeachinst
ruct
ioni
snowk nown,t
hej
u mpaddr
esscanbedet
ermine
d. I
fjnci
nst
ruc
tion
notnottruet
henex
tinst
ruc
ti
oni srea
da ndPCregi
st
er(prog
ramcount
er)i
salt
eredbyt
hisva
lue.Thelas
tst
episto
conver
tthedi
rec
tva
lues%vali
ntothei
rde c
imal
orhexa
decimal
equ
ival
ent
.
De
compi
l
eda
sse
mbl
ysc
ri
pt:
begin
clr ca
mov l,%0d
mov b,%252d
mov al,%49d
mov ah,%48d
mov h,%0d
mov l,%32d
sta ax
jump1: inc b
add al,%2d
inc ah
inc ah
inc l
sta ax
jnc jump1
mov al,%32d

1
06
mov ah,al
mov b,%10d
inc l
sta ax
jump2: inc l
sta ax
djnz b,jump2
end

Thes cr
iptsacce
ssestheme moryands t
ores1 6bit
s(values49 da nd4 8d)a tlocat
ion0 020h.Thislocati
oni
sthen
i
nc r
ementedb y1intheloop1 .
Thef i
rs
tloop( j
ump1)wi l
lbecomet r
u ewhe ncarr
yb i
tisset(j
nc )
.Howe ver
,Bregis
ter
i
sl oa
dedwi thval
ue2 52dandi si
ncrementedb yoneinsi
dethej ump1l oop,theloopwi l
lbee xi
tedaft
er6iter
ati
ons.
Insi
detheloopALr egist
erisaddedwithav al
ue2dandAHr egist
e risincr
e mentedtwiceandb othre
gist
ersar
estor
ed
i
nt heme mory.Thent hescri
ptconti
nuesa sf
oll
ow:regis
terBi sloade dwi t
hv a
lue10da ndbot hregi
st
erALa ndAH
stor
ethes amevalue32 d.Thent hescr
iptloops10timest hroug ht hejump2a nds t
oresthes amevalue32dinthe
me mory.TheLr e
gist
erwhi chdet
e r
minestheme moryaddressl
oc ati
oni sincr
eme nte
dinsidetheloop.

Fi
gur 20:S
e5- cre
ens
hot
showi
ngt
hes
tat
eof
memor
yaf
te
rthes
imu
lat
ion.
Thei
nte
res
tedl
oca
ti
onsi
nsi
det
her
ed
box
.

Thesc
ript
store
snumber0
12345
6789f
romthememoryl
oca
ti
on002
0h.
The
nthes
econdl
oops
tor
ese
mpt
yspa
ce
cha
rac
terathere
stof
thes
pac
esupt
otheaddr
essl
oca
ti
on0046
h.

1
07
Cha
pte
r6

Ev
alua
tio
nandCo
ncl
usi
on

6
.1 Ai
msa
ndObj
ect
ive
s
I
nte
rna
lar
chi
te
ctur
eoftheimpl
eme
nte
dmicr
opr
oces
sori
snotof
apart
ic
ula
rty
pebutr
athe
rins
pir
edma
inl
ybyMPC-
5
1and8051a
rchi
te
ctu
res.Thei
mpl
ement
edmic
ropr
oces
sorc
onsi
st
soft
heseu
nit
s:
 Cont
rol
Uni
t
 Re
gis
ter
s
 Ar
it
hme
ti
cLog
icUni
t
 I
nst
ruc
ti
onS
etAr
chi
te
ctu
re
 Me
mor
y
 S
tac
k

Co
ntr
olUn
it
Contr
oluni
tgenera
tescl
ocki
mpu
lse
swhic
hdete
rminewhenandhowf
astt
hemic
roope
rat
iona
repe
rfor
med.The
cl
ockspe
edisdef
ine
db yus
era
ndt
heact
ual
val
uegi
venisa
ssu
medtobei
nHert
z.

Re
gi
st
er
Eight8-bi
tre g
iste
rshavebeenimpl e
me ntsAH, AL,B,C, D,E, La ndH.Thei nternalar
chi
tect
ureamixtur
eofthe
thr
e eaccumu l
atorbas
edma chine,
r e
gist
erb a
sedma chi
nea nds t
ackbasedmachinet oprovi
deav er
sat
il
euse.I
tisa
acc
u mu l
at
orb asedarchi
te
ctureb ecauseonlyALr egis
terisc apabl
eofs t
ori
ngt her es
ult
sofa r
it
hme t
icandlogi
c
operat
ions.Iti
sar eg
ist
erbasedarchit
ectu
reb ec
ausegeneralpurposere
gis
ter
sAH, B,C, DandEa reav
ail
abl
etothe
usertoholdt emporar
ydata.Itisastackb a
sesarc
hitec
turea swellbec
ausear
ithme ti
coperat
ionscanbeperf
ormed
dir
ectl
yont hestackwit
houtanynee dforaccumula
torreg
ist
e r
.
Al
lre
gis
terar
ecapa
bleofs
impl
eincr
ement
ati
onandde
crementa
ti
on.Theint
erna
lvalu
ec anbefr
eel
ymovedf
rom
ea
chre
gis
tert
oanot
her.
Theval
uefr
omanyreg
ist
erc
ana
lsobecopi
edtothememoryorpoppedont
othes
tac
k.

Ar
it
hme
ti
cLo
gicUn
it
Ari
thmet
icl
ogi
cunithasbe
enimplementedt
oprov
idel
ogic
ala
ndmat
hemati
cal
opera
ti
ons.Thearc
hit
ect
u r
econsi
st
s
oft
wotempora
ryregi
st
ers(
temp1andt e
mp2)andthea
ri
thmet
ic&l
ogi
cbodywhic
hpe r
for
mstherequi
redoper
ati
on
onthes
etworegi
st
er.Theres
ultoftheoper
ati
oncanei
the
rbemov
edtotheALregis
terorpoppedont
ot heSt
ack

1
08
de
pendi
ngont
heope
rat
iona
lins
tr
uct
ion.

I
nst
ruc
ti
onS
etAr
chi
te
ct
ure
Theinst
ructi
onse tc onsi
st
sof2 28oft ota l256po ssi
bleinstructi
ons.Thi sme a
nsa l
most89% ofthepos si
b l
e
i
nstr
ucti
onroom ha sb ee
nfil
ledwit
hme aningf
u li
nstr
u ct
ions.Thei nstr
ucti
onc onsi
stsoftwop a
rts
:ope r
ati
ona nd
oper
and.Eachpartc onsi
st
sof8b i
ts.Thewi dt
hoft heinstru
c t
ionist here
fore1 6bi
ts.Thedataregi
st
er,st
a c
ka nd
memoryt r
ansf
erinst r
ucti
onscomposet hel arges
ts e
t( 94i nstruc
tions,41%) .Ari
thme t
icandlogicinst
ructi
ons
composethes e
condl ar
gestset(92inst r
u ct
ions,40%) .Thet hi
rdl arges
ts eti
sc ont
rolfl
ow ins
truct
ion( 29
i
nstr
ucti
ons,1
3%) .Thel a
stgroupi
sthespeciali
ns t
ruct
ionssucha sbegin,cl
earandend( 13ins
tr
ucti
ons,6
%) .

Me
mor
y
Oneoft heob j
ecti
ve swast ode si
gname mor yt ostorelar
gerda t
ase t
s.Thei mpl ementedme mor ycanstor
eu pto
64Kb .Theme morya ddressisde f
inedb y1 6b itsande achme moryloca tioncans tore2b yte
s.Ther eas
onforthi
sis
deri
vedf rom theinstruc
tiona rchit
ecturewhe re8b i
tsareres
e rv
edfort heope r
a ti
ona nd8b i
tsf
ort heoper
and( i
f
requir
ed) .Regis
tersLa ndH f ul
fi
las pe c
ia lf
u ncti
onwhe nac c
essi
ngt heme mor y
.Pr i
ort oaccessi
ngthedatain
me moryt headdressmu stb elo a
dedt ome mor ya ddres
sregis
ter.Thisa ddr e
ssisde ri
vedf r
om theLa ndH regis
ter
s
(eachstoring8b it
s).Theme mor ysu pport st
woope r
ati
onswr i
teandr ead.De pendingont heflowofinfor
ma ti
on
appropri
a teopera
tionischos en.Ifdatai sextra
c t
edf romme mor y,de
pe ndi ngont hede st
inat
ionregist
erei
the
r8b it
s
areful
l16b i
taretr
a nsf
err
e d.AXr egis
te ras peci
a l16-bi
tregi
st
erc apa
b l
eof 16-bi
tme morytrans
fer.Iti
scomposedof
ALa ndAHr egis
terwhe r
eALc ontai
nsthel owe r8b it
sandAHt hehigher8b i
tsof AX.

S
tac
k
Oneoftherequi
rementswastoimple
me ntasta
ckba
sedmac
hine.Asi
mples
tac
khasbeeni
mplement
eddir
ect
lyon
themicr
oproces
sortoful
fi
lthi
srequi
reme nt
.Thest
acki
scapab
leof8
-bi
tdat
atra
nsf
erandari
thmet
ic
.Thevalue
s
however
,cannotdir
ect
lybet r
ansf
err
edf r
om ortot
hememory.Theval
ueonthest
ackmustbepoppedouttoa
regi
st
erandthe
nmov edtothememory.

Co
mpi
l
er
Thec ompil
e rwasdevel
opedasas t
andal
onepr
og r
amwhichise xplici
tl
yinvok e
db ytheu s
er.I
tacceptsafi
lewit
hthe
ex
tensionas( as
semblysourc
e).Everyot
herex
tensi
onisi
gnoreda nda nerrorispri
ntedtothescreen.Thecompile
r
pr
ovide ss
yntaxcheck
sa ndifa
ne rr
orisf
oundtheli
nenumbera ndt hecontentof t
helineispri
nte
dt onoti
fytheuse
r
aboutthesyntaxerr
or.Eachli
nec anonl
ycont
a i
noneins
tru
ctiona ndthes ynt
axit
selfisc
a s
e-i
nse
ns i
ti
ve.Comme nt
s
ca
nb eincludedbyaft
erasepara
tingchar
act
ers
e mic
olona
ft
erthei ns t
ruct
ion.

Gr
aph
ica
lUs
erI
nte
rf
ace
Thegrap
hica
luse
rinte
rfac
ewa sdevel
ope
dde s
igni
nGl
adede
sig
ner
.Gt
kmm l
i
bra
rywa
sus
edt
oimpl
eme
ntt
he
i
nte
rfa
ce.Thei
nte
rfa
ceconsi
st
softhe
separ
ts:
 Te
xte
dit
or–a
ll
owi
ngt
heu
sert
owr
it
ethes
cri
pts
 Re
gis
terp
ane
l–c
ont
ai
nst
hei
nfor
mat
iona
bou
tther
egi
st
ers
'cont
ent
 Me
mor
yma
p–c
ont
ai
nst
hepr
int
out
oft
hewhol
eme
mor
y
 S
tac
kpa
nel
–gr
aphi
cal
l
ypr
int
edt
hev
alu
ess
tor
edont
hes
tac
k
 Compi
l
ero
utpu
t–s
howst
heou
tpu
tpr
ovi
dedb
ythec
ompi
l
er

1
09
Thec
onte
ntofr
egis
ter
siss
howni
nit
sbi
nar
yfor
mata
nde
it
herde
cima
lorhe
xade
cima
lde
pendi
ngons
ett
ing
s.The
sa
meappl
i
esf
ortheSt
ackpa
nel
.

Fi
gur 1:MI
e6- CP-
SIMu
seri
nte
rfa
ce

Theuse
risal
lowedtowri
tehisownasse
mb l
ys c
ri
pt.
Befor
esimul
ati
onthesc
riptmustb
ecompil
edbyinv
okingthe
compi
l
er.Theconte
ntofthetex
tboxissav
edintot
hefi
leandthi
sfi
lei
spass
edt ot
hecompi
le
r.Thecompil
erthen
compi
l
esandifaner
rori
sproduce
ditwil
lbeshowni
nthecompil
erout
putbox
.
Theuse
rint
erf
acewil
lnotal
lowtheuse
rtorununcompi
ledcodea
ndwi l
lre
quir
etofi
xthesy
nta
xer
ror
.Asi
nthe
abov
efi
gur
ethecompi
lerpr
ovide
suse
fulf
eedb
ackwher
ethesy
ntaxe
rrorha
sbeenenc
ount
ere
d.

Ani
mat
io
n
Du et
othescopeoft
heproj
ectandthet
imeconst
rai
nsIdi
dnotachi
evethisobj
ect
iv
e.Howeve
r,at
tempt
shaveb e
en
conduct
edbutal
loft
hemfai
led.Gtk
mmi sacompl
ica
tedAPIandwit
hinthegiv
enperi
odIra
the
rconcent
rat
edonthe
i
nterf
aceusa
bil
it
yrat
hert
hana ni
mati
on.
Itisal
somyfir
stl
ar
geproj
ectIhaveunder
tak
enandfi
rs
tti
meIwa sle
arni
ng
t
hisli
brar
y.

6
.2 Fe
edba
ck
Howe v e
r,t
hena tureofthi
sproj
ectisquit
ecompl i
c a
tedandrequ i
resagoodu nders
tandingof low-lev
elprogr
amming
andex per
ienceonLi nuxpla
tf
orms,theonlypossi
b l
esolut
ionwa stopubli
shthesoft
wa reu nderGPLl ice
nse.Icr
eat
ed
crea
tedawe b s
it
ehos te
da twww. code.
googl
e .
com/ p/micp-
sim/whe r
eIb ri
efl
ydiscus sthep urpose
,requir
ements
andi nsta
ll
ationproc es
soft hesimu l
at
or.Iha vewr it
tena ni ntr
oducti
oni ntoAs s
emb lylanguageforpotenti
al
i
ne x
pe ri
encede va
luator
s.Theinte
nde dst
epsoft hee v
aluat
orwou l
dbe-readingtheint roducti
ona ndrequir
ements
wikipa g
es.The ndownl oa
dthesourcecodea ndc ompil
eit,andf ol
lowtheAs se
mb l
yla ng ua
get u
toria
lpart1–First
Simulati
ont olear
nt hest
epstha
tarerequi
redtoru nthesi
mu l
ator.
Thesecondpa
rtoft
hetutor
ia
lisanexte
nsi
veadva
ncedint
roducti
oni ntotheAsse
mb l
ylang
uageandtheimpl
emented
i
nstr
ucti
onarc
hit
ect
u r
e.Thetutor
ial
consi
st
sofasse
mb l
yscri
ptsthatintr
oducetheuseofmanydif
fe
rentins
tr
uct
ions
su
cha sdat
atr
ansf
er,ar
it
hme t
icandcontr
olfl
owinstr
uct
ion.Aftertheev a
lua
torhasat
tempte
dt ogothroug
hthese
ex
amples,t
woexer
ci
sesarepr
ovidedatt
heendofthetut
ori
altoshowhi sunder
standi
ng.

1
10
Thee
val
uat
orwhoha
scondu
cte
dthea
bov
est
epsi
sthe
nab
let
opr
ovi
deau
sef
ulf
eedb
ackont
hes
imu
lat
ors
oft
war
e.

6
.2.
1Fe
edba
ckFor
m
Theai
m wast
ocre
ateasi
mpl
efe
edb
ackf
ormu
sedt
oga
the
rev
alu
ator
s’opi
ni
onont
hes
imu
lat
or.
Thef
eedb
ackf
orm
wasd
ivi
dedt
othr
eepar
ts
:

Co
mpu
lso
ryq
ues
ti
ons
 Use
r’
sb a
ckgro
und–Thepu r
posei
stoident
if
ytheu
ser
'
sba
ckg
rou
nd(
tea
che
r,s
tude
nt,e
tc.
)andt
he
pr
ogra
mmi ngexpe
rie
nce(
low,hi
ghl
eve
l).
 Gra
ph i
calUse
rIn
ter
fac
eLa
you
t–Cont
ai
nst
hre
equ
est
ionsa
bou
tthel
ayou
toft
hema
inc
ompone
ntsoft
he
us
erint
erfa
ce
 I
nte
rac
ti
vi
ty-
thi
spa
rti
nvol
vest
hef
eedb
ackg
ive
nbyt
hes
oft
war
e.I
fist
hea
ppr
opr
ia
tea
nd u
nde
rst
anda
ble
.
 Us
abi
l
ity-
mai
nl
yde
fi
ningt
hee
aseof
use(
wri
ti
nga
sse
mbl
ysc
ri
pts
)

Th
etwoo
pti
ona
lpa
rtsi
ncl
ude
 Ti
me-
det
ermi
nest
het
imet
hee
val
uat
ors
pent
wit
hthes
oft
war
e.Thi
sma
yinc
ludet
hee
xer
ci
ses
 Commen
t–a nyre
lat
edcomment
ssuc
hasmiss
ingfe
atur
es,
anypa
rti
cul
arpr
obl
emy
ouh
ad whi
l
e t
est
ing
.
Andov
eral
lopini
onaboutt
hes
oft
war
e,r
ecomme nda
ti
onetc.
.

Compl
et
efe
edb
ackf
ormc
anb
efou
ndi
nAppe
ndi
xDori
nit
sel
ect
roni
cve
rsi
ona
tht
tp:
//g
oo.
gl
/5c
aBK.

6
.2.
2Ev
alua
tiononFe
edba
ck
Irec
eiv
ed10fee
dbackformsback.
Foureval
uat
orshadexper
ienceinbot
hlowe
ra ndhigherpr
ogra
mmingl
angua
ges
,
thr
eeeval
uat
orhade x
pe r
ienc
eonlyinhigherprogr
ammingl angua
gesandnok nowledgeorothe
rsel
ect
edtwo
eva
luat
ors
.Thebac
kgroundoftheev
alu
ator
swas3s t
udent
s,3profe
ssi
onal
s,2t
utorsand2other
.
Thefi
rstsetofquesti
onsconsi
dere
dt heuserint
erf
ace.90% ofeval
uatorc onsi
dere
dt hedistr
ibut
ionofthepa nel
s
(r
egi
ste
rsandme moryma p)tobeappropri
ate
.Howe v
er,Idoagreewiththes t
udenteva
lu a
torwhopo i
nte
dou tthati
t
wasnoteas
yt oascer
tai
ntheme moryvalu
es.Theme moryisofla
rges i
zea ndifhi
ghme moryaddress
esar
eu se
dt he
us
erisrequir
edt oma nual
l
ys c
rol
ldowna ndchecktheme morya ddresshimself
.Thisu sab
il
ityprobl
emisde t
ai
l
des
cri
bedinFu r
therworksandaposs
ibles
oluti
onisal
sopropose
d.
These c
onds etofq u es
tionwa sai
me datsoftwa reint
e racti
vi
tya ndsimulat
ion.Theq ues
ti
oni fthes i
mu lat
orhas
hel
pedtou nde r
sta
ndt heov e
ral
lmicroproces
s ora r
chite
c tureonly60%of eval
uatorsagr
eed.2s t
udents,1profess
ional
and1othe rbackgrou nddi s
agre
ed.Idi dnotex pectav e
r yposit
ivefeedbac
kont hisquesti
ona sthesi
mu l
ati
onitsel
fi
s
onl
ya ninter
a c
tiv
ea dditiontotradi
ti
ona l
teachinga ndwi thoutanyprevi
o u
stheor e
tic
alknowledgeiti
sv er
yd if
fi
cultt
o
under
standt heimpl eme ntedconcept.Howe ve r,Ididint r
odu cedtheimpleme nt
eda r
chitec
turebu tthereportwas
onl
yb eginwr i
tte
na ndi twasnotr eadytob ep ubl
is
heda tthetimeofg at
heringfeedback.90%ofe val
uatorwou l
d
rec
omme ndthesoftwa retootherst
u dent
sb uts omeof the malsopointe
do utt
ha tifa
llb
u gsar
efixeda ndtheinte
rfac
e
i
sfull
yimpl e
me nted.
9
0%ofe v
aluat
orsag
reedthatthesi
mula
torprov
idedenoughf
eedbac
kduri
ngthesi
mu l
at
ionand80%ofe v
alua
tor
a
gree
dthatitc
ouldunder
sta
ndwha toper
ati
onswerebei
ngper
formeddur
ingthes
imula
ti
on.Thisf
eedba
ckproved
t
hati
twastheri
ghtdeci
si
ont oimpl
emente
dmi cr
oins
tr
uct
iontoshowtha
tful
lexe
cut
ionofaninst
ruc
ti
oncantake

1
11
moretha
nonecloc
kcycle
.Forexample
,theev
alu
ator
shav
elear
ntthatasi
mpl
ere
gis
terda
tat
rans
feri
nst
ruc
ti
onwi
l
l
al
waysbeex
ecu
tedfas
ter(
inshor
tert
ime)tha
nanyari
thme
ti
cinst
ruct
ion.
Thestat
ementift
heg ener
alus
eofthesimula
torwasnotdif
fi
culta
ndc ou
ldeas
il
ybefigure
dou twit
houtanyspe
cia
l
t
utor
ial80%agreeditwasnotdif
fi
cul
t.Eventhou
ghther el
eas
edvers
iontha
twasusedforfee
db a
cklack
edfromfil
e
i
nput
/ out
putinte
rfac
ea ndmanyf e
atur
essuchasintera
cti
vespeedofsimul
at
ionwa snotimplemente
d,thema i
n
f
unct
ional
it
ywa snotentir
el
yaffe
cte
db ythes
edefi
cie
nc i
es.
Thep ur
posewasnottes
tiftheuse
risabletoopenand
sa
vethewri
tte
ns c
ript(t
hisi
sgener
al
lynotdif
fi
cul
ttoachi
eve)butt
otestt
hesi
mu l
at
orandthecompiler
.
Thel as
tqu es
tionwasconcer
nedaboutthecompil
ererrorsyntaxc heck
. 80
%of ev
alua
torfou
ndt hesy nta
xcheckver
y
usefu
l and20%di sag
reedwit
hthesta
teme nt
.Twoe va
luatorswhodi s
agree
dwi ththi
ssta
teme ntwe reb ot
hs t
udent
s.I
f
indi tdiff
ic
ulttounderst
andthei
rdeci
sionasthedidr e
se a
rchi ntoothercompiler
sandwa si nspir
edb ythesynta
x
err
orou t
putthatwasproduc
edinv a
ri
ou scompil
erprograms.Ing e
nerali
tc ons
ist
edofthety peoft hee r
ror(i
nthis
caseonlyonlyde a
ltwit
hsynta
xerror
s),theli
nenumb erandpr intedli
newhe r
etheerr
orwa sfou nd.Ididfoll
owthis
convention,buti
tseemsli
keIhadtoexa
c tl
ypoi
ntoutthec har
acte rwheretheerr
orsta
rts
.
Theopt i
onalcomme ntsprovi
dedmewi thmos tu sef
ulinf
ormat
ion.Prof
e s
si
onalev a
luat
orsmainl
yaimeda tthe
i
mpleme nt
ati
ona ndg c
cou t
putwarni
ngs.Thei
rc omme ntshel
pedmet oidenti
fytheg va
ri
able
.herr
ordescr
ibedin
Furt
herWork sbelow.
Iwa sal
sogi
venre
comme nda t
ionsformake
fi
leandwarningsuchasari
thmeti
convoidtypeand
gene
ralcompilat
ionwhe r
eitshoul
dnotb eneededt oa cc
esst
helibr
arypathneit
he rcopyi
ngheader
sintoit.The
st
udentsmainlyhighl
i
ghtedthedi
ff
icu
ltyofunderst
a ndi
ngoftheconceptandwouldne edsomeonetoexpla
initin
per
son.
S
omeof
ther
ece
ive
dcomme
ntsc
anb
efo
undi
nAppe
ndi
xD.

6
.3 Fur
the
rWor
ks
 Impl
ement
ati
onError
s–Fixthegvar
ianter
rorbyr
emovi
ngthedefi
neddat
atypebyte.
Inste
adofu s
ing
poi
nter
sfocusmoreondi r
ectva
lueswhichsi
mpli
fya
ndma kethecodemorereadable
.Re movethe
req
uir
ementforroot
'sr
ightstoi
nstal
lthesof
twa
re(e.
g.c
opyingconve
rsi
on.hhe
a derint
o/ us
er/l
ib
dir
ect
ory)
.
 Mic
ropr
oce
ss
or–Curr
ent
lyt
hemicr
opr
oces
sorisonl
yabl
etoex
ecu
tema
ximu
m of2
55i
nst
ruc
ti
ons
.
Thi
sshoul
dbee
xte
ndedt
oal
lowu
singt
hehi
gher8bit
sof
theme
mory.
 Cl
ock–Cl ockratherthancr
eati
ngas epa
ratet
hread,
thetimingshoul
dbeincl
udedi
ntheexecu
tionl
oop
whi
c hwou l
de x
cludetherequi
rementforcheck
ingfortheact
ualcl
ockval
ueduri
ngexe
cut
ion.Thecl
ock
cl
assshouldthe
nonl ystor
ethevalu
e sde
fini
ngthedelayti
me .
Thisdel
ayti
mewo ul
dbeca
lledaf
tere
ach
i
nst
r uct
ioninst
eadof re
quir
ingthelooptocheckwhethert
hev al
uehasc
hanged.
 Me mor
yi mple
menta
ti
o n–theme moryimple
me nta
tionwa sdes
igne
dfromascra
tcha
sa3 -
dimensional
arr
aythatst
ores16unsigne
di nteg
ersatea
chaddresslocat
ion.
Theme moryca
nberes
igne
dtor eus
ethe
Regis
tercla
ss.Theproposeda ppr
oachsave
saloto fcodeandals
osimpli
fi
est
heimpl
ementa
tionwhich
al
soma kestheimpl
eme nta
tione a
sie
rtounders
tandb ythethi
rdpart
y.Ins
tea
dofhav
ing16va l
ues,t
he
addre
sslocati
onwil
lcontai
nt wo8 -
bitr
egi
ste
rs.
 Compil
er–howe ver
,somei nst
ruc
tionsespecia
ll
ythecontrolfl
owinst
ruct
ionswe r
eimplementeda ta
l
aterst
ageofcompil
erimple ment
ation,t
hec ompil
ermayi nte
rpre
ttheins
truct
ionsinthewrongwa y
.
Thereisane e
dt orei
mpl e
me ntthec ompile
rtoe ns
urethatjumpsa ddr
essarecalc
ulat
edc orr
ectly
.
Alt
hough,t
hec ompi
lerhasinte
rpr
ete dal
lthesampl
escri
ptscorre
ctl
ysomea l
te
rnati
onswerema deinto
compil
er'
scodeduri
ngthetesti
ng.
 Graphi
calUs erInt
er
fac
e–t heGUIi sthema jorwe ak
nessoft hi
sproje
ct.Mu l
ti
-t
hreade
dGTK
appl
ica
tiondidnotprovedtobefaste
noughtor ef
res
ht hecont
entoftheregi
st
ersandme mory.A
dif
fe
renta ppr
oac
hisess
enti
ali
nordert
os moot
ht heupdate
s.Theint
ernalc
onte
ntofmic r
oproc
essor
compone ntsi
spr
inte
dintoate
xtb
o xwhic
hisbei
ngr ef
res
ha f
tere
achinst
ruc
ti
on.Ift
heclockspe
edof

1
12
t
hemi croproces
sorist
oohightheuse
rwi l
lnotnoti
cethec hangei
mme di
atel
y.Theme moryma pt
e x
t
boxisinappropri
at
elybi
gandthesc
roll
ingpadretur
nstothet oppos
it
ionaft
erever
yinst
ruct
ionwhich
c
a us
esc onfusi
on.There
for
e,themapsho u
ldb espl
ita
llowingtheuserdef
inearangeoftherequi
red
a
ddre s
ses.Eachpa r
tshoul
dha v
eit
sownt ex
tb oxorl
a belthatwoul
db eu p
date
dde pendi
ngont he
i
nstr
u c
tion.This,
wou l
dcons
equent
lysa
v et
imeforupdati
ngt hewhol
einte
rfac
e.
Theinstr
ucti
onshoul
db ehi g
hli
ghtedduringthesimul
ati
ontoma ketheuserawar
eoftheinst
ructi
on
t
hatisb e
ingexec
ute
d.Ex perimenta
lste
ppi ngsi
mu l
at
ionforsi
milarfunc
ti
onali
tyhasbeenatt
empted
andprovedt obemor ec omplexthanitwa sini
ti
al
lyexpect
ed.Eachl i
newou l
dne e
dt oha v
ea n
i
nstru
cti
ona s
soci
at
edwithi tandtheappropria
teli
newouldbehighli
ghte
da c
cordi
ngtothi
srefe
rence.
Thesteppedappr
oachimpl ementsasi
milarfuncti
onbutfai
lswhena nemptyli
neisins
erte
dintothe
scr
iptf
il
e.
 Animat
io
n–Ana ni
mati
onshowingt heint
erna
lfl
ow ofi nf
ormat
ionwoul
dincre
asetheover
al
l
under
st
atingofthemicr
oproc
essora
rchit
ect
ure
.Eachinst
ructi
onwouldha
veadef
inedpr
ocedu
reto
ani
matetheproc
e s
s.The
rewouldbemax i
mumof 2
56animat
ions.
 Te
xtedi
to
r–addmoref
eat
ure
ssu
cha
sli
nehi
g hl
ig
hti
ngandnu
mbere
dlines.
Whe nl
ar
ges
cri
ptsare
wr
it
ten,
thenu
mbere
dli
neswoul
dmak
eeas
iertoi
dent
if
ythes
ynt
axer
rorsprodu
cedt
hec
ompi l
er
.

1
13
Appe
ndi
ces

1
14
Appe
ndi
xA

Te
rmofRe
fer
enc
e

A.
1 Pr
oje
ctBa
ckg
round
Mi c
roprocessorareg e
ne r
al
lyv eryc omplic
atedi ntegratedcir
cu itchi
pswhicha r
edi ffi
cul
ts u
b j
ecttoteach.I tisa n
i
mpor tanttopicincompu terarchi
te ct
uresasitist hefundame ntalpar
tofeverycompu t
ersyste
m. Possi
bi
lityofl ar
g e
cal
culati
onsinas mallamo untof t
ime ,pr
ogrammi ngc apabi
li
ti
e sandthepotenti
alt
oc ommu nic
atewithothe rde v
ices
hasincreasedt hescal
eofa ppli
c a
tionsthemi c
ropr oce s
sorhasb e
enu s
edin.Att hepr esentti
mee v
eryi ntell
igent
elec
tronicdevicesuchasamob i
lep honeorana vig at
ions ys
temdoe sconta
ins omekindof microproc
essor.Asar es
u l
t
ofthiseveryc omputersci
ences tudentshouldk nowt heg e
nera lar
chi
tect
ureofmi c
r oproce
s s
orandhowi tma nages
andpr oces
sesda ta
,andc ontrol
sot herpa r
tsoft hes ystem.Ma nyme t
hodsforteachingmi cr
oprocess
orsha v
eb ee n
proposed,onei mportantme t
hodi ssimu l
ati
on.Ca mb r
idgeAdv a
nced Le a
rner
'sDi c
ti
ona r
y[ 2008]de fi
ne sa
si
mu lat
ionas


amo
del
ofas
eto
fpr
obl
emso
fev
ent
sth
atc
anb
eus
ed
t
ote
achs
ome
oneh
owt
odos
ome
thi
ng,
ort
hep
roc
esso
f
ma
kin
gsu
chamo
del

Howe ver,purethe
oret
icalteachingofthesu bj
ectdoe snotful
lyc l
ari
fi
eswha tthes tudentisexpectedt
ou nders
tand,
andthisistheti
mewhe nsimu lati
oncome si
nt obridgetheg a
pb etweenthetheor yandthere a
lwor d.Oneofthemos t
val
uablef eat
ureofsi
mu l
a t
ioni sthatstudentshav eanoppor tunit
ytoa pplyt heirtheoret
icalknowledgeinas af
e
r
e a
li
sti
ce nvi
ronment
.Mi c
ropr oces
sorsimu l
ati
onr e
v e
alsrealsituat
ionsofi nne rmic r
oprocessorproces
ses.The
advant
a geofsimul
ati
onistha tu s
erhasac a
pab i
l
itytog r
aphical
lyill
ust
ratethewhol eprocessanddi spl
aytheint
ernal
s
tateata nyt i
meofthee xecution.Additi
onall
y,instr
u c
tionscanb eex ec
uteds tep-b
y -
stepme thodwhi chst
opsthe
exec
u t
iona ft
ereac
hinstr
u c
tion, t
husstudentshavea nopportunitytoidenti
fythec hangesthathav ebeenmadeafter
eac
hs t
e p.
Theproj
ectshouldst
a rtbyhigh-
leve
ldescr
ipti
onofasimpl
emodelprocess
orfoll
owedb ypr
ecis
es pe
cifi
cat
ionand
des
ignofthemode landc orr
espondi
ngGUI .Then,th
emode li
stob eimpl
eme nt
edalongwit
ht heGUI .Thefinal
pr
oductisas of
twar
et oolthatacce
ptsshor
ta s
sembl
ylangua
gescr
iptandsimulat
esi
tse x
ecut
ionona ninterpr
ete
r
modelofaproces
sor.
Thes cri
pt e
xecut
ionwill
bevis
ual
lysk
etc
hedandproces
sorsta
ti
st
icswil
lbedispl
ayed.
Thema inreasonIhavec hosenthi
sproj
ectisthatIprefe
rredt ochooseacha l
leng
ingtaskthatwou l
da l
l
owmet o
i
mpr ovemypr ogra
mmi ngs ki
ll
sandknowledgea boutsomethingIa m notveryfamili
arwit
h.Thepr ojec
tc over
sa
l
argeareaf r
om microproces
sora r
chi
tec
tur
es,c ompil
ersandl ow-lev
elprog r
ammi ngtog ra
p hic
alu serint
e r
fac
es.
Howe ver
,Ionlyhaveasu per
fi
cialk
nowledg
ea boutthetopi
c, t
hepr oj
ectofmicroproces
sorsi
mu l
at
ionb ri
ngsmea n
opport
unitytolea
rninde tai
lwhatIaminteres
tedi n(whet
he rprogra
mmi ngormi cropr
ocess
or sarchi
tect
u r
es).
The
proj
ectrequir
ementsplayedthek eyrol
einmyde ci
si
ont oc hooseana dequateproje
ct.Programmi ngs k
ill
sand

1
15
knowle
dgeofsimpledet
ail
sofamicr
oproc
essora
rerel
eva
nttomyint
ere
stsandknowl
edge
.Thesub
jec
tasi
thasbe
en
menti
onedaboveisquit
ebroa
da ndthe
rearesuf
fi
ci
entre
sou
rceswhe
therbooksort
heInt
erne
twhi
chal
sof
ir
me dmy
deci
si
onoverthisu
nit.

A.
2 Ai
ms
Theaim ofthisproj
ectistodeve
lopas impl
esimula
torf
orb a
sicmicr
oproc
ess
orstha
tcouldbeusedfortea
chi
ng
si
mplecompu tera
rchit
ectu
re.Al
ongwi t
has ui
ta
blefr
ont-
endGUI ,t
hesimul
ati
onsshoul
dincl
udebot
ht here
gis
ter
andst
ackbasedma c
hine
s.Thestudentshoul
dsel
ectfr
om themanysi
mpl ei
nst
ruc
ti
ons e
ts,t
hewaytopa r
sei
nthe
i
nstr
uct
ions,
a ndhowt odis
pla
ytheanimatedpr
ocess
or.

Wh
atIa
mho
pin
gtog
ainf
romt
hisp
roj
ec
t?
 l
ear
nab
out
mic
ropr
oce
ssorh
owt
heywor
kandt
hei
rar
chi
te
ctu
re
 f
ul
lyu
nde
rst
andwha
tisme
ant
byami
cr
opr
oce
ssors
imu
lat
ion
 l
ear
nab
out
howma
inme
mor
y(RAM)wor
ks
 i
mpr
ovemypr
ogr
ammi
ngs
kil
l
s
 l
ear
nab
out
compi
l
ati
onpr
oce
sse
s
 l
ear
ntheAs
semb
lyl
ang
uag
e

A.
3 Obj
ect
ive
s
Asthi
sismyfirstexper
ie
nc ei
nu nde
rta
kingaproje
ctt
hatIknowv e
rylit
tl
eabout
,itsunc
lea
rtomet hea mountof
workre
quir
edtoi mple
me ntsu
chaprojec
t.Cons
equent
ly
,Iai
mt oimple
me ntas
implesi
mulat
oral
lowingexec
u t
inga
si
ngl
einst
ruct
ionsatat i
mewi t
hGUI ,however
,ifIha
vethetimeIwilli
mplementasmanye x
traspeci
fi
cat
ionsas
poss
ibl
e.

1
.0 Pr
oje
ctb
ack
gro
unda
ndl
i
ter
atu
rer
evi
ew
Inorde
rtoachi
evethesetofa i
msIwillnee
dac ompre
hensi
veunder
st
a ndi
ngofmicr
oproc
essors
,the
ira
rchi
tectu
re
andpri
nci
plest
heya r
eb as
e d/wor
kon.Thi si
nclu
desal
lthepart
sthatami c
ropr
ocess
orconsi
stsof
.Addit
ional
ly,
i
mplementi
ngame moryu nitdoesre
qu i
reag oodknowle
dgeofdiff
e r
entaddr
ess
ingmode sandhow da t
aa r
e
org
anis
edandst
oredintheme mory.

2
.0 Re
vie
wof
obj
ec
tor
ie
nte
dpr
ogr
ammi
ng
Objec
tori
ent
eddes
ignpri
nci
plesandunder
st
andi
ngthes
imul
at
ionpr
oce
sse
sarebe
nef
ic
ialf
orasu
cce
ssf
ulproj
ect
.
Withreg
ardtot
heimplementa
tionsta
ge,Iamint
endedtor
evie
wobje
ctori
ent
edpr
ogrammi
ngi
nC++a ndle
arn
ab
ou t
crea
ti
ngmult
ipl
ethr
eadsinasing
lepr
oces
s.

3
.0 De
vel
opi
ngau
seri
nt
er
fac
e
I
nres
pectt
otheg r
aphi
caluse
rinte
rfa
ce,ther
ea r
eplent
ysol
uti
ont oachi
evet
hedes
ir
abl
ere
qui
reme
nts
whi
cha
re–se
lec
ti
onofopt
ions,
contr
olcap
abil
it
y,anal
ysi
sofou
tput,
por
tabi
li
tyandeas
eofus
e.

1
16
4
.0 Re
vie
wof
exi
st
ings
imu
lat
ors
Therehav
ebeenplentyofsimu
lat
orsal
readyre
lea
seda
ndar
eava
il
abl
etou s
ers
.Iwil
lana
lysesomeofthema nd
hi
ghli
ghtt
hei
radvanta
gesanddisa
dvant
ages.Ba
sedonmyr
evi
ewofex
ist
ingsi
mula
tor
sIwillde
v e
lopa
ni nt
erf
ace
ta
kingt
headv
anta
geof whatIwi
ll
havele
arnt.

5
.0 I
mpl
eme
nti
ngas
imp
lec
omp
il
erf
orAs
se
mbl
yla
ngu
age
AsIknowonl
yv e
ryli
tt
lea
boutt
heAss
emb l
yla
nguag
eormachi
necodeadept
hknowl
edgeabou
tconst
ruc
ti
ngs
ucha
compil
eri
ses
sent
ial
.Theai
misnot
tocre
ateabra
ndyouas
sembl
ylangu
agewit
hnewnon-
st
andar
dsynt
ax.

6
.0 An
ima
ti
on
Anani
mati
onpr
odu ce
ddu r
ingofaf
te
rtheex
ecu
t i
onofanas
sembl
yscr
ipt
.Iha
venev
eruse
dgr
aphi
cspr
ogr
amming
be
for
e,t
husIam notsur
eofthewayachi
evi
ngthi
satthi
smomentint
ime.Ia
ssu
melea
rni
ngasi
mple2Dgra
phi
cs
l
ib
rar
ywil
lbene
cessar
ytoreac
hthedes
ir
edai
ms.

A.
4 Pr
oje
ctDe
li
ver
abl
es
 Theproj
ecti
sint
ende
dtodel
iv
eraf
ulls
oft
war
epack
agewhic
hi nc
ludessi
mul
ati
onsof
twar
e,g
raphi
cal
use
r
i
nte
rfa
ce,as
sembl
ycompi
le
randabl
ocksc
hemeof
micropr
oce
ssorcapa
b l
eofs
impl
evis
ual
simul
ati
on
 Pr
oje
ctre
portwhichc
ons
ist
sofre
lev
antl
it
era
turer
evi
ew,re
vie
wofe x
is
ti
ngs
imu
lat
orsont
hema
rke
tand
de
tai
le
ddesc
ript
ionof
des
ignandi
mpleme
ntat
ionof
mymi c
ropr
oce
ssor
 Somee x
ampl
esofs
impl
eas
semb
lypr
ogr
amswi
l
lbei
ncl
ude
dtoe
ncou
rag
ings
tude
ntst
owr
it
ethe
irown
prog
rams

1
17
Appe
ndi
xB

I
nst
ruc
tionSe
t
DEC BINARY HEX INSTRUCTION DESCRIPTION

1 00000001 0x01 nop


2 00000010 0x02
3 00000011 0x03
4 00000100 0x04
5 00000101 0x05
6 00000110 0x06 xor al,h
7 00000111 0x07 xor al,%m
8 00001000 0x08 xor al,%val
9 00001001 0x09 sta %M,ax 16-bit memory transfer
10 00001010 0x0A mov %M,al
11 00001011 0x0B mov %M,ah
12 00001100 0x0C mov %M,b
13 00001101 0x0D mov %M,c
14 00001110 0x0E mov %M,d
15 00001111 0x0F mov %M,e
16 00010000 0x10 mov ax,%M 16-bit memory transfer
17 00010001 0x11 mov b,%M
18 00010010 0x12 mov c,%M
19 00010011 0x13 mov d,%M
20 00010100 0x14 mov e,%M
21 00010101 0x15 not al
22 00010110 0x16 not ah
23 00010111 0x17 not b
24 00011000 0x18 not c
25 00011001 0x19 not d
26 00011010 0x1A not e
27 00011011 0x1B not l
28 00011100 0x1C not h
29 00011101 0x1D orl al,ah
30 00011110 0x1E orl al,b
31 00011111 0x1F orl al,c
32 00100000 0x20 orl al,d
33 00100001 0x21 orl al,e
34 00100010 0x22 orl al,l
35 00100011 0x23 orl al,h
36 00100100 0x24 and al,ah
37 00100101 0x25 and al,b

1
18
DEC BINARY HEX INSTRUCTION DESCRIPTION

38 00100110 0x26 and al,c


39 00100111 0x27 and al,d
40 00101000 0x28 and al,e
41 00101001 0x29 and al,l
42 00101010 0x2A and al,h
43 00101011 0x2B orl al,%m
44 00101100 0x2C and al,%m
45 00101101 0x2D orl al,%val
46 00101110 0x2E and al,%val
47 00101111 0x2F xor al,ah
48 00110000 0x30 xor al,b
49 00110001 0x31 xor al,c
50 00110010 0x32 xor al,d
51 00110011 0x33 xor al,e
52 00110100 0x34 xor al,l
53 00110101 0x35 add al,%val
54 00110110 0x36 add al,%m
55 00110111 0x37 add al,ah
56 00111000 0x38 add al,b
57 00111001 0x39 add al,c
58 00111010 0x3A add al,d
59 00111011 0x3B add al,e
60 00111100 0x3C add al,l
61 00111101 0x3D add al,h
62 00111110 0x3E sub al,%val
63 00111111 0x3F sub al,%m
64 01000000 0x40 sub al,ah
65 01000001 0x41 sub al,b
66 01000010 0x42 sub al,c
67 01000011 0x43 sub al,d
68 01000100 0x44 sub al,e
69 01000101 0x45 sub al,l
70 01000110 0x46 sub al,h
71 01000111 0x47 mul al,%val
72 01001000 0x48 mul al,%m
73 01001001 0x49 mul al,ah
74 01001010 0x4A mul al,b
75 01001011 0x4B mul al,c
76 01001100 0x4C mul al,d
77 01001101 0x4D mul al,e
78 01001110 0x4E mul al,l
79 01001111 0x4F mul al,h
80 01010000 0x50 div al,%val
81 01010001 0x51 div al,%m
82 01010010 0x52 div al,ah
83 01010011 0x53 div al,b
84 01010100 0x54 div al,c
85 01010101 0x55 div al,d
86 01010110 0x56 div al,e
87 01010111 0x57 div al,l

1
19
DEC BINARY HEX INSTRUCTION DESCRIPTION

88 01011000 0x58 div al,h


89 01011001 0x59
90 01011010 0x5A
91 01011011 0x5B
92 01011100 0x5C
93 01011101 0x5D
94 01011110 0x5E
95 01011111 0x5F
96 01100000 0x60
97 01100001 0x61
98 01100010 0x62
99 01100011 0x63
100 01100100 0x64 inc al
101 01100101 0x65 inc ah
102 01100110 0x66 inc b
103 01100111 0x67 inc c
104 01101000 0x68 inc d
105 01101001 0x69 inc e
106 01101010 0x6A inc h
107 01101011 0x6B inc l
108 01101100 0x6C dec al
109 01101101 0x6D dec ah
110 01101110 0x6E dec b
111 01101111 0x6F dec c
112 01110000 0x70 dec d
113 01110001 0x71 dec e
114 01110010 0x72 dec h
115 01110011 0x73 dec l
116 01110100 0x74
117 01110101 0x75
118 01110110 0x76
119 01110111 0x77
120 01111000 0x78
121 01111001 0x79
122 01111010 0x7A
123 01111011 0x7B
124 01111100 0x7C
125 01111101 0x7D
126 01111110 0x7E
127 01111111 0x7F
128 10000000 0x80
129 10000001 0x81 mov al,ah
130 10000010 0x82 mov ah,al
131 10000011 0x83 mov al,b
132 10000100 0x84 mov al,c
133 10000101 0x85 mov al,d
134 10000110 0x86 mov al,e
135 10000111 0x87 mov al,l
136 10001000 0x88 mov al,h
137 10001001 0x89 mov ah,b

1
20
DEC BINARY HEX INSTRUCTION DESCRIPTION

138 10001010 0x8A mov ah,c


139 10001011 0x8B mov ah,d
140 10001100 0x8C mov ah,e
141 10001101 0x8D mov ah,l
142 10001110 0x8E mov ah,h
143 10001111 0x8F mov al,%val
144 10010000 0x90 mov ah,%val
145 10010001 0x91 mov b,%val
146 10010010 0x92 mov c,%val
147 10010011 0x93 mov d,%val
148 10010100 0x94 mov e,%val
149 10010101 0x95 mov h,%val
150 10010110 0x96 mov l,%val
151 10010111 0x97 mov b,al
152 10011000 0x98 mov b,ah
153 10011001 0x99 mov b,c
154 10011010 0x9A mov b,d
155 10011011 0x9B mov b,e
156 10011100 0x9C mov b,h
157 10011101 0x9D mov b,l
158 10011110 0x9E mov c,al
159 10011111 0x9F mov c,ah
160 10100000 0xA0 mov c,b
161 10100001 0xA1 mov c,d
162 10100010 0xA2 mov c,e
163 10100011 0xA3 mov c,h
164 10100100 0xA4 mov c,l
165 10100101 0xA5 mov d,al
166 10100110 0xA6 mov d,ah
167 10100111 0xA7 mov d,b
168 10101000 0xA8 mov d,c
169 10101001 0xA9 mov d,e
170 10101010 0xAA mov d,l
171 10101011 0xAB mov d,h
172 10101100 0xAC mov e,al
173 10101101 0xAD mov e,ah
174 10101110 0xAE mov e,b
175 10101111 0xAF mov e,c
176 10110000 0xB0 mov e,d
177 10110001 0xB1 mov e,h
178 10110010 0xB2 mov e,l
179 10110011 0xB3 mov h,al
180 10110100 0xB4 mov h,ah
181 10110101 0xB5 mov h,b
182 10110110 0xB6 mov h,c
183 10110111 0xB7 mov h,d
184 10111000 0xB8 mov h,e
185 10111001 0xB9 mov h,l
186 10111010 0xBA mov l,al
187 10111011 0xBB mov l,ah

1
21
DEC BINARY HEX INSTRUCTION DESCRIPTION

188 10111100 0xBC mov l,b


189 10111101 0xBD mov l,c
190 10111110 0xBE mov l,d
191 10111111 0xBF mov l,e
192 11000000 0xC0
193 11000001 0xC1 mov l,h
194 11000010 0xC2 cjne al,%val,addr
195 11000011 0xC3 cjne ah,%val,addr
196 11000100 0xC4 cjne b,%val,addr
197 11000101 0xC5 cjne c,%val,addr
198 11000110 0xC6 cjne d,%val,addr
199 11000111 0xC7 cjne e,%val,addr
200 11001000 0xC8 cjne l,%val,addr
201 11001001 0x0xC9 cjne h,%val,addr jump if not equal
202 11001010 0xCA djnz al,addr
203 11001011 0xCB djnz ah,addr
204 11001100 0xCC djnz b,addr
205 11001101 0xCD djnz c,addr decrement and jump if not zero
206 11001110 0xCE djnz d,addr
207 11001111 0xCF djnz e,addr
208 11010000 0xD0 djnz l,addr
209 11010001 0xD1 djnz h,addr
210 11010010 0xD2 jc addr jump if carry set
211 11010011 0xD3 jnc addr jump if carry not set
212 11010100 0xD4 cje al,%val,addr
213 11010101 0xD5 cje ah,%val,addr
214 11010110 0xD6 cje b,%val,addr
215 11010111 0xD7 cje c,%val,addr
216 11011000 0xD8 cje d,%val,addr
217 11011001 0xD9 cje e,%val,addr
218 11011010 0xDA cje l,%val,addr
219 11011011 0xDB cje h,%val,addr jump if equal
220 11011100 0xDC jz jump if al is zero
221 11011101 0xDD jnz jump if al is not zero
222 11011110 0xDE push %val
223 11011111 0xDF push al
224 11100000 0xE0 push ah
225 11100001 0xE1 push b
226 11100010 0xE2 push c
227 11100011 0xE3 push d
228 11100100 0xE4 push e
229 11100101 0xE5 push l
230 11100110 0xE6 push h
231 11100111 0xE7 pop al
232 11101000 0xE8 pop ah
233 11101001 0xE9 pop b
234 11101010 0xEA pop c
235 11101011 0xEB pop d
236 11101100 0xEC pop e
237 11101101 0xED pop l

1
22
DEC BINARY HEX INSTRUCTION DESCRIPTION

238 11101110 0xEE pop h


239 11101111 0xEF add %s
240 11110000 0xF0 clr ca clear carry
241 11110001 0xF1 sub %s
242 11110010 0xF2 mul %s
243 11110011 0xF3 div %s
244 11110100 0xF4 orl %s
245 11110101 0xF5 and %s
246 11110110 0xF6 xor %s
247 11110111 0xF7 clr al
248 11111000 0xF8 clr ah
249 11111001 0xF9 clr b
250 11111010 0xFA clr c
251 11111011 0xFB clr d
252 11111100 0xFC clr e
253 11111101 0xFD clr h
254 11111110 0xFE clr l
255 11111111 0xFF end
0 00000000 0x00 begin

1
23
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

0 1 2 3 4 5 6 7 8 9 A B C D E F

0000 0 begin nop xor xor xor sta mov mov mov mov mov mov

0001 1 mov mov mov mov mov not not not not not not not not orl orl orl

0010 2 orl orl orl orl and and and and and and and orl and orl and xor

0011 3 xor xor xor xor xor add add add add add add add add add sub sub

0100 4 sub sub sub sub sub sub sub mul mul mul mul mul mul mul mul mul

0101 5 div div div div div div div div div

0110 6 inc inc inc inc inc inc inc inc dec dec dec dec

0111 7 dec dec dec dec

1000 8 mov mov mov mov mov mov mov mov mov mov mov mov mov mov mov

1001 9 mov mov mov mov mov mov mov mov mov mov mov mov mov mov mov mov

1010 A mov mov mov mov mov mov mov mov mov mov mov mov mov mov mov mov

1011 B mov mov mov mov mov mov mov mov mov mov mov mov mov mov mov mov

1100 C clr mov cjne cjne cjne cjne cjne cjne cjne cjne djnz djnz djnz djnz djnz djnz

1101 D djnz djnz jc jnc cje cje cje cje cje cje cje cje jz jnz push push

1110 E push push push push push push push push pop pop pop pop pop pop pop pop

1111 F clr sub mul div orl and xor clr clr clr clr clr clr clr clr end
p
agei
nte
nti
ona
ll
yle
ftb
lan
k
Appe
ndi
xC

Sol
uti
ons
Exe
rci
se1Writ
eapr
ogr
amt
hatwi
l
lpr
int
you
rna
mef
romme
mor
yloc
ati
on1
000
hasNAME_S
URNAME(
whe
re_
whi
tes
pac
e).

begin
mov c,%00h
mov b,%5ah
j: dec b
push b
inc c
cjne c,%25d,j
mov h,%0h
mov l,%30h
clr c
dec c
mov al,%20h
j1: pop ah
sta ax
inc l
dec c
jnc j1
end

Exer
cie2 Wr
s i
teaprogr
amthatwi
llpri
nttheAl
phabe
t( l
et
terA-Z)i
ntome
mor
yfr
om l
oca
ti
onf
rom 1
000
h.A
sa
mplesol
uti
onf
orthe
s ee
xer
ci
sesc
anb ef
oundinAppe
ndixB.

begin
mov h,%0h
mov l,%30h
mov ah,%77d
mov al,%65d
sta ax
inc l
mov ah,%82d
mov al,%69d
sta ax
inc l
mov ah,%75d
mov al,%32d
sta ax
inc l
mov ah,%82d
mov al,%69d
sta ax
inc l
mov ah,%80d

1
26
mov al,%65d
sta ax
inc l
mov ah,%75d
mov al,%32d
sta ax
end

1
27
Appe
ndi
xD

Fe
edba
ck

D.
1 Fe
edba
ckFor
m
Ba
ckg
round
Yo
urb
ack
gro
und
a
)Le
ctur
er/
Tutor
/Tr
ai
ner
b
)St
udent
c
)Pr
ofe
ssi
onal
Pr
ogr
ammi
nge
xpe
ri
enc
e
a)Noknowledgeofpr
og r
ammi ng
b)Knowledgeofhi
gherprogr
amminglanguag
es(C++,
Jav
a,PHP..
)
c)Knowle
dgeof l
owerAssemblyprog
ramming
d)Exper
ienc
e di
nbothhigherandl
owe rpr
ogra
mmingl
anguag
es
e)Other

Us
erI
nte
rfa
ceLa
yout
Us
eri
nte
rf
acel
ayo
uti
sap
pro
pri
at
e(d
ist
ri
but
io
nof
pan
elsa
ndt
ext
edi
to
r)
a
)Ye
s
b
)No
I
sit
eas
ytoa
sce
rt
ai
nth
eco
nte
nto
far
egi
st
er
?
a
)Ye
s
b
)No
I
sit
eas
ytoa
sce
rt
ai
nth
eco
nte
nto
fap
art
ic
ula
rme
mor
yad
dre
ss
?
a
)Ye
s
b
)No
I
sit
eas
ytoa
sce
rt
ai
nth
eco
nte
nto
fap
art
ic
ula
rme
mor
yad
dre
ss
?
a
)Ye
s
b
)No

Us
erI
nte
rac
tiv
ity
I
tisc
le
arwh
ato
per
ati
onsa
reb
ein
gpe
rf
orme
ddu
rin
gsi
mul
at
io
n.

1
28
a
)Ag
ree
b
)Di
sag
ree
S
imu
lat
orp
rov
ide
sad
equ
atef
ee
dba
ckd
uri
ngs
imu
lat
io
n(s
hel
l
)
a
)Ag
ree
b
)Di
sag
ree
If
i
nds
ynt
axe
rro
rch
eckv
eryu
sef
ul
a
)Ag
ree
b
)Di
sag
ree

Us
abi
li
ty
I
tisg
ene
ral
l
yno
tco
mpl
i
cat
edt
owr
it
ean
dte
sta
sse
mbl
ysc
ri
pt
s
a
)Ag
ree
b
)Di
sag
ree
Th
eso
ft
war
eha
she
lpe
dmet
oun
der
st
andh
owg
ene
ral
l
ymi
cr
opr
oce
ss
orswo
rk
a
)Ag
ree
b
)Di
sag
ree
If
i
ndt
hes
imu
lat
oru
sef
ulIwo
uldr
eco
mme
ndi
ttoo
the
rst
ude
nts
a
)Ag
ree
b
)Dis
agr
ee

Opt
iona
lque
sti
ons
Ho
wmu
cht
imed
ida
ppr
oxi
mat
iv
elyy
ous
pen
dont
hee
xer
ci
se
s?

Co
mme
nt

D.
2 Sa
mpl
eComme
nts


Onlywor
kedonget
ti
n gi
ttocompi
leandst
art
.Tr
iedasi
ngl
eexampl
eonl
y.
Hadtr
oub
lewit
hsi
nglest
eppi
ng.Coul
duseamova
bles
pli
tt
erbe
caus
enota
ll
r
egi
st
er
sweres
hown(Ih a
dtosc
roll
).
Co
uldb
ean
ices
imo
ncet
hep
rob
lemsa
res
ort
edo
ut.

Pr
ofe
ssi
ona
l


Th ep
robl
emover
all
wa sthef
ullu
n d
ers
tandi
ngo
fth
eappl
i
cat
io
na ndh
owit
l
ogi
cal
lywor
ks,
readi
nga s
ci
i c
odes
,matc
hin
ganddec
odi
ngas
ci
icod
esre
qui
re
v
erygoodmat
hemat
ical
a ndtec
hni
calsk
il
ls
.
Iwo
uldl
i
kes
ome
bod
ytog
eti
nto
uchmef
orf
urt
herq
uer
ie
s.
Th
anky
ou”
S
tude
nt

1
29
“Thi
sisanouts
tand
ingwor
k.Ihav
enohes
it
ati
ontosa
ythatth
erear
enots
o
manystud
entswhocandos
ometh
ings
imi
lar
.Verys
impl
eb u
tyetpo
werf
ult
o
hel
pwithth
ea s
se
mb l
yla
nguag
e-atal
ll
ev
el
s.Ver
yimpres
ed!

Le
ctu
rer
/Tu
tor
/Tr
ai
ner

“Thepr
ogra
mwo r
kperf
ec
tandhasn
op r
obl
emtope
rf
ormanycal
cul
ati
on.
Theper
sonwhodi
dit
,sho
wedho
wmu chkno
wle
dgea
ndint
er
esth
e/sh
eh as
i
np ro
grammin
g.
Th
iss
of
twa
rei
wil
lre
comme
ndi
tase
xamp
lef
orp
rog
rami
ngt
ask
.
Al
lt
heb
est

Ot
her


dif
fi
cul
ttoi
nst
al
landl
oto
fbu
gs.
iwo
uldr
eco
mme
ndf
i
xin
gth
ema
ndt
hen
r
el
eas
etheso
ft
ware

S
tude
nt

1
30
Appe
ndi
xE

Re
qui
reme
nts

E.
1 Tool
s
S
tanda
rdde
vel
opme
ntt
ool
sav
ail
abl
eonLi
nuxma
chi
neswi
thr
oota
cce
ss:
 g
cc(
GNUC++Compi
l
er)
 ma
keu
til
i
tyt
obu
il
dex
ecu
tab
lef
il
es

E.
2 Li
bra
rie
s
Thef
oll
owi
ngl
i
bra
ri
esa
rer
equ
ire
dtob
eav
ail
abl
eont
hema
chi
nepr
iorc
ompi
l
ati
on.

E.
2.1Li
bgl
ade
Gr
aphi
cal
Int
erf
aceDe
scr
ipt
ionLo
ade
rAPI
l
i
bgl
adeisal
ib
rar
ythatprovi
desinte
rfa
cesforlo
a di
nggra
phi
calint
erf
ace
sdes
cri
bedingl
adex mlf
il
esa
ndf
or
a
cce
ssi
ngt
hewi
dge
tsbu
ilt
intheloa
dingproc
ess,
.gl
adefi
le
sar
egener
ate
db yt
heGl
adeapp
li
cat
ion.
S
our
ce:ht
tp:
//l
i
bra
ry.
gnome
.or
g/de
vel
/l
ib
gla
de/
sta
ble
/
Ub
unt
u:a
pt-
get
ins
tal
ll
ib
gla
de2
.0
I
fthep
ack
agec
oul
dnot
bef
oundu
sea
pt-
geti
nst
al
ll
ib
gla
de2
.0*

E.
2.2Gt
kmm
C++I
nte
rfa
cesf
orGTK+a
ndGNOME
gtk
mm istheoff
ici
alC++inter
fac
eforthepopul
arGUIlibra
ryGTK+.Hi ghl
ig
htsinc
ludetypes
afecall
bac
ks,anda
compre
hensi
vesetofwi
dgetst
hatareea
sil
yext
ens
ibl
eviainhe
rit
ance
.Youcancreat
euserint
erf
acesei
theri
ncodeor
wit
htheGladeUserInt
erf
acedes
igner
,usi
ngGtk:
:Bui
l
de r
.There'
sext
ens
ivedocument
ation,
incl
udingAPIref
erenc
e
andatut
ori
al.
S
our
ce:ht
tp:
//www.
gt
kmm.
org
/en/
Ub
unt
u:a
pt-
get
ins
tal
lgt
kmm-
2.
4

1
31
E.
2.3Li
bgl
ade
mm
C++l
i
bra
ryt
olo
adg
ladei
nte
rfa
ce
S
our
ce:ht
tp:
//www.
gt
kmm.
org
/en/
Ub
unt
u:a
pt-
get
ins
tal
ll
ib
gla
demm-
2.
4

E.
2.4Boos
t
Re
gul
arEx
pre
ssi
onsi
nC++wi
thBoos
t.
Reg
ex
Boos
t.
Rege
xal
l
owst
odoe
ver
ythi
ngf
rom s
impl
ema
tchi
ng(
val
i
dat
ingaphonenu
mbe
r,f
ore
xampl
e)t
ose
arc
hand
re
pla
ce.
S
our
ce:ht
tp:
//www.
boos
t.
org
/
Ub
unt
u:a
pt-
get
ins
tal
ll
ib
boos
t.
*-
devl
i
bboos
t-
docl
i
bboos
t.
*1.
34.
14

1
32
Appe
ndi
xF

I
nst
all
ati
on

F.
1 Sour
ceAv
ail
abi
li
ty
Thel
at
ests
oft
war
esou
rcec
odec
anb
edownl
oade
dfr
om
ht
tp:
//c
ode
.goog
le.
com/
p/mi
cp-
si
m/downl
oads
/li
st

Fi
l
eve
rsi
onnot
ati
on:
micp.releaseDDMMYY.tar,
whe
reDDMMYYr
epr
ese
ntst
heda
teof
rel
eas
e.
S
our
cec
odei
sal
soa
vai
l
abl
eont
hes
uppl
i
edCDa
spa
rtof
proj
ectr
epor
t.

F.
2 Compi
la
tion
S
our
cec
odei
sdi
st
ri
but
edi
nasat
arp
ack
age
.Thec
omma
ndt
ounz
ipt
hef
il
e:
tar xvf micp.releaseDDMMYY.tar

Thec
ompi
l
erc
omma
ndsa
res
tor
edi
nma
kef
il
esdi
st
ri
but
eda
sapa
rtof
sou
rcec
ode
.Ent
ert
hes
imu
lat
ordi
rec
tor
yand
t
ypei
n:
marek@localhost:/home/marek/micp# make

Thema
kec
omma
nds
hou
ldb
eex
ecu
tedwi
thr
oot
'
sri
ght
s.

I
fther
equ
ire
dli
bra
ri
esa
renot
ava
il
abl
etheo
utpu
tpr
odu
cedb
yma
kef
il
eis

1
33
Appe
ndi
xG

CD Cont
ent
s

C.
1 Pr
oje
ctRe
por
t
Theproj
ectr
epor
tca
nb efou
ndi
nthepr
oje
ctf
olde
r.S
imCi
rJa
vas
imu
lat
orc
anb
eisi
nthef
olde
rsi
mci
rtog
ethe
rwi
th
t
hecir
cui
tsuse
dinChapte
r2.

C.
2 mi
cp-
sim
Thes
our
cec
odet
arb
all
canb
efou
ndi
nfol
dermi
ps-
si
m.

C.
3 As
sembl
ySc
ript
s
Sa
mpleass
emb
lyscr
ipt
scanareloc
ate
dinex
ampl
esf
olde
r.Pos
si
bl
esol
uti
onst
othet
woe
xer
ci
sesa
tthee
ndof
Chapt
er5c
anbef
oundins
olu
tionsf
ol
der.

1
34
Re
fer
enc
es
S
tok
es,
J.(
200
7)I
nsi
det
heMa
chi
ne.
SanFr
anc
isc
o:NoS
tar
chPr
ess
Je
on,J.
W. (2
000
)`AMi c
ropr
oce
ssorCours
e:Desi
gni
nga
ndI
mpl
eme
nti
ngPe
rsona
lMi
cr
ocompu
ter
s`I
,EEE
Tran
sact
io
nsone
duc
ati
on,v
ol.
43,No.4,p.
426,4
2
th
Ba
nks
,J.
,Ne
lson,
B.L.
,Ni
col
,D.
M.(
200
9)Di
sc
ret
e-
Eve
nts
yst
emS
imu
lat
io
n.5 ed.
,Ne
wJe
rse
y:Pr
ent
ic
eHa
ll
S
okol
ows
ki,
J.A.
andBa
nks
,C.
M.(
200
9)Pr
inc
ipl
eso
fmo
del
i
nga
nds
imu
lat
io
n.Ne
wJe
rse
y:J
ohnWi
l
eya
ndS
ons
Mc
Hane
y,R.
(19
91)Co
mpu
ters
imu
lat
io
n:ap
rac
ti
cal
per
spe
ct
iv
e.S
anDi
ego:
Aca
demi
cPr
ess
Edwar
ds,
D.(19
99)`
Useof
Simu
lat
ori
nTe
achi
ngI
ntr
odu
ctor
yCompu
terEng
ine
eri
ng.̀I
nt.
J.En
gngEd
.Vol
.15
,
No.5pp.
353
-357
Xi
li
nx,(
2010
)Ge t
ti
ngS
tart
edwihFPGAs–FPGAv
t s.ASI
C[ Onl
i
ne][Ac
ces
sedon1De
cemb
er2
010
]
ht
tp:
//www.
xil
i
nx.
com/compa
ny/ge
tti
ngs
tar
ted/
fpg
avsa
sic
.ht
m#pcs
Wik
iboo
ks,(
2010)Mic
rop
roce
ss
orDe
si
g n–Wi
kib
ook
s,c
olle
ct
iono
fop
en-
cont
ent
tex
tbo
oks
.[Onl
i
ne][
Acc
ess
edon1
7
Nove
mb e
r2010
]http:
//e
n.wi
kib
ook
s.org
/wi
ki
/Mic
roproces
sor
_Des
ign
Pa
lni
tk
ar,
S.(
200
3)Ve
ri
lo
gHDL:
agu
idet
odi
gi
ta
lde
si
gna
nds
ynt
hes
is
.Vol
ume1
.Pa
loAl
to:
Pre
nti
ceHa
llPTR
Kasi
m,M.,Al
-Aubi
dy,M.(2
007)`TeachingComputerOrgani
sat
ionandArchit
ect
ureUsi
ngSimul
at
ionandFPGA
Appl
ica
ti
ons`
,Jou
rnalof
Compute
rSci
ence3,p.62
4-6
32[ Onli
ne][Acces
sedon1De cember2
010]Avai
la
blef
rom:
ht
tp:
//ci
te
seer
x.
ist
.ps
u.e
du/v
iewdoc
/downl oa
d?doi
=10.1.
1.
1 1
0.7
2 88
&rep=rep1&type
=pdf
Chuda,
D.,Ne hez
,M.,Cer
nansky.
,M.(2009
)`OnUs ingofRandomAcces
sMa chi
neSimul
ator
sinTeachi
ngof
Theor
eti
calCompu t
erSc
ience`
,Int
er
nati
onal
Confe
renceonComput
erSy
ste
msan dTec
hnol
ogi
es–CompSysTe
ch`
09,
p.
IV.
14-
1–I V.1
4 -
6[Onli
ne][Acces
sedon1De c
emb e
r2 01
0 ]Ava
il
abl
efr
om:http:/
/port
al
.a
cm.org/
cit
ati
on.
cf
m?
i
d=1731830&dl=ACM&c oll
=DL&CFI D=113338
664&CFTOKEN=9 072500
3
IEEEComputerSoci
etyandACM (
2004
),`Cu
rri
cul
umGu i
del
ine
sforUnder
gra
dua
teDegr
eeProgra
msi
nCompu
ter
Engi
neer
ing
`[Online][Acce
sse
don5Dece
mber]Ava
il
abl
efr
om:http:
//www.e
ng.
aub
urn.
edu
/e c
e/CCCE/
CCCE-
Fina
lRe
port
-20
0 4
De c12.
pdf
Cl
eme
nts
,A.
(20
00)
,`TheUnde
rgr
adu
ateCu
rri
cul
umi
nCompu
terAr
chi
te
ctu
re`
,IEEEMi
cr
o,v
ol.
20,
no.
3,pp.
13-
22
Mera
tF.,L.andChung
,D.(1
997)`Wor
ldWideWebAppr
oac
htoTe
achMi
cr
opr
oce
ssor
s`De
, p
t.o
fEl
ec
tr
.En
g.&
Ap
ppl.Ph
y s
.,
v ol
.2,
pp.
838
-841.
Pit
ts
bur
gh,PA,US
A
Mart
in-
Del-
Bri
o,B.
,Ber
nal
-Ru
iz,
C.(19
9 9
)`Asof
twar
etool
fort
eac
hingmi
cr
ocont
rol
l
ers
yst
empr
ic
ipl
es I
`,nt
.J.
El
ec
t.Eng
ing
.Educ
,vol
.36,
pp.
279-2
86.Manc
hest
erU.
P.
Fe
rensK.
,Fri
ese
n,M.andIng
ram,
S.(20
07)`I
mpactAss
ess
mentofaMicr
oproc
ess
orAni
ma t
iononS
tude
nt
Le
arni
ngandMotiv
ati
oninComput
erEngi
nee
ri
ng`
, I
EEETran
sact
iono
nEd u
cat
ion
,vol
.50
,no.2
Motor
ola(19
99)`M68HC11Ref
ere
nceManu
al̀[
Onl
ine][
Acce
sse
don5De
cemb
er2
010
]Av
ail
abl
efr
om:
ht
tp:
//handy
boar
d.c
om/ol
dhb/
tec
hdocs
/mot
o-68
11-
tec
hre
f.
pdf
Dj
ordj
evi
c,J.
,Nik
oli
c,B.
andMile
nkov
ic,
A.(20
05)`Fl
exi
bl
eWe b-
Bas
edEduc
ati
onS
yst
emf
orTe
achi
ngCompu
ter
Ar
chit
ect
ureandOrga
nis
ati
on`
,IEEETra
nsa
cti
ononEd
ucati
on,
vol
.48
,no.
2
Wi
ki
pedi
a(2
011
a)`
Proc
ess
orRe
gis
ter–Wi
ki
pedi
athef
reee
ncy
clope
dia
`[Onl
i
ne][
Acc
ess
edon1
4De
cemb
er

1
35
2
010
]Av
ail
abl
efr
om:ht
tp:
//e
n.wi
ki
ped
ia.
org
/wi
ki
/Pr
oce
ssor
_re
gis
ter
Ma
no,
M.M.
(19
82)Compu
terS
yst
emAr
chi
te
ctu
re.
Sec
ondEdi
ti
on.
NewJ
ers
ey:
Pre
nti
ce-
Hal
l
Wiki
pedi
a(2011
c)`MOSTe c
hnolog
y6502–Wiki
ped
iat
hef
reeenc
ycl
ope
dia`[
Onl
i
ne][
Acc
ess
edon5J
anu
ary
20
11]Avai
la
blefr
om:ht
tp:
//en.
wiki
ped
ia.
org
/wi
ki
/MOS_Technol
ogy
_6502
Wiki
pedi
a(2011
d)`Random-ac
ces
smemory–Wik
ipe
diathef
reeencyc
lope
dia
`[Onl
i
ne][
Acc
ess
edon8J
anu
ary
20
11]Avai
la
blefr
om:htt
p://
en.wi
ki
ped
ia.
org
/wi
ki
/MOS _Technolo
gy_6502
Wiki
pedi
a(2011
e)`Compil
er–Wik
ipe
diat
hef
reee
ncy
clope
dia
`[Onl
i
ne][
Acc
ess
edon2
0Ja
nua
ry2
011
]Av
ail
abl
e
f
rom:htt
p:/
/en.
wik
ipe
dia
.or
g/wi
ki
/Compil
er
CPUWorld(2
011
)`MOSTe chnol
ogy650
2mi c
roproc
essorf
ami
l
y`[Onl
ine
][Ac
ces
sedon5J
anu
ary2
011
]
Ava
il
abl
efr
om:ht
tp:
//e
n.wi
ki
pe di
a.
org
/wik
i/Random-a
ccess
_memory
Fol
tyn(2
007
)`Fol
tynPre
sent
ati
on–Micr
oproc
ess
or6
502
`[Onl
i
ne][
Acc
ess
edon4J
anu
ary2
011
]Av
ail
abl
efr
om:
htt
p:/
/www.
eri
ch-
fol
ty
n.e
u/Techni
que
/6502
.ht
ml
Ar
a s
e,K.
(20
10)`Si
mcir–J
avaLogi
cCi
rc
uit
simu
lat
or`[
Onl
i
ne][
Acc
ess
edon2
7De
cemb
er2
010
]Av
ail
abl
efr
om:
ht
tp:/
/www.
d-pr
oje
ct.
com/
simci
r/
Ma
ini
,A.
K.(
200
7)Di
gi
ta
lEl
ec
tr
oni
cs
:Pr
inc
ipl
es
,De
vic
esa
ndAp
pli
cat
io
ns.
Cippe
nha
m:J
ohnWi
l
ey&S
ons
Gods
e,D.
A. &Gods
eA. P.(
2 00)Mi
8 cr
opr
oces
sorTe
chni
que
s:808
5an
d8 08
6Ar
chi
te
ct
ure
,In
str
uct
io
nSe
t,
th
Pr
ogr
amming&In
ter
fac
ing.
4 Edi
tion.
Pune:Techni
cal
Publ
ica
ti
onPune
He
rri
ck,
C.N.
(19
97)Ba
sicEl
ec
tr
oni
cMa
th.
Newt
on:
Els
evi
er
Ba
rbor
ia
k,A.(
2004)Mini
mal
i
sat
ionb
yus
ingKa
rna
ughMa
p.Ex
erc
iseb
ook
.Re
vuc
a:S
econda
ryVoc
ati
ona
lSc
hool
.
Modul
e“El
ect
roni
cs”
El
-Rewi
ni,
H.&Abd-
El-
Bar
r,M.
(20
05)Ad
van
cedCo
mpu
terAr
chi
te
ct
urea
ndPa
ral
l
elPr
oce
ss
ing
,Vo
lume2
.Ne
w
Je
rse
y:J
ohnWil
ey&Sons
Ve
nka
ta,
K.Re
t.a
l(2
01)Pu
0 lseDi
gi
ta
lCi
rc
uit
s.Noi
da:
Dor
li
ngKi
nde
rsl
ey
CDC421xxx
,TexasIns
tr
uments(20
07 )`Ful
lyInt
egra
tedFixe
dFre
que
ncyl
ow-
ji
tt
er,
Cry
sta
l-
Osc
il
la
torCl
ock
Gene
rat
or`[Onli
ne][Acc
ess
edon5J anuar
y2 011]Avai
la
blefr
om:
ht
tp:
//f
ocus.
ti
.
com/ l
it
/ds
/sy
ml i
nk/cdc4
2 1
10 0
.pdf
Le
surf
,J.
(20
00)`Buf
fe
rsandCur
rentAmpl
i
fi
ers
`[Onl
ine
][Acces
sedon7Janua
ry2
011
]Av
ail
abl
efr
om:
ht
tp:
//www.
st-
andr
ews.
ac.
uk/
~www_pa/Sc
ots
_Guide
/audi
o/pa
rt1/
page
2.html
Coope
rK.
,D.
&Tor
czonL.
(20
04En
) g
ine
eri
ngac
omp
il
er
.Sa
nFr
anc
isc
o:Mor
anKa
ufma
nnPu
bli
she
rs
S
nav
ely
,A.
(2004
)`Ins
tr
ucti
onSetArc
hit
ect
ureor“
Howtotal
ktocomput
ersi
fyoua
ren'
ti
nSta
rTr
ek”
.[Onl
i
ne]
[
Acc
ess
ed26J
anuar
y2011]Ava
il
ablef
rom:ht
tp:
//www.
sds
c.
edu/~al
la
ns/
cs141/
L2.
ISA.
pdf
MS 5(20
10)
,` Micr
oproces
sorSimula
torf
orStudent
s`[Onli
ne][Ac
ces
sedon4Janua
ry20
11]Avai
l
abl
efr
om:
ht
tp:/
/www.soft
waref
oreducat
ion.
com/sms32v50/
OneStopTesti
ng(2011)`It
erati
veModel̀.
[Onli
ne][Acces
sedon26Decembe
r2 0
10]Avai
l
abl
efr
om:
ht
tp:/
/www.onest
optest
ing.
com/ s
dlc
-models
/it
erat
iv
e-model
.as
p
Lewa
ll
en,R.(20
05)`Sof
twar
eDe v
elopment
li
fec
ycl
emode
ls`[Onli
ne][Ac
cess
edon26Decembe
r2010]Av
ail
abl
e
f
rom:ht
tp:/
/codeb
ett
er.
com/ra
ymondlewal
le
n/20
05/0
7/1
3/ s
oft
ware-
deve
lopment
-l
if
e-
cyc
le-
model
s/
TheGTK+Te a
m( 2
008)`GTK+-About
`.[
Online][
Ac c
ess
edon20J
anua
ry201
1]Avail
abl
efr
om:
ht
tp:
//www.
gtk.
org/
GTKmm( 201
1)`Fe at
ure
s–gtk
mm–C++i nte
rfac
esforGTK+andGnome`[
Acces
sedon20Janu
ary2
011
]
Avai
l
abl
efr
om:http:/
/www.gt
kmm.or
g/e
n/
TheGla
deProj
ect
(2 00
9)`Gl
ade–AUs
erI
nte
rfa
ceDe
sig
ner
`[Onl
i
ne][
Acc
ess
edon2
1Ja
nua
ry2
011
]Av
ail
abl
e
f
rom:ht
tp:
//gl
ade
.gnome.
org
/

1
36
Br
aga,
P.(2
0 0
7)`TheUnixGeed:
GTKvsQT`[Onli
ne][Ac
ces
sedon2
3Ja
nua
ry2
011
]Av
ail
abl
efr
om:
ht
tp:
//t
heuni
xge
ek.
blog
spot
.c
om/200
7/1
0/gt
k-v
s-qt
.ht
ml
Bl
ais
e,B.(
201
1)`POSIXThre
adsProg
r a
mming`[
Onl
i
ne][
Acc
ess
edon5Oc
tob
er2
010
]Av
ail
abl
efr
om:
ht
tps
://c
omputi
ng.
l
lnl
.
gov/
tut
ori
als
/pthre
ads
/
Ippol
ito,
G.(
2011)`POSI
Xthr
ead(
pthr
ead)li
bra
rie
s`[Onl
ine][
Acces
sedon5Oc
tob
er2
010
]Av
ail
abl
efr
om:
http:
//www.
yol
i
nu x
.com/
TUTORIALS/Linu
xTutori
al
Posi
xThre
ads
.ht
ml
j
Guru(
2010)`Wha
tdo“s
ynta
x”and“s
emant
ic
s”meana
ndh owa r
etheydi
ff
ere
nt?
`[Onl
i
ne][
Acc
ess
edon3
0
Dec
ember2
0 1
0]Ava
il
abl
efr
om:htt
p:/
/www.j
gur
u.c
om/fa
q/ v
iew.j
sp?
EID=81
Ba
rney,
B.(2
010)`POSIXThrea
dsProgra
mming.̀[
Onl
i
ne][
Acc
ess
edon1
8Nov
emb
er2
010
]
ht
tps
://
comput
ing
.ll
nl
.g
ov/t
utor
ial
s/pt
hrea
ds/
TheEECompe
ndium(2010)`805
1Compendi
um–TheEECompe
ndi
um`[
Onl
i
ne][
Acc
ess
edon3J
anu
ary2
011
]
Ava
il
abl
efr
om:ht
tp:
//e
e.c
leve
rsoul
.c
om/
8051.
html
MSCMa nua
l(1
994)`MCS51Mic
rocont
rol
lerFami
lyUse
r'
sMa nu
al̀[
Onl
i
ne][
Acc
ess
edon3J
anu
ary2
011
]
Av
ail
abl
efr
om:htt
p:/
/www.
805
1proj
ects
.ne
t/downl
oads
215.
html
Wi
kipedia(20
11 a
)`Int
elMCS -
51–Wikipe
diathefr
eee
ncycl
ope
dia
`[Onl
i
ne][
Acc
ess
edon3J
anu
ary2
011
]
Av
ail
ablefr
om: ht
tp:
//en.
wik
ipedi
a.
org
/wiki
/Inte
l_MCS-5
1

1
37

You might also like