Documente Academic
Documente Profesional
Documente Cultură
System
Programming with
AssemblyLanguage:PartI
y
g g
FirstSemester2013
DepartmentofComputerScience
FacultyofScience
ChiangMaiUniversity
Outline
TheComponentsofaMicrocomputerSystem
Instruction Cycle
InstructionCycle
ProgrammingLanguages
HowIntegersAreRepresentedinthe
p
Computer
CharacterRepresentation
204231:ComputerOrganizationandArchitecture
204231:ComputerOrganizationand
Architecture
204231:ComputerOrganizationandArchitecture
Bit Position
BitPosition
Thepositionsarenumberedfromrighttoleft,
g
startingwith0.
Inaword,thebits0to7formthelowbyte
and the bits 8 to 15 form the high byte
andthebits8to15formthehighbyte.
Forawordstoredinmemory,itslowbyte
comesfromthememorybytewiththelower
address and its high byte is from the memory
addressanditshighbyteisfromthememory
bytewiththehigheraddress.
204231:ComputerOrganizationand
Architecture
204231:ComputerOrganizationandArchitecture
Buses
Aprocessorcommunicateswithmemoryand
y
g g
g
I/Ocircuitsbyusingsignalsthattravelalonga
setofwiresorconnectionscalledbuses.
Therearethreekindsofsignals:address,data,
There are three kinds of signals: address data
andcontrol.
Andtherearethreebuses:addressbus,data
bus, and control bus.
bus,andcontrolbus.
204231:ComputerOrganizationand
Architecture
Buses
Forexample,toreadthecontentsofa
l
d h
f
memorylocation,theCPUplacestheaddress
ofthememorylocationontheaddressbus,
anditreceivesthedata,sentbythememory
circuits,onthedatabus.
Acontrolsignalisrequiredtoinformthe
g
q
memorytoperformareadoperation.
TheCPUsendsthecontrolsignalonthe
The CPU sends the control signal on the
controlbus.
204231:ComputerOrganizationand
Architecture
204231:ComputerOrganizationandArchitecture
10
204231:ComputerOrganizationandArchitecture
11
204231:ComputerOrganizationandArchitecture
12
13
Instruction Prefetch
InstructionPrefetch
WhiletheEUisexecutinganinstruction,the
p
y
BIUfetchesuptosixbytesofthenext
instructionandplacesthemintheinstruction
queue.
204231:ComputerOrganizationandArchitecture
14
Machine Instruction
MachineInstruction
TheOpcode specifiesthetypeofoperation.
TheOperands
The Operands areoftengivenasmemory
are often given as memory
addressestothedatatobeoperatedon.
204231:ComputerOrganizationandArchitecture
15
FetchExecute Cycle
FetchExecuteCycle
Fetch
h
1. Fetchaninstructionfrommemory.
y
2. Decodetheinstructiontodeterminethe
operation.
operation
3. Fetchdatafrommemoryifnecessary.
Execute
4. Performtheoperationonthedata.
p
5. Storetheresultinmemoryifneeded.
204231:ComputerOrganizationandArchitecture
16
Programming Languages
ProgrammingLanguages
Theoperationsofthecomputershardware
y
arecontrolledbyitssoftware.
Whenthecomputerison,itisalwaysinthe
process of executing instructions
processofexecutinginstructions.
204231:ComputerOrganizationand
Architecture
17
Machine Language
MachineLanguage
TheCPUcanonlyexecutemachinelanguage
instructions.
Theyarebitstrings.
204231:ComputerOrganizationand
Architecture
18
Machine Language
MachineLanguage
MachineInstruction
Operation
101000010000000000000000 Fetchthecontentsof
memoryword0and
put it in register AX
putitinregisterAX.
000001010000010000000000 Add4toAX.
101000110000000000000000 Storethecontentsof
y
AXinmemoryword0.
204231:ComputerOrganizationandArchitecture
19
Assembly Language
AssemblyLanguage
Amoreconvenientlanguagetouseis
y g g
assemblylanguage.
Inassemblylanguage,weusesymbolic names
to represent operations registers and
torepresentoperations,registers,and
memorylocations.
Iflocation0issymbolizedbyA,thepreceding
program expressed in IBM PC assembly
programexpressedinIBMPCassembly
languagewouldlooklikethis:
204231:ComputerOrganizationand
Architecture
20
Assembly Language
AssemblyLanguage
AssemblyInstruction Comment
MOVAX,A
,
ADDAX,4
MOVA,AX
;
;fetchthecontentsof
;locationAandputitin
; register AX
;registerAX
;add4toAX
;movethecontentsofAX
;
;intolocationA
204231:ComputerOrganizationandArchitecture
21
HowIntegersAreRepresented
intheComputer
Theleastsignificantbit(lsb)istherightmostbit.
Inabyteorword,bit0
y
,
Themostsignificantbit(msb) istheleftmostbit.
Inaword,bit15
In a word bit 15
Inabyte,bit7
204231:ComputerOrganizationandArchitecture
22
Unsigned Integers
UnsignedIntegers
Anunsignedintegerrepresentsamagnitude.
Unsignedintegersareappropriatefor
Unsigned integers are appropriate for
representingquantitiesthatcanneverbe
negative.
negative
Addressesofmemorylocations
Counters
ASCIICode
204231:ComputerOrganizationandArchitecture
23
Unsigned Integers
UnsignedIntegers
Thelargestunsignedthatcanbestoredina
y
=255.
byteis11111111=FFh
Thebiggestunsignedintegera16bitword
can hold is 1111 1111 1111 1111 = FFFFh
canholdis1111111111111111=FFFFh
=65535.
Notethatiftheleastsignificantbitofan
integer is 1, the number is odd, and itssevenif
integeris1,thenumberisodd,andit
even if
thelsb is0.
204231:ComputerOrganizationand
Architecture
24
Signed Integers
SignedIntegers
Asignedintegercanbepositiveornegative.
Themsb
The msb isreservedforthesign:
is reserved for the sign:
1meansnegative.
0meanspositive.
0
ii
Negativeintegersarestoredinthecomputer
g
g
p
inaspecialwayknownastwoscomplement.
204231:ComputerOrganizationandArchitecture
25
Twosscomplement
Two
complement
Theonescomplementofanintegeris
y
p
g
obtainedbycomplementingeachbit;thatis,
replaceeach0bya1andeach1bya0.
Togetthetwo
To get the twosscomplementofaninteger,
complement of an integer
justadd1toitsonescomplement.
204231:ComputerOrganizationandArchitecture
26
204231:ComputerOrganizationandArchitecture
27
SubtractionasTwosComplement
Addition
Asubtractioncanbedonebybit
p
complementationandaddition.
Thecircuitsthataddandcomplementbitsare
easy to design
easytodesign.
204231:ComputerOrganizationand
Architecture
28
SubtractionasTwosComplement
Addition
Ex.:SupposeAXcontains5ABChandBXcontains
S
i
Ch d
i
21FCh.FindthedifferenceofAXminusBXbyusing
complementationandaddition.
l
t ti
d dditi
Solution:5ABCh=0101101010111100
+1scom.of21FCh=1101111000000011
+1
1
Difference=1 0011100011000000
= 38C0h
=38C0h
Notethat21FCh=0010000111111100
204231:ComputerOrganizationand
Architecture
29
SubtractionasTwosComplement
Addition
Aoneiscarriedoutofthemostsignificantbit
andislost.
Theanswerstored,38C0h,iscorrect,asmay
be verified by hex subtraction
beverifiedbyhexsubtraction.
204231:ComputerOrganizationand
Architecture
30
204231:ComputerOrganizationandArchitecture
31
204231:ComputerOrganizationandArchitecture
32
SupposeAXcontainsFE0Ch.Givethe
unsignedandsigneddecimalinterpretations.
FE0Ch=1111111000001100
Fortheunsigneddecimalinterpretations
For the unsigned decimal interpretations
FE0Ch=65036
Forthesigneddecimalinterpretations
FE0Ch=N
Onescom.ofFE0Ch=0000000111110011
Twosscom.ofFE0Ch=0000000111110100
Two
com of FE0Ch = 0000 0001 1111 0100
N=01F4h=500
204231:ComputerOrganizationandArchitecture
33
ASCII Code
ASCIICode
AmericanStandardCodeforInformation
g
InterchangeCode
TheASCIICodesystemusessevenbitstocode
each character so there are a total of 27 =128
eachcharacter,sothereareatotalof2
= 128
ASCIIcodes.
Noticethatonly95ASCIIcodes,from32to
126,areconsideredtobeprintable.
,
p
204231:ComputerOrganizationandArchitecture
34
ShowhowthecharacterstringRG2zis
storedinmemory,startingataddress0.
Address
0
1
2
3
4
Contents
0101 0010
01010010
01000111
00100000
0011 0010
00110010
01111010
204231:ComputerOrganizationandArchitecture
35
Reference
Ytha YuandCharlesMarut,Assembly
g g
g
g
g
LanguageProgrammingandOrganizationof
theIBMPC.NewYork:McGrawHill,1992.
204231:ComputerOrganizationandArchitecture
36