01a Basic Concepts - iet.unipi.it
Transcript of 01a Basic Concepts - iet.unipi.it
EmbeddedSystemBlockDiagram
EmbeddedSystem
Processor
Device/Equipmenttobecontrolled
Memory
Peripherals
EmbeddedComputer
Actuator
Actuator
Indicator
DRIVER
SENSO
RCO
NDITIONING
Sensor
Sensor
Sensor
OutputInput
InstructionsandPrograms
• Aninstruction specifiesanoperationandthelocationsofitsdataoperands
• A32-bitwordtypicallyholdsoneencodedinstruction
• Asequenceofinstructions,executedoneafteranother,constitutesaprogram
• Bothaprogramanditsdata arestoredin themainmemory
Instructiontypes
• Fourbasicinstructiontypes:– Load: Readadataoperandfrommemoryoraninputdeviceintotheprocessor
– Store: Writeadataoperandfromaprocessorregistertomemoryoranoutputdevice
– Operate: Performanarithmeticorlogicoperationondataoperandsinprocessorregisters
– Branch: Alter,ifaconditionisverified,thesequentialexecutionoftheinstructions
ProgramExample• A,B,andC,arelabels representingmemorywordaddresses;Ri areprocessorregisters
• Aprogram forthecalculationC=A+B
is:
Load R2,ALoad R3,BAdd R4,R2,R3Store R4,C
MainProcessorElements(1)
• Theprogram counter (PC)registerholdsthememoryaddressofthecurrentinstruction
• Theinstruction register (IR)holdsthecurrentinstruction
• General-purpose registers holddataandaddresses
• Control circuits andthearithmeticandlogicunit(ALU)fetchandexecuteinstructions
Fetchingandexecutinginstructions
Example: Load R2,LOC
Theprocessorcontrolcircuitsdothefollowing:
• SendaddressinPCtomemory;issueRead• LoadinstructionfrommemoryintoIR• IncrementPCtopointtonextinstruction• SendaddressLOCtomemory;issueRead• LoadwordfrommemoryintoregisterR2
RepresentationofInformation• Whateveristhesourceofinformation,dataarerepresentedbyastringofbits(usuallyinanumbermultipleof8,i.e.,1BYTE)
• AnarrayofbitsdirectlyrepresentsaNaturalnumberinbase2 (positionalbinarynotation)– B=bn-1…b1b0 representsthenumberV(B)=bn-1x2n-1 +... b1x21+b0x20
• AnyotherinformationcanbeencodedbyaNaturalusingaspecificrepresentation– E.g.signednumbers,floatingpointnumbers,chars,…
– Representationstypicallyuse1,2,4,8BYTES
SignedNumbers(1)
Forsignedintegers,theleftmostbit(MSB)containsthesigninformation:0 forpositive1 fornegative
Therearethreewaystorepresentsignedintegers:
• Signandmagnitude• 1’scomplement• 2’scomplement(theMSBhasweight-2n-1)
SignedNumbers(3)2’s-complementrepresentationisusedincurrentcomputers
Considerafour-bitsignedintegerexample,wherethevalue+5isrepresentedas:0101
Toformthevalue-5,complementallbitsof0101 toobtain 1010andthenadd1toobtain1011
SignedNumbers(4)
Replicatethesignbittoextend4-bitsignedintegersto8-bitsignedintegers
0101 00000101
1110 11111110
CharacterEncoding• AmericanStandardCodeforInformationInterchange(ASCII)
• Uses7-bitcodes(extendedversion1BYTE)• Someexamples:
characterbinarycode(decimal,0xhexadecimal)A 100 0001 (65,0x41)a 110 0001 (97,0x61)0 011 0000(48, 0x30)1 011 0001(49,0x31)9 0111001(57,0x39)
MemoryOrganization
• Memoryconsistsofmanymillionsofcells– Eachcellholdsabitofinformation,0or1
• Informationisusuallyhandledinlargerunits:bytesorwords
• Aword isagroupofn bytes• Wordlengthcanbe16,32or64bits• Memory canbeseenaseitheracollectionofconsecutivebytesorwords(ofthesizespecifiedbythewordlength)
WordandByteEncoding
• Acommonwordlengthis32bits• Suchawordcanstorea32-bitsignedintegerorfour8-bitbytes(e.g.,ASCIIcharacters)
• Wordsinmemorymaystoredataormachineinstructionsforaprogram
• Eachmachineinstructionmayrequireone(ormoreconsecutivewordsforencoding)
AddressesforMemoryLocation
• Tostoreorretrieveitemsofinformation,eachmemorylocationhasadistinctaddress
• Numbers0to2k - 1areusedasaddressesforsuccessivelocationsinthememory
• The2k locationsconstitutetheaddressspace• Memorysizesetbyk (numberofaddressbits)• Examples: k = 20 ® 220 or1Mlocations,
k = 32 ® 232 or4Glocations
ByteAddressability
• Bytesizeisalways8bits• Butwordlengthmayrangefrom16to64bits• Abyte-addressable memoryassignsanaddresstoeachbyte
• Bytelocationshaveaddresses0,1,2,…• Assumingthatthewordlengthis32bits,wordlocationshaveaddresses0,4,8,…
Big- Little-Endianess
• Twowaystoassignbyteaddressacrosswords• Big-endian addressingassignsloweraddressestomoresignificant(leftmost)bytesofword
• Little-endian addressingusesoppositeorder• Commercialcomputersuseeitherapproach,andsomecansupportbothapproaches
• Addressesfor32-bitwordsarestill0,4,8,…• Bitsineachbytelabeledb7 …b0,lefttoright