Download as pdf
Download as pdf
You are on page 1of 50
8y Niya Jackson ASSL Pro , ECE 8086 PROCESSORS RNSIT 6Sem Ec UNIT-4 > Historical background > Ieroprocesso/- based pessonal Computer system > 8086 CPU Archi tecture > Machine langage. instsuckions > Instruction exembion Liming A__Historical Backs roundl The #086 Hp includes 8086, 8088, 80186, 80086 , 80386 F 80486 MPS, pentium , pentium pro, pentium IL Pentium & The mechanical age = The. iclect 4 Computing and calculating cwith a machine dates fo 500 B¢ when the Babylonians invented the Abaws, the ixst mechanical Calculator - Gn 18Q3 the Royal Astronomical Sowety 4 Great Britian Commissroned Charles Babbage to produce a Proqvamma ble calculating machine. He cxeated an Analytical Engine ~ it 0 mechanical computer that Stored O thousand ao- Higit olecimal numbers and a Variable prograns that toulel modify the functor of the machine £0 Petforny Various caltealating easks- - In 1970's ,a Small handhelkl electronic caliulatoy called Bomar grain was introduced by Bomar. - Gn 1384, Hesman Holleth developed the punched Card for Storing olata- The. 1a-bit Code used on a punched casd i5 called Hollesith code - The fisst electronic computing system , wohich used Vatcum tubes cas invented by Alan Taxing: This machine was called Colussus+ Jt was a specral- paypose Computer which cannot be progtammed - - The fitst qenetal: purpose 5 programmable electonic Computey System was developed in 1948, called Ewac [Electonics Numerical Integrator and calculator]. GE was prog arom eck by wevsrting rts citcwits + This required many eworwers fe work for Several days. * Anothey problem eth ENIAC (was the I’fe time | the Vaccum tube Components , whch requite frequect mountenance- Paogramming Advances - Early in the evolution ef computer Systems, Computer languages began to appeay 19 otdex to Conti] the computer: - The fivst language, iS machine language constucted oT ones and 26105 sing binary ,which was code S that were Stored in the compute’ memory system as groups yf instruckrons called programs - - $0 early 1950s a computer system univAc became available ewhere assembly language was used to Simply the Chose a] entering binary code into a computey as its insteuctrons $n 1951, brsace Hopper ocleveloped the first high-level Programming language callel Flow- matic & 16m developed FortRAN [Formula TRANslator] o* "ES Computer Sqstems, which allowed to use fosmulas to Solve mathematical Problems. Cobol [computer Business Osrented Language] was successful d opide spread Proqvamming lang wage fot business Applica tions - - The adelitional lang wages Ave BASIC, Cle+t, pascAL, ADA The ADA language is eiseol heavily by he Department of Degense The _icsoprocessov_ Age = he worlds frst mi croprocessoy was the Lotel Loo, , Ly Gt wasa &-biE microprocessor & It had 12-bit Adolress Line andl addyvessad 40% memory locabon each bit ude %& It hael only 4S Mnstwchons & The craw backs o | 4004 cvas its Speed, word ew'dth and memory Stree es 1911, Srtel inkvoducee goes | Ete Ss oneere general Purpose micvoprotessor ° & I has & address bres and addressed 4 gles | 4 memory . | by ot had 266 insktuck'ons in its instyuction Se. 6 It had an internal clock generator, intevnal System conbolley and higher Clocks {rejuerg: C5 I allowed instuckons be to he executed at the Bake of 500 k instiucbions [second . - IN 1918 Gntel yeleased the 8086 & GIL is A 1b -biE general pur pose mi crop 8066S Sov © SF has 20 addsess Lines and can address upto Im bytes 4 memory & These ave dveY 20,000 Variations 4 inglracthoos | in 8096 - This 18 & CISC [Complex instyuchon Set Computer], & Ot executes upto a5 millions y instructions pey Second: & Ot als hasa bors ~byte instsuction queue or instrachion Cache that GF Pre fetches a few instru chon before they ave executed. | % The increased memory Si2e and additional instructions | have led fo mmciny Sophisticated applica tions dev Mu (roproces ors « bP alee | 6" sem 80286 45 Sthas 6 data lines hente it is a Ib bit processor 6 9 has du address Lines and hence can address upto 161m bytes of memory: & The instruction Set % 80286 #5 identical fo exce pt for a few additional instsuctions - 6 coas increased , 50 S08 & The clock Speed 4 8028 it can execute nas btkle as a60ns[% mips] $0386 Lo Gt 15a 32 bit processoy with 32 data lines by Ot has 3a address Unes and hence addressed upto 4G bytes 4 memory: by Ths 32 bit processor cas able fo lrans{er veal Numbers that require 3Q bit corde memory, & The instruction set of 90386 was upward - Compatible cvith the earliey 8086, and 60286 mu Cro py 0 (035075 « BoKEG was seleasedl by intel in 19.84 “Gt has 32 data Lines and 32 address bres & It Can addvess upto kG bytes a memory and also hasan 8 ‘ K-byle Cach integrated bo iks De, & memory System ae Pentium was introduced by Tote! in 1993 - S The two introductory Versions F the pentrum Operated eth a Clocking (Bequery of bo m2. And 66 MH2 and Q speed %f Ho mips. & the cache Size @ pentium cvas increased bo 16K bytes. 5 I has a § Kbyte inshuchon cache and Bk byte data Cache fy Ot has b4 data lines and 32 address line). In brief: micropro ce 5507 Data bus | pddvess bus memory Size. cor'dth width 4004 & bits tr-bits | Goa6 bytes 8085 g bits Ib bits 64 k bytes 086 tb bits ao- bits 1 fn byes $0286 Ie bits T loin bytes 80386 32 bis | 30 bits | let bytes 80486 32 bits | 32 bits | 4G +8k cache Pentium 64 bits | 32 bits | G&G, +Ibk Cache bela] ece [ar Microprocessor - Based pexsonal Computer system [ens Spr|e—fetaepucuner [Ee Seto | Buces DRAM re Partner, seam oss Serial Communtcahers coche 0286 ‘ Hosa dh duwve ROM B036G Keyboard Ww Mem! Flow at 20486 moseren Pentiam Scanner The block diagram 15 Composed of theee blocks that are interconnected by buses: (f bus i5 Q@ set °4 Common Connections that carry the Jame type of information]. Memory and a) Sy Stem The memory Structure a all Inte} BOX86 - pen tummy personal computer System ave Similar. The memory 15 divided into 3 parts , (2) Teh [Trarsient program area] lw System area (ii) Xm5 [Extended memory systems] The by pe. 4 muCropro(esov in geour computer determines whether an extended! memory System exists Mf the Computer +3 based 0 8056 the TeA ane) System area e565, but these 15 0 extenced memory avea * Extended Memory ~~! | ismbytes 17 the $0286 Gr 8038 SX /~ a sim bytes the g03@6SL/SLC 6 aMbyre the go386EXx. BEG DK, BOUBS |__| 2 System Area 0 45Mbytu tn the ce & Pentium - bytes . oer ougbyre i tre pentium PA TPA pentium i, pensar ms pentium 4 GHok bytes and Cove 2 44 she memory MOP ey a pesonal Cownp utev The Computey Sy stem basecl on $0286- pentium 4 not only contain TPA and system area sit also contains extended memory - cane pe Teeoalet program area [Tea] holds the operating system and other programs that Control the compatey figatern ~The TPA Stores any currently active/inactive Dos application progvam « - tb . «length of TPA 1S 640 k bytes which holds Dis oO, Ly erating S93tem and application 50 teoare Lens] €cE| 6h semy aFFFe 4RFFO MSD05_paogaam 08630 | COMMAND: Com OBIT Device dyevex MOUSE ~ 0.2530 [Such a1 MOUSE -S¥s MSDOS PYPYarn 01160 [01 Sys. paogian, 0 00900 oS Cowrmnunc cabin Avea Core Bios Communicostov a oonoo f ee ee Mbp t Vee 00000 - The inte vaupt Vectors Qtcess various {eatuses of Dos , BL0S€ Basic Lo system) and applications: The System Bios 15 @ collection a programs Stored in either Q vead only (Rom) or {lash memory that Operates many 0) the Ao olevices connected to your computer Sy stem ~ The TPA Contains RAM (Random access Memosy), Read/write memory , Where 6105 and D05 Communication areas Contain transient area usecl by programs to access Tp devices and internal features a) Computer System -I/o+ 545 "Saprogvam that loads into the req from the disk wwhenevev an msb05 [pcoos 84 stem is Started which allow Dos bo use k eg board 1 Video display and printer - The Commanp «com p¥09%4 (Command prove 5501) Contsols the opesahion of the Computex (x0M the Keyboard when operated in Dos mocle The {vee TPA asea holds dos application Programs bre -word processors | cap programs, Spsead Sheet | Progyoms ete The Sq stem Area SE Contains Pa8ams on ether Rom oy {45h memory and aveas 4 read farite. (Ram) memory fot data Storage. / - ~ The Sire o memory Maas Bios System Rom| U5ed depends on type Fooon asic language fom “| Video display adapter ce oo only on earl 4 attached - Free areq ~ Midleo RAM Stoves [ avd Win contvolley Frephecal or br mapped €8009 FROM data and above it tere Video Bt0s Rom olata: C0000 i Video RAm —Weleo Bl05 Rom located (textarea) Boos 2 ON Rom os (lash memory Video RAM Contains proqvams that (Graphs aveq) Control the Dos video ‘0000 o's play bpls[ece (6 sem ry a hasd disk memory iS attached to Computer, the intevface. card might Conta'n Rom and a disk Bios: ~The avea C000 - OFEFFH 15 {sees used fos Expanded memory System (xms) - $¢ allows 64 K-bybe page {tame Y memory fo be used by applcati'on programs - ~Avea £0000 4 bt EFFFEH Contain the CaseHe Basic lane on ROM + This area Vs 5 Finally af ten open in newer Systems « System 6105 Rom Controls the opesabon of base d/o devices Connected to Computer « The Incr oprocessoy The MP , Sometimes Tefevred 45 cpu is the Controlling element in a Computer system: The hp controls memory and to trough a Series Hl conn ecb’ons called buses . The buses select an d/o of memory device, transfer data between an To device oF memory and the LP and contro) the S/o and memo System Memory and Slo ave contsolled Fhrough ins tvuctions that ave Stoveol in the Memoxy and executed by hp. The KP pesfosms 3 tasns fot Compute’ System (Data tsansfer between it5el] and the memory ov Flo system (i) Simple Avi'thmebic and logre operabons and Gili) program glow via Simple decisions The power 4 Lp is in its abi bty fo execute. millions 9] instrachions | second {rom a progvam Stoved in the memory System + This Stoved program Concept has made the MP and Computer Systen a very power|ul olevice - Another feature that maxes it powerfel is its ability fo make Simple dletisions - These Simple decisions allow upto modi a the program 7 low « Lo Space ze, -Flo deveces allows the MP bo expanatow | . Area communicate between itself Ve and outsi'de evorld » CON . 038 ape dt -Lfo space allows the computer 03F6 | controle a0, (Car caapte fo access upto 64x olilferent re R-biF Flo cles’ 0318 Pisa bak [o olevi'ces rou one coms. | - Jt Contains 2 major Sections: 6255 006 Be ve ee Frtenes (825 The avea below o400H Besexved gmtoxupt {ov Sqatem devices - Remaining oon 0 Contwtinv es DNA ts available L/o space fos 9000 | conrrwiter- : expansion of newer System. - Fo addresses between 0000H to OOFFH Addyess Components on the main board of the Ccomputey while addvesses between 1004 to 03FF It adalxess devices locatecl on plug -in cards - The System gros Rom addvesses these basic devices 5 whrch can vary slightly in location and dancéon {vom one. com putes to the next hela] Eece [6 sen $086 Cpu Architecturve The 806 Cpu ts cliv'ded ito two fanchonal parts W The bus intewace Unit (Bru) Gi) The execution Unit (Eu) The Blu $li) Sends out adelvesses Gi) fetches instsuctions from memory (ii) weads data Jrom ports and memory f Gv) writes data 0 ports ancl memory. ie The Blu handles all tsangyers + data and addvesses on the buses for the exewtron Unit @ The Exetution unit tells the giu where fo fetch instructions and data from Gi) decodes Gil) eyecike instiuctions instiuctions and The Execution Unit The Exewtion Unit Contains Contol unit , Instuction decodev , tb-bit Arithmetic logre Unit (acu) , Geneva] purpose reqisteYS, plags veqiSte¥ A othe raster The tontvol unit clivects alll intevnal operations The decocley in the Eu Franslates the instructions fetched {10m memory into @ Series oy actons whith the EU Carries ou’ The Alu Can peyorm additon, Sublsaction, ANDO, OR, XOR, incsement, decrement, Complement , Shift binary numbers ekc: Flag seqrstey 5 8086 has a Ib-bre flag reqrster twhich 's divided into & parts (i) Conditional 4 lags Gi) Contsol flags: The {lag vegistev 'S aS Shown in dg) , ; ins 9 active flags: 1e-brt dla TegisteY Contains 7 A dy jin are used fo indicate Some Xx 0 nition produ cted by an insttuction - The Sx Conditional Condi d 'a45 are pe lvslece| 6's em a d!4q (c) - Ot holds the carry ajtey addition, oy the borT0w a tet Subtsaction « Parity Flag CP)..2 gbis set& 1 y the lower @-bits 4 the Vesulk Contains an even no: of J's Ceven pari'ky) , otherwise Cleared Codd paviy) Geis Sek if there 15 a Carry from brit position 3 & & duving addition of borrow from bit posifion & 63 during Sub tsarceion fuzeillary Covry Flag (A) - zeso flag [2] - Geis Set & 4 if the sesult ¥ an ee 4 atithmetic oF doge operation {5 2er. Gf 2-1 jthe result 1S eve , and Y 2-0, the TeSult i$ non 2er0 « sign flag (5s) - Gt i6 equal to the (5G 4 the result. S=4, the resull 1s neg alive and [sro the vesulk 15 positive Over loco ¢ lag (0) - Overy loo Occurs when 8.9 ned numbers ave Subtracted ox added - An ovet{ loco indicates the result has exceeded Me capacity 4 the registers Fot undigned operations OF Is ignored - T | XIX |X |xX|O|D]1 t[s[2 A [x |P |x c Bow wo 4 gz = $ 5 path Fig: (> 8086 Flag Yeqistey NOTES overflow Flag if Get hen the exot oF carry inte renga bit and Car ry-our oF mss bit iS AS Ex: MBM Considey the execution CT the instyuchon Apo Bx,cx + St adds the contents 4 BX and Cx and Stoves the vesult “Ss Bx Depencling en the Tesailts Me Cond. tonal flags ave fected as follows - Let B= 1234 H Ck = FaeH 1 1aak 4 4 1Fa€ H ~G16a H = 1001 DOO! OID Colo CF 0 3 No carry from M56 A> 1 > cary out from bit 3 & bith 2F=0 3 gesult '5 non 2e%d SF<4 2 GInclicates the vesull 1s negabve (56-4), Je can be neglected for unsigned Numbers - of- 4 > indicates wrong answwey if cootKing eo iH Signed numbers. For unsigned num bers it is neglected: OF occas in the Above example since the lang est positive number using tb bres is TFFEH) ancl the Sum is required to be lovger than this Value, which is not possible . So, we get a CTerg ansiver - OF Is possi ble. only when addi wma num bers 4 Same sign oY Sab tratkng Numbers 4) opposite S190 pr= 0 > The LS byte 4 yesule has 3 number of 1's Codal pal vty) bel wa[ece| 6 sero The Temaining thee {lags in the dlag Fegister ave usecl to contyl certain opera tions of the processor These Contvol d!ags ave Set ov Feset woith Specigrc instructions in the program. The three Contxl ¢ lag ere Tsap lag (1) - This is used for Single Stepping through OQ progvam rduving dle bug ging: Sy T=4, the LP intersupes the {low of the program 0n Conditions as indicated by the olebug registers and control vegrsters. 4 T-0 debugging featare 19 disabled . Entervupt {lag (4) - The T {laq Controls the speration o the Ime (Soterrupt request)ip pin- yf I-4., WTR 15 enableel and i] T-0, twtr is Aisableol . Divection flag (D) — The D flag geleces eithed increment ox decrement Mode (0% OF and 54 ‘Keqist ev during Stxing inStauctions . 4 Ded , he Feqisters are automabiall, dlecremen ted 9020, the veqisters are automa ball, incremented . Piogtar ming Model of 9034 General purpose Registers The EU has eight general purpose repr sters They can he used as either ¢-brt or [b-bie registers They are used for holeling data, variables and inted meclate vesults Eemporarily ox as a Counter or fot Storing offset addlvess for Some particular adolr ess ing modes * AX Bx cx Dx AL OL CL. OL a | [Flags Accumulatod Base Inclex count bata Stack pointet Base pointer Sous ce Index Destination Index - Insesaction pointer Flags cs oS BS) $s Code Segment regi stey Data " Extra 7 v Stack ” Fig. Proqtamming model of 8086. bela] ECE [6 sem, | As in dg: , the 16 biE general purpose registers ase AX, BX,cx and dx: Ax (Accumulator) - AX V5 used as @ Ib-biF Acta mulatoy twith lower B-bits of Ax olesigna ted as AL and hag hey §-b'és as AH: ~ AL can be used as acceumulatoy dor B-brt Opesabions - - The attumulaboy 15 used for instyuctrons Gke mulbplicahons, diwsi02 and Some Goly'ustmenk iNnskruCbONs * 8X (Bose Index) - 6x15 used b hold Offset address 1A Some adelae 3sing modles + = for g bit operakons , lower B-bres of Bx 15 olesig nated as BL and heghed &-bits as 8H cx(tount) - cy is also used as a default [inc eesratate counted in case of String and loop instructions - - hower @-brts 4 cx > CL { Fox “bit = Higher @-bresey Cx > CHS Speva kon | py (pot) - Dx also holds lo acdyess dusing | cestain Llo Opesatrons han frrvabons St algo holds part of the result DL from malkiphcatior and part of | olividend before olivisron - @ The other general purpose Teqisters are In olex veqistes (Destinator index, Source index] and pase pointers - Apart {rom functioning a3 general parpodse regiskers, they also funchion as follows: Z| Source Index (52): Addvegses Source Serving data for unce Lndex O: the String ingtxuchions - Destination Undex (01): Addresses Stving destination data dot the String instructions. pase pornter (BP— + Points bo a memory for memory ec porntet © dala tranafers- Special puspose | Registers . The Special purpose vegisters aré used as flags, pointes [Stack pointer, Instruchor pointer) and Seq ment reqs tens (cs,05, 65, 33): NOTE* When questinn *s asked to explain pescen model i 1 Bogs explain Speco) The Bus Interjace unit [B10] Hotton geyistens Gnd GPR The Bus Intexface Unit [eiu) consists qd Ls The Instyuch'on Queue 4 Segment weg seers L, gnstract’on pointe’ CrP) | bP/(ws] ce) 6% Se Instiutbion Queue - 7 To Speed up Program execution, the Blu detches as many as Six instYuthons bytes ahead g time from memory. These bytes axe Sloved in a Fixst ww Fivst oue [FIFO] memory Fegisters Ths ig called A Quecde. Ftuhen the EU 15 ready for it neve ingtyuttion, rt Simply Yeadls the instwichon bytes or the in Sou (bon {vom the queue in the Blue -Thi's increases the Speed of opesalror , Since the Eu need not cwart for the opcode tohe fetched rom the memory. Also when the Eu 1s decoding ov execu ng aN instruction , the Biu can fetch the nett inséruction. Ths process 4 fetching the next instvuction while the Current instruction executes i5 called Pipelining. cohen the jump or CALL instruchor i5 encountered, the wequired opcode evill not be present in the Queues Then the Contents of quene evill be flushed out and i reloaded Stasting from the new address. Seqment Registers - The 8086 Blu Sends out ao-bit addyesses. - Hence it can aclel po ie adelress 2°" oy Lone, 51g bytes [rem bye] in memory . - But the 8086 eses memory Seqmentabon: $t treats the mega byte memory as divided into segments. The matimum Sire el each Seqment fs 64 Khykes. Thus a location wittin a Segment can be cidelaessecl using 1h- bres + - The Biu consrsts of & Seqenent registers - these Seqment registers bold the upper |b- bits of the Starting addzess vy the Segments: The four Segment peysters ave the Cocle seament Ces) Teqistey , the Stack Segment (55) vegister , the Extra Segment (Es) register and the lata segment (nn) 7 eyister. Ui) Code Segment Register : The code Segment Ces) Teqister holds the Staxting address of the code Seqment. The 65 holds the Program code. The 16-bit content G| 4 Segment register 1s Called Segment address . (i) Data Segment Register : The 05 holds cata, Constants and work axeas needed by program. The Starting addyess of the Data segment re indicated inthe Data Segment register: be] vs| eCE| 6 sem Gil) Stack Seqracnt Register : A stack 15 a postion of memory set asicle to Store Adolyesses Sf data , when the bP bsanches fo @ subroutine - The Stack *5 Q Last in Fixse out [LIF] olata Sesucture im plemn ented in RAM. The }P accesses the Stack fov a pust ova PoP opesation + The top most filled location in stack 15 indicated by Stack pointes (sp), The Stack Seqment weg ister holds the Staxting addvess 4 Slack Segment memory, iv) Esctwa Segment (Es) Register: 8086 has a number 7] instructions dor String manipula bons. Tp move a Sixing from one memory area to another , the Stving must be in the Dala Segmut. The olestination to cwohich the String has to be moved! must be in Extwa segment Where extatly the Es gtavtS in the memor inclica ted by the. Contenés of a register called Extya Seq ment (5) vegister. is FeFFA | | I< Top | extva sejment Fakaa Segment reyistey 210004) < EXtIW Segment base < Top c| Stack Seqmnent * Stacie segment vegister = 5000 # € Stack Seqment base < Top of code Seqment Icode Seqment veqrater- 348AK sek] ES 100004 | SFFFF A TI bk $3 500008 I Gy BaF bu cs snared LRFFE HK = 6K Ds | Kcode Segment base j —— Top ef data Seqment - pata Seymeat vegiatet = 300 0K 20000H' $————— bottom 44 Data Segment ° Fig: One way four by-K byte Segments might he positioned eoithin the I-m byte address Space 4 an 6086 He[rs fe ce (6 sem Lnstauctron Pointer C1?) + The instruction pointer (4p) Points to the instruceion to be fetched and executed next: ~ Gb 15 a b-bit veqrgtey which holds the 16-b:t delves, OF offset, of the next cocle bate within the Code Seqment- - The value contained tn the IP 15 Tefessed bo 05 an offset because this value must be Od 5et fre Cadcledte) the Segment base addvess in Code Segment register to produce the seguired ®o-bit physical address Sencl out fy the Blu- - The contents of IP is incremented af ter each memory access opervalvon o the C5 memory, Physical adelyess calculation . Let us Considey how ao-bit adldyess is Generated by the Blu using the 16 bit IP contents. Fg: Shows how this works. The C5 veqester points to the base ov Staxt Of the current Coole Seament the TP Contains the c’Stance or afdsct from this base addsess fo the mext instruction byte to be fetched - hyearn © Top of code Segment 3eABy Hn < Code byte IP>GQt BL EADH Ke Stast of code Segment C5 = 348A Let the contents ay ¢s be 348A H+ [his 15 called the Seq ment Base Valuey™ je the cocle Segment Staves at B4gA0 H+» Ket the next instruction to be {etched {x0 a memory he tare # bytes Away from the beginning of the code Segment 1e@ the tP content S bogeH. This 15 Calleol the aff ace value ox Effective Addlvegs. while calculating the physical — addyess , since the cs repister Contains only the upper !6 bits of the base address dor the Coole Seqment y He Blu inserts Zev Jor the lowey 4-brts a the Segment hase addvess te To calealate be. physi cal address the Blu adds oP. 348A0 H And Halk H USing the addeY in Blu, ©. Value in Code Seqment geqisteY =34 8A H its 2640 QJ ‘J ow 9 Nagi" Bo-bit Stavting addvess of Coole Segment = 348 A nn 3 igF OF "-bit EA ox offset in IP = ale J. do-bit PA = 38AB4 H bePlnvsjece| 4m The lable below shows the dil ferent Segments and the ‘Teq'sters whith Stores they efectve Address and theit speVial purpose « Segment | Offset Special Puvpose cs Ip Jnstsucbon addsess $5 SP ov BP Stack addxess Ds BX, ST of DE Data address DT ji £6 Clot $¢1ieg spe Sésing destination addyess Foumation of a_physveal addvese Effective addvess Pe = o8 offset + a bits 5 ves Len bite Sas tiael physical adde[ao- bits _¢_1 Advantages of Using Segmentation DAllow the memory Capacity to be I Mbyte even though the Adelyesses assoviated ewith Mme individual instructions are only (6 bits wide: a)Allow the instructor, data or Stack postion of a program to be more than by K bytes long by using more than ene code, data ox Stack Segment 3) Favlitate the Use of Seperate memory areas for o progsam , its data and the Stack: a proqranr and[ot its data to be put into i) Pesmit djerent aseas of memory each time the pe 0qr is executed: i Pai 00000 00010 9.0020 a — Fiat Le saci second Segre” 10000 <— Thad segment 1000, - +} — Bm 10020 -}——_,-— 4iq. ovatopping Segrnens rams Code, data and its stack Sepesaton af Oo pr (co Code Segment pata Segment Extra dara segment Stace Fg Shows how programs Coole and its associated data and stack Can be Seperated in memory: be(rsece | 652m The Simpler Approach 15 to let both code and data VeSide jin one contiguous area in memory and put the Stack in Some fixed avea- This 5 Satisfactory ¢ there. i5 only one progyam in memory at a time , bat in mulki px0g Farming environment there may be gevesal progsams io memory Simul taneously, Foi multi progyvamming it is bettey to keep the Contiguous Ce ie) memory as small as possible and, whevejore , itis bettey to sepesate the Code from data « Advantage ) Can be better understood by Censidering a time Sharing Systems in which Sevesal UsexS are execcting diferent programs. $f there 15 not enough ey ee Proqvams axe Shuttled back and for between memory and mass storage. As they take tusns using memory they ore dyna cailly put in olifferent places in memory, Memory 02.000 }-———] <— Cuxent((cs) = 0200 6 = Branch add <0260r Current code Segment “tf enewlesd=1A3O 600 t new bran adsens,, “WZ y Relocated Code Stgm en $iq: paogtara delocaliow uuting CS aegiatey, A given program may begin at PA O2000H oohile re is Currently executing 5 but the next time it és brought into memory it may begin at (A3oo: Y the preg ram Contains @ bsanch insHuction, the branch will fake place convectly only the Contents of 68 ave changed cohen the program 16 velocated. Although the Seqments ave by bytes long y they can be overlapped to better ubili2e the memory « fis shown in dg: fo pregram fils only past y a Seqment, another Code , data os Stack Segment could overlap the progsam's Segment and the beginning addyess 7 the Second Segment could be corthin 16 bytes of the end qf the program: The only wasted space would be the few bytes between the end vi the program? and the nett — I6- byte boundary. Machinkstanquhje: Snikeateizon An instruction 16 clvided into JPeups 0% fields, wrth one field called operation code Copcode] , indicating cohat the Computer 15 to do and the other felds, called the operands , indicating the information needed by the instruchon +n carrying out ls task opcode lOpevand |... ... Opevand Frege Geneval instyaction dovmat : be/wal ece/ oem Addve5Sing Modes The way in which an operand is Spetifred 15 Addte5 5:04 | mode» The addressing modes a $086 ave classyred inte two categories —. those gor dala = Data adcliessing moder those fox branch addvesoes +3 prog7am am is called Data- Related addvessing mede - (1) Immediate + The clatum is erthey Gbit ov Ib-bits long and i6 part of the instruction - dosttuction Eq: Mov AL, 55H 5 Copy byte 55H fo AL Mov BK, OAIZH ; Copy 16 bit data oAIaH to Bx mov Ab, ‘A’. Copy the Mscll Cede of ‘A’ (ute) to AL vepater: (2) Disect Addvessing mode : The (b-bit EA 0) the dlitum is past of the instructron itself - d Anstructon eA } ty Eq! mov GL, Loc : Copy the Contents % Symbolic memory Loc to BL tegistev Mov BX, 05:34H > Copy evord Value atan ajset ef 00344 in DS to Bx (3) Regis tet Am: The datum is in the vegister that /5 Specified by the instruction. for a 16-bit operand, a s eqister may be AX, BX, Cx, OX, ST, DE, Sp 08 BP y and for an g-bit opesand a wsepster may be AL, AH, BL, BH ,CL,CH, OL ov OH: Anstauction datum Register | —4 Regratey ata Content of BL GAL Eq: mov AL, BL ; copy @-bit d data content 4 BY & Ax fnov AX, BX 5 Copy th-bit mov C¥,$£ ; Copy to-bre data Content 4 ST G ox, (4) Registey Indirect Am: the effective address (EA) of the daturn is in the base register (ax) 0 aM index register (st/pr) , that 5 specified by the tnstyuction: EA= § (6x) 7 (51) (pt) Anstraction Reqistey memory [Register }-— ea Datum fg: ro g: tnov ex, [6x] 5 The word contents of the data Segment memory focatror adds essed by 8x 18 copied to CK veyister « helms] Ece| bse 5) Register Relative : The EA #5 the sum of ar 8 ox th-brt olisplacement and the Contents of & base registes ox an index veqister ea= ¢ g-bit displacement we + Giegn extended) 07 9) 1b bit b's placement Anstsuction Displacement FA _Memory Addxe ss Eq: Mov AX, 1000H [6x] 3 Copy a data from DS memory dela essed by Bxt WooH bo Beqistey AX Mov 2SA[or], pe 5 Copy a data byte BY into ps memory location addressed bg DItasn. in “ [orrssn), Ax; Copres a word f70™ AX inty Stack segment memor. location Ad¢rvessed bg (6P-+850 1] (6) Based Indewed Addsessing mMode+ the EA 15 the sum of a base wagiciey. and an index Teqister, both a cohich ave specified by the instyaction , ive - EA = Gy + wt (ep) (01) Dhstiuction Register Index q, eg iste Base veg aie eae ‘Index memory EA Register 4] Datuno —| Base address Eq: mov AL, Cor] [ox] Mov cx, 0S: Cot+ap] (1) Relative Gased Indexed AM » the FA Fs the sum o an ¢ ov tb-bit displacement and a based indexed Adelyess je. | €A “jeat fet abit | (6 Pp) cl'sp lace ment (or) (Sign ext tenclealloy 16- bie ob'splacmunt Eg: mov 37H [op+si], AL $3» ppasat 31H - mov AX, 64H [ st48x ] 5 DS! ST 40x + 64H Base Fegistes| Me] ¢c€ 14" sem Lastyuction Branch Adddée ssing Modes 0% progdam adel ess1'ng mode Re lative progyam memory addressing Lotsasement Bisect + The Me raent Bisect dective branch addsess is the Sum 4 9 B-bit ow Ib-bit displace ment and the Current Contents 4 Ip. when the dlisplacement 5 9 bits long , it a5 a Shove jump is Teered to In sesaction FA = Effectiv ee & ‘dec tive branes ely 55. Sen, . SE may be used wres Chet Conc tional oy un conditional branching , bat a Conditional branch ‘Ns5buUCb on Cap have Only an e-bit de splacement: Ey Back ; mov AX, Bx Short backward jump . i offset addvess ef "back" <: 1a8 bytes Jmp back Tine beloco Short fox ward jump Mov Ax, Bx : "below" offset address < 121 bytes. below: SuB dy ies fov Short furop the clisplacement cor'll be. coithin “128 to +1at bytes wn cind for a neav jump the. Ih-bit displacement 15 wr 30768 to t3aTET PARGE (barkeoard) (doxwoard) Loclivect piogrvam memory _add4essing GIntrasegment indirect} The effective branch address 15 the Contents Y 4 weqiatey OF memory location that is accessed using any yf the dlata-velated addsessing modes except the immediate mode. The contents % the FP ave. replaced by the effective branch addsess + Ths addvessing mode is used only in un cond: tional branch instyuctrons. St 15 4fa% Neat jump - he(nis] EcE |e M5 ern Reg ster | ____» Ej fective byanch addvess SEK n ptia EA Computed mo auording to laddvessing mode Edjective branch add Yess memory Eq: TmP OX 5 yesults in uncondiwonal byanch Fo Of{ Sef locaton Ox= 1834 in the Same C5 Trp cord Pex ao00H [ox] 5 Yo 8x2 1a34H At word loca bon] tasuH+ | @000H)= 3a34H sf the dato '6 5618 Hy then tt 65 an unwnditronal beanch fo offset lo cabs S61 H in the Same Cs. Ditect proqsam memory addressing Lntetseqm ent Qivect: Replaces the Contents of worth part of the instyuction and the Contents 4 cs corth anothey past a the ing bvackion + The puxpose oy tis Am 15 to provide @ means 4 branching {som one ¢5 to cindther: St is for FAR Jump Instruction Oddset | Seqment +35] £4: Temp FAR PTR Loc os Inter Seqraent Indirect : Replaces the Contents of IP and cs Beqister with Contents o evo Consecutive words in memory that ave veferenced using Aq of the data- selated Am except the immediate and Yagister modes Two congetutive Instouction words in memory Adolye: Branch addsess old Segment addvess £4: Imp dwotd PTR 2000H Cex] Suppose BX> 1234H sy the contents y word location [ 123qutacoon] 3234¢n is S6TSH: Ths SéTER provides the 4d set value and the Contents of next word location 3236H 15 ABCDH, which provides Segment base Value. 16-bit Ansttattion mode- MoD-REG - Rm o-t bytes opcode pisplacement Lmreckiate 1-2 by EAS 0-2 by tes 0-2 bytes helws] Ecel 6%sem Enstsuction Formats SETAC OD Te One-byle instsuction -impliedl OPLODE opesand (5) One-byte instyuction ~ Fegistey mode OPCODE Register bo Register my Register tol rom memory with no displacement OP COOE Mod [REG | Rita Register bo] {som memory with displacement OPcooE | moo [REG | Rim [Low- order Disp | [High-oxder dis] Cay 1e-bit clisplacement Immeclate opesand to vegisted is used) OPCODE. ] [11 Jorcove [Rim] [Low ovder Data tr igh ovder data (9g \e-bit data is as LImmeoliate opesand to memory with Ib-bit i's placement OPcooE Mo p[opcope| Rien Low over chsp [High order cus Tow Ofer data igh oxder datal (4 tb- bit data 15 used) -The opcode and addvessing mode designations ave in the fisst 4 o6 2 bytes of an instvaction “YO displacement ov immediate opevand 1s & bytes the low-oxdes bytes appeass gisst ~ the optocle usually occupies the fisst byte » and only the first byte, of an insteuction » within most o/ the opcodes theve ave SpeGal t-bit indicators + They ave ; Wbit- Y an insexuction can opevate on either a byte/ wore , the. optode includes @ we-bit whth jnedcates whether a byte (w=o) or a word (w-1) 5 being accessed. D-bit - Fos dou ble. -opesand instyucbion , one of the operand must be a REG (seqister dield). Retr is the Source opesand (=o) ox the destination operand (0-4) Sabit - An e-bit 2'5 Complement number can be extended 0 a 16-bit als Complement num ber by letting all the bits in the high-order byte equal the mse in the low-order byte This is tepgerred to a8 Sign extension. The S-bik appears ewrth the W-bit rn the immediate lo segistev/memory add, Subtract and Compare instruchons , @-bit opevation — Siw = 00 16-bit opesabion with a ig-bit immediate opevand- $iw=04 (b6-brt opesahon ert Sign- extended g-bit op immed ate opesand | ~ swe dd pelvs/ ECE] 6 sen V-bit - Used by Shift and votate instyactrons bo dleteymine the numbex oY Shifes: 2-bit - Used by the REP insksucl¥on . A vegister designation 15 Q bits long if ib 15 for Segment equ ster and 3-bits long if it 15 for ang Other fype 4 seqistet Register Registet Reqisted] 3 eqment Adelvess| co= 4 | w-=0 |Addvess | Register 000 | AX AL ) £8 ool cx cL or cs oro | ox OL 10 68 orl | ex BL ti 0s 100} $8P AH Onl BP” cH tro} $r DH rei | O7 BH Table : Reqster addvesses The opesand Specifed by mod and Rim fields i determined according fo Table given nestt Ne u Rin N} 08 oO) 10 uc tad 000 /ex+5I | Bx+sI1+D8 | Bxt ST + D6 AL AX oo! |axt+or |ox+or+ Ds | Bx + DEF OH] CL 2 x oto | gprst |pp+sz+ 0s | p+ st+ ow) De c ott | gp+ ot | apt OF + $8) BP DI + Db} BL Bx 100 | sr git D8 SI + DIb AW $P tot] oz Or + 08 pr + Dib cu BP 110} pie Bp +08 BP + Dib DH $1 ma Bx Bx+ De Bx+ Dib BH ot Table, Address modes and default Segment seqisters fos Vaor'ous "mop and Rim field Combinations - For the addvess modes involving BP reqistes , the $5 1s added to affective addyess to produce physical addyess. For all ofhes addvess mocles , DS is added to glfective addyess to produce Physical addy ess Tern plate fos Data tsansfer between Register and Reg [mem ‘}ofofo[ifo [pw] [roe] rea [Rin tee Fq:4) mov ax, Bx OPcode D w mod REG ~— Rim 100010 4 4 t ooo. «OO v v REG destination AX = 8BC3H fx) hee(ns[ ECE 6 sem 5) Mov DS: oFaueHLar] px Segment would be $5. But in ov opcode =D tw mop REG RI m 100010 =O ot a ur ou 000 REG Source Y Bx BX 2) mov cL,[st] Opeede D wo MoD RE&% Rm toeeio =O 00 601 100 Req Bute. operated 3) mov wén [or], ox opcode D w NOD REG Rim & toon 0 4 of lott 4) Mov OF a46u[od, px OPcocle D W MoD REG Rim (6b loooin OO 4 tp oD NO ke whoo Lowed Byte = 89 DSH: = 8AOCH bit disp = 895646H 4oH it disp + i = 84.96 4eroH tng hey byee Whenever Bp i6 used to genevate FA, the defacile this eocamp le et AS Seqment veqgister DS is used, we have to provide Sop (Seqment over ticle prefix) byte. The Sop byte. iS 001 SRILO 5R Seqnoent Teqister 00 acy oO. cs +. SOP doi Above ex0mple 10 55 Httlos nA bs 15 00 tb = 3B 0s fe G0P opcode D w moP REG Rjm lb-bit disp 3E toooto 0 A 10 oto tio ke fou = 3E39 4646 F2 immediate data to Yeqister 4] wighet Se ‘ara = BB Q5 oon 6) mov Ax, 25H (NOTE: For movi opcode ow tou 4 REG lb-bit data- 000 «25004 1) mov DS LOF UW 6H LBA i934 u SOP opcode GW MOD Opcede Im 3eE 'o-bit disp. 16-bit data Wooo 4 10 QUO 1 = harry 34124 = 3€ C1 Bo ue F2 aui2u &) Abo 2345H[ex+07] , px opcode D W fod REG Rim pr'sp co0000 0 4 10 O10 Q 00] 4s a3H Source register = O1WN 45 23H- 3) ADD AX, 0123H opcode § WwW Mop opcode RIm to-bit data ie loooon (0! " 000 oe 23 01H | dorm AX 2 81co 23014 | ot optode § W Bata Short form Cop00! Oo ! 23 OU = 05 23 01H | Notes § bit is 8gn Extension fot a byte operation (w=0) > 50 For q@ word opevabon (w=) => fre $4 only if the imme cliate data is <=1FH - Jn such assembley generates t bg be code. for However during execahon, Sign extended bo case immediate data- the one byte data will be make 2 byte operand - 1s > 1FH , hen $20 Sf immechate lata Code. and the assembley genesates a 2byte Pow immediate clata ® bel] ECE Le’ Len) 8) mov AL, [123G-H] opcode DB W mod REb Rim lb-bit - 100000 1 0 690 000 tO 34 12H = $Q 06 34 12H 4) mov 8x, cs opcode moP SR RIM tooolloo = HT ool, ss = BC CB és to) Mov 08, 8x opcode mop $R RIM _ ge pg ur toooulo =o tl ots Vv bs Note + To Copy to ov From ~~ Seqment veqis revs ADD mnapsuatiog 1) ADD CL, BH Opcode D Ww mod REG Rim co000 «2 OO oot tits = «OR CFH v (co s destination 6H vegisted ov opcode =D w mop REG RI cee 000000 O O uw th O8Id 5. Se (aya Sousce ae Begistey telns] Ec€ | 6! sem Terrplala ov ADD instruction Add vegisteY to veqistet [memory and Stove vesults iP Beqister [memory + lopcocle of] [rro0 REG alm| [bw ordel bise [Mgnrde A 600000 ise opcode = optional depending on mop field BJ Add immediate data to veqisted memory and pul pak Besulk in veqrstet |memory tional depending on on teneD del opcode |S [ew] fino [opcode] Rlin| [Loco oveley| [rig h-ovder + optocle =100000 opcode= 000 Disp Disp tgh ordes data a, Optional yf Siud= 04 Eq ADD CL, 83H OPlode $ w mod optode Rj Loworder clisp 100000 © 0 th 000 ool 83H = 80cC183H 2) ADp [6X], 1234H opcode § W MOD Optede Rim Low tMigh 100000 O 4 00 060 thi 34 iQH v ox = 810134 12H - The eotecution Thsteuction Execution Timing time Of % inStruckon Can be cletermined by multiplying the number of clock cycles needed to execute instsuction by the clock’s period - Y tan be expressed as the Suro a a basic enewtion time plus the time Bequived to calulate the glfective adesess if & Memory opesand 1S involved: (Lostvuctron AbD or 5B Reqrster lo rei stev eqn ster Inernory fo ¥e9 Register to memory Immechate & Register INo: q clk (yele Nord tvandexs 3 © Q+eA A IbteA a | 0 ri+eA 2 lImmeclate fo memory Time needled to calculate Effective address EA No: of clock Cycles Disect Register Unelivect | Registey ve lative Based Indexed CaP) +01) ov(Bx)+ (st) 7 (8p) +61) 0¥ (Bx) +07) g helnis] Ece [6 sem cA No: of clock cycles Based Indexed velative (a) + (bI)+ Disp ov (Gx) + (sr) + Disp (BP) #054) + DISP o4 (ex) + (oz) + OYSP For eq: Sf clock has a freq: ef Srat2 (period = o.2 45) ") App Register bo Regi stex —> ADD AX, BX No: of Clock “cycles = 3 Ler'they Jor by te| word operand] “Time 2 wo: 4 clock cycles ¥ clock pexiod = BxXO2s = O-6hS 2) Aod memory to Registev using based inclexed ve lative Am Abd AL,CaxI( pre 12H) | Clocks cycles > QtEA FA4t2 © Qi cycles (dor byte] 7 ovd Time 2 alXorhs= Hip las operahon ateven cloldlve ss Nox a) € lock cy cles 2141244 IF cycles if eword at p odd addres extra ycles Time = 25x0-2h5= Soke 3) Adel Register fo memory using based indexed address Avo (6xJ [pa], AL No: of clock Gyeles Hf word at even address = 16+EA 216+ 8 2 dh LTime = Qu x%0-2US= beg bs coe No: af clock cycles 7 word at an odel acldarss= = IbtEA+ h + w ba exten cycles exreo to stove wooed cycles bo relative word = 32 uyeles Time > 3ax0.2 HS = 6-4 hs Note: Each odd address word Teference needs © & extea clock tycles in acce 53ing the opesand

You might also like