lecture03 - 0306-250 Assembly Language Programming Lecture...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 0306-250 Assembly Language Programming Lecture Three: Memory • Assembler Memory Directives • Memory Maps • Examples HCS12 Assembler Directive Syntax [Label] Directive[.Size] Parameter • Label: optional name (beginning with a letter) Format Suggestions – Left margin • Directive: assembler instruction Format Suggestions – Tabbed to left-align with instructions – Upper case • Parameter: immediate value 2 DC: Define Constant Label DC. Size Constant[, Constant[,. . .]] • Puts constant(s) in memory • Label: Equates to address in memory where constant is placed • Size: B (byte), W (word), or L (long) • Constant: Actual value to store in memory 3 DS: Define Storage Label DS. Size NumberPlaces • Allocates storage in memory • Label: Equates to address in memory where constant is placed • Size: B (byte), W (word), or L (long) • NumberLocations: Number of places of size Size 4 Memory Map • Graphical illustration of memory contents/allocation • One block/cell per memory unit – Byte Be careful with unit! – Word – Long • Contents inside cell (usually in hex) • Addresses outside cell (usually in hex) 5 DC Memory Maps MyConst: SECTION A DC.B 10,3 B DC.W 4 C DC.B 9 D DC.B 2 E DC.L 5 F DC.B 'ABC' Assumption: linker maps MyConst to memory address $60 Byte Memory Map 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 0A 03 00 04 09 02 00 00 00 05 41 42 43 A B C D E F Word Memory Map 60 62 64 66 68 6A 6C 0A03 0004 0902 0000 0005 4142 43-- Note: Memory contents shown in hexadecimal 6 DS Memory Maps Byte Memory Map MyData: SECTION P DS.B 6 Q DS.W 2 R DS.B 2 S DS.L 1 Assumption: linker maps MyData to memory address $200 200 201 202 203 204 205 206 207 208 209 20A 20B 20C -------------- 20D -- 20E -- 20F -- P Word Memory Map Q 200 202 204 206 208 20A 20C 20E ------------------------- P Q R S R S 7 Arithmetic Expression v.1 • Compute 13 - 16 + 2 ´ 12 + 3 ´ 7 – – – Each term for addition or subtraction must be in a register Use immediate values in instructions Only byte operations can be used ; 13 – 16 ldaa #13 ldab #16 sba ; 13 - 16 + 2 x 12 ldab #12 aslb aba ; 13 - 16 + 2 x 12 + 3 x 7 ldab #7 aslb addb #7 aba ; 13 ; 16 ; subtract ; 12 ; 2 x 12 ; add ; ; ; ; 7 2 x 7 3 x 7 add 8 Arithmetic Expression v.2 • Compute 13 - 16 + 2 ´ 12 + 3 ´ 7 – – – Each term for addition or subtraction must be in a register Use EQUate values in instructions Only byte operations can be used NUMBER1: NUMBER2: NUMBER3: NUMBER4: ; 13 – 16 EQU EQU EQU EQU 13 16 12 7 ldaa #NUMBER1 ldab #NUMBER2 sba ; 13 - 16 + 2 x 12 ldab #NUMBER3 aslb aba ; 13 - 16 + 2 x 12 + 3 x 7 ldab #NUMBER4 aslb addb #NUMBER4 aba ; 13 ; 16 ; subtract ; 12 ; 2 x 12 ; add ; ; ; ; 7 2 x 7 3 x 7 add 9 Arithmetic Expression v.3 • Compute Result = 13 - 16 + 2 ´ 12 + 3 ´ 7 – – – – Each term for addition or subtraction must be in a register Get values from constants in memory Store result to variable in memory Only byte operations can be used ; 13 – 16 ldaa number1 ldab number2 sba ; 13 - 16 + 2 x 12 ldab number3 aslb aba ; 13 - 16 + 2 x 12 + 3 x 7 ldab number4 aslb addb number4 aba staa Result ; 13 ; 16 ; subtract ; 12 ; 2 x 12 ; add ; ; ; ; ; 7 2 x 7 3 x 7 add store ;********************** ; Constants MyConst: SECTION number1: DC.B 13 number2: DC.B 16 number3: DC.B 12 number4: DC.B 7 ;********************** ; Variables MyData: SECTION Result: DS.B 1 END 10 ...
View Full Document

This note was uploaded on 05/06/2010 for the course EECC 0306-250 taught by Professor Roymelton during the Fall '10 term at RIT.

Ask a homework question - tutors are online