DOC PREVIEW
NMT EE 308 - Disassembly of an HCS12 Program

This preview shows page 1-2-3-4-5 out of 14 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 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 14 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 14 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 14 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 14 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

EE 308 Spring 2003Disassembly of an HCS12 ProgramIt is sometimes useful to be able to convert HC12 op codes into mnemonics.For example, consider the hex code:ADDR DATA---- ---------------------------------------0800 C6 05 CE 09 00 E6 01 18 06 3FTo determine the instructions, use Opcode Map, Section 4.5 of Core UserGuide.– If the first byte of the instruction is anything other than $18, use Sheet1 of 2 (Page 97). From this table, determine the number of bytes ofthe instruction and the addressing mode. For example, $C6 is a two-byte instruction, the mnemonic is LDAB, and it uses the IMM addressingmode. Thus, the two bytes C6 05 is the op code for the instructionLDAB #$05. You can also see the number of CPU cycles.– If the first byte is $18, use Sheet 2 of 2 (Page 98), and do the same thing.For example, 18 06 is a two byte instruction, the mnemonic is ABA,and it uses the INH addressing mode, so there is no operand. Thus, thetwo bytes 18 06 is the op code for the instruction ABA.– Indexed addressing mode is fairly complicated to disassemble. You needto use Page 101 (4.8) of the User Core Guide to determine the operand.– For transfer (TFR) and exchange (EXG) instructions, use Page 99 (4.6) todetermine which registers are being used.Use up all the bytes for one instruction, then go on to the next instruction.C6 05 => LDAB #$05 two-byte LDAB, IMM addressing modeCE 09 00 => LDX #$0900 three-byte LDX, IMM addressing modeE6 01 => LDAB 1,X two to four-byte LDAB, IDX addressingmode. Operand 01 => 5b constant whichcorresponds to 1,X18 06 => ABA two-byte ABA, INH addressing mode3F => SWI one-byte SWI, INH addressing mode1EE 308 Spring 2003STARTOPERATIONENDCONDITIONAL BRANCHLABEL:YESNO2EE 308 Spring 2003Writing Assembly Language Programs — Use Flowcharts to Help Plan Program StructureFlow chart symbols:STARTOPERATIONENDCONDITIONAL BRANCHLABEL:YESNO3EE 308 Spring 2003IF-THEN Flow Structure CMPA #$10 BGE L2 LDAB #$5 STAB varL2:EXAMPLE: { var = 5;} CMPA #$10 BLT L1 BRA L2L1: LDAB #$5 STAB varOR: L2: next instruction next instructionIF (A<16)C?Aif (C){} A;FALSETRUEL1:L2:4EE 308 Spring 2003IF-THEN-ELSE Flow StructureL1:L2:{ var = 5;}else{ var = 0;} CMPA #$10 BLT L1L2: next instruction CLR VAR BRA L2L1: LDAB #$5 STAB varif (A<16)C?Aif (C){}else{} A; B;BFALSETRUE5EE 308 Spring 2003DO WHILE Flow StructureEXAMPLE:do{ table[i] = table[i]/2;}i = 0; i = i+1;while (i <= LEN); CLRA INCA CMPA #LEN BLE L1L1: ASR 0,X+ LDX #tableC?FALSEA{ A;}while (C);doTRUEL1:6EE 308 Spring 2003WHILE Flow StructureEXAMPLE:i = 0;while (i <= LEN){ table[i] = table[i]*2; i = i + 1;}L3:L1:L1: CMPA #$LEN BRA L3 INCA BRA L1L3: next instruction LDX #table CLRAL2: ASL 0,X+ BLE L2C?FALSEwhile (C){} A;AL1:TRUE7EE 308 Spring 2003Use Good Structure When Writing Programs — Do Not Use Spaghetti CodeSPAGHETTI CODEDO NOT USE8EE 308 Spring 2003Example Program: Divide a table of data by 2Problem: Start with a table of data. The table consists of 5 values. Each valueis between 0 and 255. Create a new table whose contents are the original tabledivided by 2.1. Determine where code and data will go in memory.Code at $1000, data at $2000.2. Determine type of variables to use.Because data will be between 0 and 255, can use unsigned 8-bit numbers.3. Draw a picture of the data structures in memory:COUNTtable1:table2:$20009EE 308 Spring 20034. Strategy: Because we are using a table of data, we will need pointers to eachtable so we can keep track of which table element we are working on.Use the X and Y registers as pointers to the tables.5. Use a simple flow chart to plan structure of program.STARTDivideby 2StoreResultPointersIncInit EntryGetPointersCOUNTtable1table2XY10EE 308 Spring 20036. 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 many elementswe have processed.More?YESL1:NOSTARTSTOPDivideby 2StoreResultPointersIncInit EntryGetPointersCOUNTtable1table2XYInit CounterDecCounter11EE 308 Spring 20037. Add code to implement blocks:More?YESL1:NOLDAA #COUNTLDX #TABLE1LDY #TABLE2LDAB 0,XSTAB 0,YINXINYDECALSRB ; unsigned divideSTARTSTOPSWIBNE L1Divideby 2StoreResultPointersIncInit EntryGetPointersCOUNTtable1table2XYInit CounterDecCounter12EE 308 Spring 20038. Write program:; Program to divide a table by two; and store the results in memoryprog: equ $1000data: equ $2000count: equ 5CODE: section .text ;The stuff which follows is program codeorg prog ;set program counter to 0x0800ldaa #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 ;DoneDATA: section .data ;The stuff which follows is dataorg datatable1: dc.b $07,$c2,$3a,$68,$F3table2: ds.b count13EE 308 Spring 20039. 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 5CODE: section .text ;The stuff which follows is program codeorg prog ;set program counter to 0x0800ldaa #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 table1; then inc pointerlsrb ;Divide by two (unsigned)stab 0,y+ ;Save in table2; then inc pointerdbne a,l1 ;Decrement counter; if not 0, more to doswi ;DoneDATA: section .data ;The stuff which follows is dataorg datatable1: dc.b $07,$c2,$3a,$68,$F3table2: ds.b countTOP-DOWN PROGRAM DESIGNPLAN DATA STRUCTURES IN MEMORY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


View Full Document

NMT EE 308 - Disassembly of an HCS12 Program

Documents in this Course
Load more
Download Disassembly of an HCS12 Program
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 Disassembly of an HCS12 Program 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 Disassembly of an HCS12 Program 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?