GeneralPurpose Registers.docx

上传人:b****1 文档编号:19081530 上传时间:2023-04-24 格式:DOCX 页数:67 大小:306.42KB
下载 相关 举报
GeneralPurpose Registers.docx_第1页
第1页 / 共67页
GeneralPurpose Registers.docx_第2页
第2页 / 共67页
GeneralPurpose Registers.docx_第3页
第3页 / 共67页
GeneralPurpose Registers.docx_第4页
第4页 / 共67页
GeneralPurpose Registers.docx_第5页
第5页 / 共67页
点击查看更多>>
下载资源
资源描述

GeneralPurpose Registers.docx

《GeneralPurpose Registers.docx》由会员分享,可在线阅读,更多相关《GeneralPurpose Registers.docx(67页珍藏版)》请在冰豆网上搜索。

GeneralPurpose Registers.docx

GeneralPurposeRegisters

General-PurposeRegisters

3.4.1.General-PurposeRegisters

The32-bitgeneral-purposeregistersEAX,EBX,ECX,EDX,ESI,EDI,EBP,andESPareprovidedforholdingthefollowingitems:

•Operandsforlogicalandarithmeticoperations

•Operandsforaddresscalculations

•Memorypointers

Althoughalloftheseregistersareavailableforgeneralstorageofoperands,results,and

pointers,cautionshouldbeusedwhenreferencingtheESPregister.TheESPregisterholdsthe

stackpointerandasageneralruleshouldnotbeusedforanyotherpurpose.

Manyinstructionsassignspecificregisterstoholdoperands.Forexample,stringinstructions

usethecontentsoftheECX,ESI,andEDIregistersasoperands.Whenusingasegmented

memorymodel,someinstructionsassumethatpointersincertainregistersarerelativeto

specificsegments.Forinstance,someinstructionsassumethatapointerintheEBXregister

pointstoamemorylocationintheDSsegment.

 

Thespecialusesofgeneral-purposeregistersbyinstructionsaredescribedinSection5,

“InstructionSetSummary”inthisvolume;seealsoChapter3,InstructionSetReferenceA-M

andChapter4,InstructionSetReferenceN-ZoftheIA-32IntelArchitectureSoftwareDeveloper’s

Manual,Volumes2A&2B.Thefollowingisasummaryofspecialuses:

•EAX—Accumulatorforoperandsandresultsdata

•EBX—PointertodataintheDSsegment

•ECX—Counterforstringandloopoperations

•EDX—I/Opointer

•ESI—PointertodatainthesegmentpointedtobytheDSregister;sourcepointerforstringoperations

•EDI—Pointertodata(ordestination)inthesegmentpointedtobytheESregister;destinationpointerforstringoperations

•ESP—Stackpointer(intheSSsegment)

•EBP—Pointertodataonthestack(intheSSsegment)

 

3.4.2.SegmentRegisters

Thesegmentregisters(CS,DS,SS,ES,FS,andGS)hold16-bitsegmentselectors.Asegment

selectorisaspecialpointerthatidentifiesasegmentinmemory.Toaccessaparticularsegment

inmemory,thesegmentselectorforthatsegmentmustbepresentintheappropriatesegment

register.

Whenwritingapplicationcode,programmersgenerallycreatesegmentselectorswithassembler

directivesandsymbols.Theassemblerandothertoolsthencreatetheactualsegmentselector

valuesassociatedwiththesedirectivesandsymbols.Ifwritingsystemcode,programmersmay

needtocreatesegmentselectorsdirectly.Adetaileddescriptionofthesegment-selectordata

structureisgiveninChapter3,Protected-ModeMemoryManagement,oftheIA-32IntelArchitecture

SoftwareDeveloper’sManual,Volume3.

Howsegmentregistersareuseddependsonthetypeofmemorymanagementmodelthatthe

operatingsystemorexecutiveisusing.Whenusingtheflat(unsegmented)memorymodel,the

segmentregistersareloadedwithsegmentselectorsthatpointtooverlappingsegments,eachof

whichbeginsataddress0ofthelinearaddressspace(asshowninFigure3-5).Theseoverlapping

segmentsthencomprisethelinearaddressspacefortheprogram.Typically,twooverlapping

segmentsaredefined:

oneforcodeandanotherfordataandstacks.TheCSsegment

registerpointstothecodesegmentandalltheothersegmentregisterspointtothedataandstack

segment.

Whenusingthesegmentedmemorymodel,eachsegmentregisterisordinarilyloadedwitha

differentsegmentselectorsothateachsegmentregisterpointstoadifferentsegmentwithinthe

linearaddressspace(asshowninFigure3-6).Atanytime,aprogramcanthusaccessuptosix

segmentsinthelinearaddressspace.Toaccessasegmentnotpointedtobyoneofthesegment

registers,aprogrammustfirstloadthesegmentselectorforthesegmenttobeaccessedintoa

segmentregister.

Figure3-4.AlternateGeneral-PurposeRegisterNames

311615870

AHAL

BHBL

CHCL

DHDL

BP

SI

DI

SP

16-bit

AX

DX

CX

BX

32-bit

EAX

EBX

ECX

EDX

EBP

ESI

ESP

General-PurposeRegisters

EDI

 

 

 

Eachofthesegmentregistersisassociatedwithoneofthreetypesofstorage:

code,data,or

stack.Forexample,theCSregistercontainsthesegmentselectorforthecodesegment,where

theinstructionsbeingexecutedarestored.Theprocessorfetchesinstructionsfromthecode

segment,usingalogicaladdressthatconsistsofthesegmentselectorintheCSregisterandthe

contentsoftheEIPregister.TheEIPregistercontainstheoffsetwithinthecodesegmentofthe

nextinstructiontobeexecuted.TheCSregistercannotbeloadedexplicitlybyanapplication

program.Instead,itisloadedimplicitlybyinstructionsorinternalprocessoroperationsthat

changeprogramcontrol(suchas,procedurecalls,interrupthandling,ortaskswitching).

TheDS,ES,FS,andGSregisterspointtofourdatasegments.Theavailabilityoffourdata

segmentspermitsefficientandsecureaccesstodifferenttypesofdatastructures.Forexample,

fourseparatedatasegmentsmightbecreated:

oneforthedatastructuresofthecurrentmodule,

anotherforthedataexportedfromahigher-levelmodule,athirdforadynamicallycreateddata

structure,andafourthfordatasharedwithanotherprogram.Toaccessadditionaldatasegments,

theapplicationprogrammustloadsegmentselectorsforthesesegmentsintotheDS,ES,FS,and

GSregisters,asneeded.

TheSSregistercontainsthesegmentselectorforthestacksegment,wheretheprocedurestack

isstoredfortheprogram,task,orhandlercurrentlybeingexecuted.Allstackoperationsusethe

SSregistertofindthestacksegment.UnliketheCSregister,theSSregistercanbeloaded

explicitly,whichpermitsapplicationprogramstosetupmultiplestacksandswitchamongthem.

SeeSection3.3.,“MemoryOrganization”,foranoverviewofhowthesegmentregistersare

usedinreal-addressmode.

ThefoursegmentregistersCS,DS,SS,andESarethesameasthesegmentregistersfoundin

theIntel8086andIntel286processorsandtheFSandGSregisterswereintroducedintothe

IA-32ArchitecturewiththeIntel386™familyofprocessors.

 

3.4.3.EFLAGSRegister

The32-bitEFLAGSregistercontainsagroupofstatusflags,acontrolflag,andagroupofsystemflags.Figure3-7definestheflagswithinthisregister.Followinginitializationoftheprocessor(eitherbyassertingtheRESETpinortheINITpin),thestateoftheEFLAGSregisteris00000002H.Bits1,3,5,15,and22through31ofthisregisterarereserved.Softwareshouldnotuseordependonthestatesofanyofthesebits.SomeoftheflagsintheEFLAGSregistercanbemodifieddirectly,usingspecial-purposeinstructions(describedinthefollowingsections).Therearenoinstructionsthatallowthewholeregistertobeexaminedormodifieddirectly.ThefollowinginstructionscanbeusedtomovegroupsofflagstoandfromtheprocedurestackortheEAXregister:

LAHF,SAHF,PUSHF,PUSHFD,POPF,andPOPFD.AfterthecontentsoftheEFLAGSregisterhavebeentransferredtotheprocedurestackorEAXregister,theflagscanbeexaminedandmodifiedusingtheprocessor’sbitmanipulationinstructions(BT,BTS,BTR,andBTC).Whensuspendingatask(usingtheprocessor’smultitaskingfacilities),theprocessorautomatically

savesthestateoftheEFLAGSregisterinthetaskstatesegment(TSS)forthetaskbeingsuspended.Whenbindingitselftoanewtask,theprocessorloadstheEFLAGSregisterwithdatafromthenewtask’sTSS.Whenacallismadetoaninterruptorexceptionhandlerprocedure,theprocessorautomaticallysavesthestateoftheEFLAGSregistersontheprocedurestack.Whenaninterruptorexceptionishandledwithataskswitch,thestateoftheEFLAGSregisterissavedintheTSSforthetaskbeingsuspended.

 

AstheIA-32Architecturehasevolved,flagshavebeenaddedtotheEFLAGSregister,butthefunctionandplacementofexistingflagshaveremainedthesamefromonefamilyoftheIA-32processorstothenext.Asaresult,codethataccessesormodifiestheseflagsforonefamilyofIA-32processorsworksasexpectedwhenrunonlaterfamiliesofprocessors.

3.4.3.1.STATUSFLAGS

Thestatusflags(bits0,2,4,6,7,and11)oftheEFLAGSregisterindicatetheresultsofarithmetic

instructions,suchastheADD,SUB,MUL,andDIVinstructions.Thestatusflagfunctions

are:

CF(bit0)Carryflag.Setifanarithmeticoperationgeneratesacarryora

borrowoutofthemost-significantbitoftheresult;clearedotherwise.

Thisflagindicatesanoverflowconditionforunsigned-integerarithmetic.

Itisalsousedinmultiple-precisionarithmetic.

PF(bit2)Parityflag.Setiftheleast-significantbyteoftheresultcontainsan

evennumberof1bits;clearedotherwise.

 

AF(bit4)Adjustflag.Setifanarithmeticoperationgeneratesacarryora

borrowoutofbit3oftheresult;clearedotherwise.Thisflagisused

inbinary-codeddecimal(BCD)arithmetic.

ZF(bit6)Zeroflag.Setiftheresultiszero;clearedotherwise.

SF(bit7)Signflag.Setequaltothemost-significantbitoftheresult,whichis

thesignbitofasignedinteger.(0indicatesapositivevalueand1

indicatesanegativevalue.)

OF(bit11)Overflowflag.Setiftheintegerresultistoolargeapositivenumber

ortoosmallanegativenumber(excludingthesign-bit)tofitinthe

destinationoperand;clearedotherwise.Thisflagindicatesanoverflow

conditionforsigned-integer(two’scomplement)arithmetic.

Ofthesestatusflags,onlytheCFflagcanbemodifieddirectly,usingtheSTC,CLC,andCMC

instructions.Alsothebitinstructions(BT,BTS,BTR,andBTC)copyaspecifiedbitintotheCF

flag.

Thestatusflagsallowasinglearithmeticoperationtoproduceresultsforthreedifferentdata

types:

unsignedintegers,signedintegers,andBCDinteg

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 冶金矿山地质

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1