DOC PREVIEW
NMT EE 308 - Assembling an Assembly Language Program

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

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

Unformatted text preview:

EE 308 Spring 2011 • Addition and Subtraction of Hexadecimal Numbers • Simple assembly language programming • Huang, Section 2.2 • HC12 Addressing Modes • Huang, Sections 1.6 and 1.7 o A simple Assembly Language Program o Assembling an Assembly Language Program o Simple 9S12 programs o Hex code generated from a simple 9S12 program o Things you need to know for 9S12 assembly language programming o HC12 Addressing Modes o Inherent, Extended, Direct, Immediate, Indexed, and Relative Modes o Summary of 9S12 Addressing Modes Assembling an Assembly Language Program • A computer program called an assembler can convert an assembly language program into machine code. • The assembler we use in class is a commercial compiler from Freescale called CodeWarrior. •How to use CodeWarrior is discussed in Lab 1 and in Huang. • The assembler will produce a file called main.lst, which shows the machine code generated.EE 308 Spring 2011 Freescale HC12-Assembler (c) Copyright Freescale 1987-2009 Abs. Rel. Loc Obj. code Source line ---- ---- ------ --------- ----------- 1 1 2 2 0000 2000 prog equ $2000 ; Start program at 0x2000 3 3 0000 1000 data equ $1000 ; Data value at 0x1000 4 4 5 5 org prog 6 6 7 7 a002000 B610 00 ldaa input 8 8 a002003 42 inca 9 9 a002004 7A10 01 staa result 10 10 a002007 3F swi 11 11 12 12 org data 13 13 a001000 A2 input: dc.b $A2 14 14 a001001 result: ds.b 1 This will produce a file called Project.abs.s19. S06B0000433A5C446F63756D656E747320616E642053657474696E6773 S1051000A20048 S10B2000B61000427A10013F02 S9030000FC We can load into the MC9S12. S1051000A20048 S10B2000B61000427A10013F02 S9030000FC • The first line of the S19 file starts with a S0: the S0 indicates that it is the first line. • The last line of the S19 file starts with a S9: the S9 indicates that it is the last line. • The other lines begin with a S1: the S1 indicates these lines are data to be loaded into the MC9S12 memory.EE 308 Spring 2011 • Here is the second line (with some spaces added): S1 0B 2000 B6 1000 42 7A 1001 3F 02 • On the second line, the S1 if followed by a 0B. This tells the loader that there this line has 11 (0x0B) bytes of data follow. • The count 0B is followed by 2000. This tells the loader that the data (program) should be put into memory starting with address 0x2000. • The next 16 hex numbers B61000427A10013F are the 8 bytes to be loaded into memory. You should be able to find these bytes in the main.lst file. • The last two hex numbers, 0x02, is a one byte checksum, which the loader can use to make sure the data was loaded correctly. Freescale HC12-Assembler (c) Copyright Freescale 1987-2009 Abs. Rel. Loc Obj. code Source line ---- ---- ------ --------- ----------- 1 1 2 2 0000 2000 prog equ $2000 ; Start program at 0x2000 3 3 0000 1000 data equ $1000 ; Data value at 0x1000 4 4 5 5 org prog 6 6 7 7 a002000 B610 00 ldaa input 8 8 a002003 42 inca 9 9 a002004 7A10 01 staa result 10 10 a002007 3F swi 11 11 12 12 org data 13 13 a001000 A2 input: dc.b $A2 14 14 a001001 result: ds.b 1EE 308 Spring 2011 What will program do? • ldaa input : Load contents of 0x1000 into A (0xA2 into A) • inca : Increment A (0xA2 + 1 = 0xA3 -> A) • staa result : Store contents of A to address 0x1001 (0xA3 -> adress 0x1001) • swi : Software interrupt (Return control to DBug-12 Monitor) Simple Programs for the MC9S12 A simple MC9S12 program fragment org $2000 ldaa $1000 staa $1001 A simple MC9S12 program with assembler directives prog: equ $2000 data: equ $1000 org prog ldaa input asra staa result swi org data input: dc.b $07 result: ds.b 1EE 308 Spring 2011 MC9S12 Programming Model — The registers inside the MC9S12 CPU the programmer needs to know about Things you need to know to write MC9S12 assembly language programs HC12 Assembly Language Programming Programming Model MC9S12 Instructions Addressing Modes Assembler Directives Addressing Modes for the HCS12 • Almost all HCS12 instructions operate on memory • The address of the data an instruction operates on is called the effective address of that instruction. • Each instruction has information which tells the HCS12 the address of the data in memory it operates on. • The addressing mode of the instruction tells the HCS12 how to figure out the effective address for the instruction.EE 308 Spring 2011 • Each HCS12 instructions consists of a one or two byte op code which tells the HCS12 what to do and what addressing mode to use, followed, when necessary by one or more bytes which tell the HCS12 how to determine the effective address. – All two-byte op codes begin with an $18. • For example, the LDAA instruction has 4 different op codes, one for each of the 4 different addressing modes.EE 308 Spring 2011 The HCS12 has 6 addressing modes Most of the HC12’s instructions access data in memory There are several ways for the HC12 to determine which address to access Effective address: Memory address used by instruction Addressing mode: How the HC12 calculates the effective address HC12 ADDRESSING MODES: INH Inherent IMM Immediate DIR Direct EXT Extended REL Relative (used only with branch instructions) IDX Indexed (won’t study indirect indexed mode)EE 308 Spring 2011 The Inherent (INH) addressing mode Instructions which work only with registers inside ALU ABA ; Add B to A (A) + (B) → A 18 06 CLRA ; Clear A 0 → A 87 ASRA ; Arithmetic Shift Right A 47 TSTA ; Test A (A) − 0x00 Set CCR 97 The HC12 does not access memory There is no effective addressEE 308 Spring 2011 The Extended (EXT) addressing mode Instructions which give the 16−bit address to be accessed LDAA $1000 ; ($1000) → A B6 10 00 Effective Address: $1000 LDX $1001 ; ($1001:$1002) → X FE 10 01 Effective Address: $1001 STAB $1003 ; (B) → $1003 7B 10 03 Effective Address: $1003 Effective address is specified by the two bytes following op codeEE 308 Spring 2011 The Direct (DIR) addressing mode Direct (DIR) Addressing Mode Instructions which give 8 LSB of address (8 MSB


View Full Document

NMT EE 308 - Assembling an Assembly Language Program

Documents in this Course
Load more
Download Assembling an Assembly Language 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 Assembling an Assembly Language 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 Assembling an Assembly Language 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?