DOC PREVIEW
NMT EE 308 - EE 308 Lecture 9

This preview shows page 1-2-3-24-25-26 out of 26 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 26 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 26 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 26 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 26 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 26 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 26 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 26 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

EE 308 Spring 2012Lecture 9February 6, 2012Writing Assembly Language Programs• Use flow charts to lay out structure of program• Use common flow structures– if-then– if-then-else– do-while– while• Plan structure of data in memory• Top-down Design– Plan overall structure of program– Work down to more detailed program structure– Implement structure with instructions• Optimize program to make use of instruction efficiencies• Do not sacrifice clarity for efficiency or speedInput and Output Ports• How to get data into and out of the MC9S121EE 308 Spring 2012Example Program: Divide a table of data by 2Problem: Start with a table of data. The table consists of 5 values, withthe first value at $1000. Each value is between 0 and 255. Create a newtable whose contents are the original table divided by 2. Start the new tableimmediately after the original table.1. Determine where code and data will go in memory.Code at $2000, data at $1000.2. Determine type of variables to use.Because data will be between 0 and 255, can use unsigned 8-bit numbers.3. Draw a pic ture of the data structures in memory:COUNTtable1:table2:$10002EE 308 Spring 20124. Strategy: Because we are using a table of data, we will need pointers toeach table so we can keep track of which table element we are workingon.Use the X and Y registers as pointers to the tables.5. Use a simple flow chart to plan structure of program.STARTDivideby 2StoreResultPointersIncInit EntryGetPointersCOUNTtable1table2XY3EE 308 Spring 20126. Need a way to determine when we reach the end of the table.One way: Use a counter (say, register A) to keep track of how manyelements we have processed.More?YESL1:NOSTARTSTOPDivideby 2StoreResultPointersIncInit EntryGetPointersCOUNTtable1table2XYInit CounterDecCounter4EE 308 Spring 20127. Add code to implement blocks:More?YESL1:NOLDAA #COUNTLDX #TABLE1LDY #TABLE2LDAB 0,XSTAB 0,YINXINYDECALSRB ; unsigned divideSTARTSTOPSWIBNE L1Divideby 2StoreResultPointersIncInit EntryGetPointersCOUNTtable1table2XYInit CounterDecCounter5EE 308 Spring 20128. Write program:; Program to divide a table by two; and store the results in memoryprog: equ $2000data: equ $1000count: equ 5org prog ;set program counter to 0x1000ldaa #count ;Use A as counterldx #table1 ;Use X as data pointer to table1ldy #table2 ;Use Y as data pointer to table2l1: ldab 0,x ;Get entry from table1lsrb ;Divide by two (unsigned)stab 0,y ;Save in table2inx ;Increment table1 pointeriny ;Increment table2 pointerdeca ;Decrement counterbne l1 ;counter != 0 => more entries to divideswi ;Doneorg datatable1: dc.b $07,$c2,$3a,$68,$F3table2: ds.b count6EE 308 Spring 20129. Advanced: Optimize program to make use of instructions set efficiencies:; Program to divide a table by two; and store the results in memoryprog: equ $1000data: equ $2000count: equ 5org prog ;set program counter to 0x1000ldaa #count ;Use B as counterldx #table1 ;Use X as data pointer to table1ldy #table2 ;Use Y as data pointer to table2l1: ldab 1,x+ ;Get entry from table1; then inc pointerlsrb ;Divide by two (unsigned)stab 1,y+ ;Save in table2; then inc pointerdbne a,l1 ;Decrement counter; if not 0, more to doswi ;Doneorg datatable1: dc.b $07,$c2,$3a,$68,$F3table2: ds.b count7EE 308 Spring 2012TOP-DOWN PROGRAM DESIGN• PLAN DATA STRUCTURES I N ME MORY• START WITH A LARGE PICTURE OF PROGRAM STRUCTURE• WORK DOWN TO MORE DETAILED STRUCTURE• TRANSLATE STRUCTURE INTO CODE• OPTIMIZE FOR EFFICENCY —DO NOT SACRIFICE CLARITY FOR EFFICIENCY8EE 308 Spring 2012Input and Output Ports• How do you get data into a computer from the outside?If TRI is active, the switch is closedOUT will be the same as INOUT INOUT INDDDDDDD03456120x00007Read fromSignalsFromOutsideLDAA $00Puts data from outsideinto accumulator A.Data from outside lookslike a memory locationgets signals from outsideAny read from address $0000A Tri−State Buffer acts like a switchOUT INTRIIf TRI is not active, the switch is openOUT will not be driven by INSome other device can drive OUTDDHC12DataLinesSIMPLIFIED INPUT PORT9EE 308 Spring 2012• How do you get data out of computer to the outside?DDDDDDDDD03456712Write toSignalsToOutside0x0001Any write to address $01 latchesdata into flip−flops, so datagoes to external pinsWhen a port is configured as outputand you read from that port, thedata you read is the data which wasLDAA $01MOVB #$AA,$01Accumulator A will have $AA after thiswritten to that port:MOVB #$AA,$01puts $AA on the external pinsHC12DataLinesD QD QD QD QD QD QD QD QSIMPLIFIED OUTPUT PORT10EE 308 Spring 2012• Most I/O ports on MC9S12 can be configured as either input or output7PAis an output port. Data written toD7DDRARead from Address 0x0000Write to Address 0x0000If Bit 7 of DDRA is 1, the portA read from address 0x0000 reads data on pinthrough tri−state bufferA write to address 0x0000 writes data to the flip−flopDDRA (Data Direction Register A) is located at 0x0002If Bit 7 of DDRA is 0, the portis an input port. Data written tothrough tri−state bufferflip−flop does not get to pin7flip−flop does get to pinD QSIMPLIFIED INPUT/OUTPUT PORT11EE 308 Spring 2012MC9S12DP256B Device User Guide — V02.1321Figure 1-1 MC9S12DP256B Block Diagram256K Byte Flash EEPROM12K Byte RAMEnhanced CaptureRESETEXTALXTALVDD1,2VSS1,2SCI04K Byte EEPROMBKGDR/WMODBXIRQNOACC/XCLKSSystemIntegrationModule(SIM)VDDRCPU12Periodic InterruptCOP WatchdogClock MonitorSingle-wire BackgroundBreakpointsPLLVSSPLLXFCVDDPLLMultiplexed Address/Data BusVDDAVSSAVRHVRLATD0MultiplexedWide BusMultiplexedVDDXVSSXInternal Logic 2.5VNarrow BusPPAGEVDDPLLVSSPLLPLL 2.5VIRQLSTRBECLKMODAPA4PA3PA2PA1PA0PA7PA6PA5TESTADDR12ADDR11ADDR10ADDR9ADDR8ADDR15ADDR14ADDR13DATA12DATA11DATA10DATA9DATA8DATA15DATA14DATA13PB4PB3PB2PB1PB0PB7PB6PB5ADDR4ADDR3ADDR2ADDR1ADDR0ADDR7ADDR6ADDR5DATA4DATA3DATA2DATA1DATA0DATA7DATA6DATA5DATA4DATA3DATA2DATA1DATA0DATA7DATA6DATA5PE3PE4PE5PE6PE7PE0PE1PE2AN2AN6AN0AN7AN1AN3AN4AN5PAD03PAD04PAD05PAD06PAD07PAD00PAD01PAD02IOC2IOC6IOC0IOC7IOC1IOC3IOC4IOC5PT3PT4PT5PT6PT7PT0PT1PT2VRHVRLVDDAVSSAVRHVRLATD1AN2AN6AN0AN7AN1AN3AN4AN5PAD11PAD12PAD13PAD14PAD15PAD08PAD09PAD10VDDAVSSARXDTXDMISOMOSIPS3PS4PS5PS0PS1PS2SCI1RXDTXDPP3PP4PP5PP6PP7PP0PP1PP2PIX2PIX0PIX1PIX3ECSPK3PK7PK0PK1XADDR17ECSXADDR14XADDR15XADDR16SCKSSPS6PS7SPI0IICSDASCLPJ6PJ7CAN0RXCANTXCANPM1PM0CAN1RXCANTXCANPM2PM3CAN2RXCANTXCANPM4PM5CAN3RXCANTXCANPM6PM7KWH2KWH6KWH0KWH7KWH1KWH3KWH4KWH5PH3PH4PH5PH6PH7PH0PH1PH2KWJ0KWJ1PJ0PJ1I/O Driver 5VVDDAVSSAA/D Converter 5V


View Full Document

NMT EE 308 - EE 308 Lecture 9

Documents in this Course
Load more
Download EE 308 Lecture 9
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view EE 308 Lecture 9 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view EE 308 Lecture 9 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?