Unit 2
AI-enhanced title
{ ep, C8, addressing “CoP | copmeesor dhs proceising perform an opéation ins coprocessor MRC NCR we coprocessor rite ranser—move dati tofiom coprocessor registers Toad and store blocks @f memory 255.2. Coprocessor35 Instruction Syntax (CPAS is called the system control coprocessor. Both MRC and MCR| nsinetons are used to read and write to CPIS, where register Ra isthe core denination rites, Cis the pimary register, Cris the secondary’ register, opcode? is a secondary register modifier. We may occasionally have secondary register ealed “extended reste.” 2.6. STACKS AND SUBROUTINES ‘A subroutine is reusable program module. Amin program ean cal or jump the subroutine dae ot mare ines. The sack is used in several ways when subroutines ae called In his se we wil eam about ‘& How tote subroutines and ell them fom the main program. | Ways to pas parameters to and fom subroutines “© The function ofthe tack andthe stack pointer, ca roc en Pripirae a ‘How (create and se stn gag : ofan delay A avon PrN mde te Frequent the subrooine ict by epg a 8 OF cling ald, progam contol is transfered from the mag oO © Ubon i hen the subroutine Snishesexceuting, consis eo Sebo re sack provides the means of connecting the sumone oe a roa, bs. STACK stack is actually just an area of ee Aes memory whore i xia. For this reason, register RIS is refered to so he mk se ese "0 the stack pointer (SP), Make the stack and the stack pine. The ‘hack is an area of memory the stock pointers ltr isthe addres ofthe last valve pushed onto the stack. ns @ @ Fle. 27, Pate and sack analogy 10 compute steck operation (hen rom ‘AMbrocomputeregicering bile)ess erase sn cae armel tien anomie am ia ieee some plates. Si mfp ca Per ape parca emer fe et ep of Ge sk. Fg) an (0 sre is Pernt Seco mcasac etree you consider te usage of the Pines, ju ie tht the lst plate pa nto the ates remaved fom he ack Thus the rack a st in rst out ora io eevee, Te sack operates in exact same waynes itis also refered ts 1 Fo don arose. The push inacons fst decrement he stack pine by Score sd hen soe ope 80 byes f data othe tack Conse wat pens if register SP cots the adress 012000 00FF aid the iter RO cnsns he vale Ox6B. Exeaing the aston PUSH (RO} fs cements he sack pin by oe, 99 reper SP is now Ox2000.0FE. and pues he value 0x ont th sack t memory locaton 0x2000.00FE. The POP {RO} intron st pts te contents ofthe top of sck into the RO register and ten nrementthe ck pointer yon. “hea ing you vil be wig the ack fr is ving dia when subst is cle Fer exp, one your min program ss reptersRO-RS, You cll browne tht i going to ele some vale and pass i back to the main ropa. Aer yo el he sou, ou an just pus al he data onthe tack Fete exc any nsrucons ine bowtie The subroutine ten we alte ese internal use and store the data a te sin program news in oe ofthe memaryJoeations. At the end of te pus fa INE MSTRUCTONS GO HERE foray La bor Por ft : Por faa l242. CALLING A SUBROUTINE You witl reall, the program counter, o register PC (RIS), lvays contains the sss ofthe next instruction to be executed ina pogram.Caling asst i |nlar to an unconditional branch the program jumps to a diferent addres ster than the next address. The difference is tht when the subroutine finishes -resuing, contol gots back to the instruction afer he subroutine cll inthe sin peer. : | ADL insircton causes the address ofthe next memory istrstion tobe pushed onto R14 (Link Repister or LR) and the argument of BL. 1 be loaded ino the _|Pbmm counter. The argument of BL isthe staring adress of the subroutine. Bu, [se yu write your program, you just give ita name andthe assembler Figures ou [fet Attend of a ubrouting hinson BX LR aes wh va I {tein LR to be loaded into the program su. _ | this way, the instruction after the BL. in the main program is the next oxe| | Note that if the value of register LR is changed within your subroutine‘nbeed ad Real Te Sten] =a . —_——_—— (ce, ty cling Ouse o Inch eis LR nut be sverestored onthe sack ee ey preserve Ke vale. In gsneral itis a good habit to use instrtions poh (LR} and pop (LR) atthe beginning and end of ech evbroutins, 2, PARAMETER PASSING ee aes ped he mbrouine byleving he an nse, aan aag he ous oe A pence is aed tk 1 he ep nnvng he tino cg te da Ti he yy ower we psn zeny es is pean tig sed he route fin lt, his co eect synate tiger of sig prance. The tan ee tes ped eon ths cle ally fc, iegenmtogocmen alent pment 2.64, SOFTWARE DELAYS ‘One way of resin a spesfe delay isto wrt subrouin hat contains Lop, -te in the lop takes to execute canbe calculated by ang up the total number of elk eyes inthe loop and mutpyig this bythe period, T, of one clockeyete This isthe inverse ofthe clack frequency. The numberof times the lop exesies| can be adjusted to create diferent delay, This loop counter canbe passed tothe subroutine soit an be used for different length delays 2; Subroutine creat dey, 3 $DELAY_CLOCKSIs he counter whichis 5; decremented to 20 gy preteen I 6 Daley LOR Ra, = DELAY CLOCKS Set dolay ost 7 eal suas Re, m2, #1 < :oeremant count ° BNE cel =n at z10, do again ° ax OR tum when done Fig, 2 Subrowine implement software dea oop conning 1 oop igor consis OF OR 109. The fy Phas to insur js wet | lock eel and BNE is 3 tions, SUBS and BNE. i Bocce {0 SUBS adn MM ap nea Sine lope vt eo gla forthe eat DT. whee T isthe coc penn Tr This gives a| eens oms We RVG N= 1 fora dey of 7 Snes Ee ny ste shore dy spent BS 8 yf = ns. The max valve For N she Ingest iy na a BRS kin delay of (t4204.967295) x 62.508= 107.745 179 miner {fa longer delay is needed, an outer lop is adjeg ener ae st 1 0 otherwise he subroutine wil ge Make sue that ne of te into init oop, 27, FEATURES OF THE LPC 214 X FAMILY 6 soca sitaManG nicmninain tw Ge TIS euTIDMS CPU wit resin emerson ET a mente i ce el fo 2 KD SI2KD. A T2Ri wide memory ces ants ce ee [ct cae 251 cote atte nonmmeren [ree cade sae peo, he ahenaive 16 Tht ote me yr an 309 wh nina proraner ey, De eo Eview power cosuncon, LPCZIIAZ NGM ae eae cee Bete ec hey recuse sm te pra a ses commnicon ins ging fom 8 USB 20 Pp ei nt UAT, SP, SSP to Cb onl oncp SRAM 84D ep 030 ee devices very wll sie er commie gays a poe fever son monn, vie reaping, poi bo rt ie na igh roses owe ||. Yarious 32-bit timers, single or diol 10-8it ADC(S, 10-bit DAC, PWM! _ flames and 45 fast GPIO ince wih upto nine ede or level seve exe