Você está na página 1de 36

SystemProgrammingwith

System
Programming with
AssemblyLanguage:PartI
y
g g
FirstSemester2013
DepartmentofComputerScience
FacultyofScience
ChiangMaiUniversity

Outline
TheComponentsofaMicrocomputerSystem
Instruction Cycle
InstructionCycle
ProgrammingLanguages
HowIntegersAreRepresentedinthe
p
Computer
CharacterRepresentation

204231:ComputerOrganizationandArchitecture

Bytes and Words


BytesandWords
Informationprocessedbythecomputeris
f
i
db h
i
storedinitsmemory.
Thememorycircuitsareusuallyorganizedinto
g p
groupsthatcanstoreeightbitsofdata.
g
Astringofeightbitsiscalledabyte.
Eachmemorybyteisidentifiedbyanumber
Each memory byte is identified by a number
thatiscalledaddress.
Thedatastoredinamemorybytearecalled
itscontents.
204231:ComputerOrganizationand
Architecture

Bytes and Words


BytesandWords
Theaddressofamemorybyteisfixedandis
y
differentfromtheaddressofanyother
memorybyteinthecomputer.
Thecontentsofamemorybytearenotunique
The contents of a memory byte are not unique
andaresubjecttochange,becausethey
d
denotethedatacurrently
t th d t
tl beingstored.
b i
t d

204231:ComputerOrganizationand
Architecture

Memory Represented as Bytes


MemoryRepresentedasBytes

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

Bit Positions in a Byte and a Word


BitPositionsinaByteandaWord

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

Bus Connections of a Microcomputer


BusConnectionsofaMicrocomputer

204231:ComputerOrganizationandArchitecture

10

Intel 8086 Microprocessor Organization


Intel8086MicroprocessorOrganization

204231:ComputerOrganizationandArchitecture

11

Execution Unit (EU)


ExecutionUnit(EU)
ThepurposeoftheEUistoexecute
instructions.
Thearithmeticandlogicunit(ALU)can
perform arithmetic (+ x /) and logic (AND
performarithmetic(+,,x,/)andlogic(AND,
OR,NOT)operations.
Thedatafortheoperationsarestoredin
circuits called registers.
circuitscalledregisters.

204231:ComputerOrganizationandArchitecture

12

Bus Interface Unit (BIU)


BusInterfaceUnit(BIU)
TheBIUfacilitatescommunicationbetween
y
theEUandthememoryorI/Ocircuits.
TheBIUisresponsiblefortransmitting
addresses data and control signals on the
addresses,data,andcontrolsignalsonthe
buses.
Theinstructionpointer(IP) containsthe
address of the next instruction to be executed
addressofthenextinstructiontobeexecuted
bytheEU.
204231:ComputerOrganizationandArchitecture

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

Find the twosscomplementof5.


Findthetwo
complement of 5
5=0000000000000101
One
Onesscom.of5
com. of 5 =1111111111111010
1111 1111 1111 1010
Twoscom.of5=1111111111111011

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

Unsigned Decimal Interpretation


UnsignedDecimalInterpretation
Justdoabinarytodecimalconversion.
It
Itssusuallyeasiertoconvertbinarytohexfirst,
usually easier to convert binary to hex first,
andthenconverthextodecimal.

204231:ComputerOrganizationandArchitecture

31

Signed Decimal Interpretation


SignedDecimalInterpretation
Ifthemsb is0,thenumberispositive,andthe
g
g
signeddecimalisthesameastheunsigned
decimal.
Ifthemsb
If the msb is1,thenumberisnegative,socall
is 1 the number is negative so call
itN.
TofindN,justtakethetwoscomplementand
thenconverttodecimalasbefore.

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

Você também pode gostar