Lecture07 - 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 Seven: • Memory Addressing Modes • Strings • MOVsize Addressing Modes (HCS12) • Each mode allows a different type of operand (M) – – – – – – – – – – – – – • Immediate Register Direct (Inherent) Memory Direct (Direct; Extended) Register Indirect (Indexed) Register Indirect with Displacement (Indexed) Register Indirect with Index (Indexed) Register Indirect Post-decrement (Indexed) Register Indirect Post-increment (Indexed) Register Indirect Pre-decrement (Indexed) Register Indirect Pre-increment (Indexed) Memory Indirect from Register Indirect with Displacement (Indexed Indirect) Memory Indirect from Register Indirect with Index (Indexed Indirect) Relative (branch instructions are PC-relative) Each instruction may allow different addressing modes 2 Immediate Addressing • Operand: #opr8 or #opr16 – Specified as part of instruction • Value coded into machine instruction • No memory access other than instruction – Constant – Only valid for data source • Immediate source operand examples ldaa addd ora Cpd #25 #$C036 #%0010000 #16384 3 Register Direct Addressing (Inherent) • Operand: abcdxys – Contents of register • Register encoded into machine instruction aba sba asla exg D a,b – More flexible than immediate • Variable content • Fixed location CPU X Y SP Registers – Data: R[abcdxys] 4 Memory Direct Addressing • Operand: opr8 (direct) or opr16 (extended) – Specified by actual address • Encoded into machine instruction • Numeric¾address lda ldd 102 NumB 104 NumC 106 NumD 108 NumE $10 $2200 10A NumF • Symbolic¾label EQU $100 addd X std NumD MyData: SECTION NumD: DS.W 1 100 NumA Memory X: ;Here MyData maps to $100 – Data: M[opr8] or M[opr16] 5 Register Indirect Addressing (Indexed) 100 NumA • Operand: (xysp) 102 NumB – Specified by address in register – More flexible than absolute 104 NumC 106 NumD 108 NumE • Variable content residing at • Variable address 10A NumF Memory – Example ldx ldy ldd addd #$104 #NumF ,x ,y X ;NumC ;NumF – Data: M[R[xysp]] CPU Y SP PC Index Registers 6 Register Indirect with Displacement Addressing (Indexed) • Operand: (opr5,xysp), (opr9,xysp), or (opr16,xysp) 100 NumA 102 NumB – Specified by two components 104 NumC 106 NumD • Base address in index register • Signed displacement (i.e., constant offset) 108 NumE 10A NumF – More flexible than register indirect • Variable content residing at • Variable address with offset -4 – Example ldx ldd addd Memory + CPU #$108 -4,x 2,x ; &NumE ; D ß NumC ; D ß D + NumF – Data: M[R[xysp]+opr] X Y SP PC Index Registers 7 Register Indirect with Index Addressing (Indexed) • Operand: (abd,xysp) 100 NumA – Specified by two components 102 NumB • Base address in index register • Unsigned displacement in accumulator 104 NumC 106 NumD – More flexible than register indirect 108 NumE 10A NumF • Variable content residing at • Variable address with variable offset – Example ldx lda ldab #$100 #4 a,x A B ;NumC – Data: M[R[xysp]+R[abd]] D Memory + CPU X Y SP PC Accumulator Index Registers 8 Register Indirect Addressing with Automatic Post-decrement (Indexed) • Operand: opr3,(xys) 100 NumA – Specified by address in register – Register decremented after by 1 to 8 – More flexible than absolute • Variable content residing at • Variable pre-decremented address #$104 2,x- addd 2,x- 104 NumC 106 NumD 108 NumE 10A NumF Memory – Example ldx ldd 102 NumB X ;D ;X ;D ;X ß ß ß ß Data: M[R[xys]] NumC X - 2 D + NumB X – 2 CPU Y SP Index Registers 9 Register Indirect Addressing with Automatic Post-increment (Indexed) • Operand: opr3,(xys) 100 NumA – Specified by address in register – Register incremented after by 1 to 8 – More flexible than absolute • Variable content residing at • Variable pre-decremented address #$104 2,x+ addd 2,x+ 104 NumC 106 NumD 108 NumE 10A NumF Memory – Example ldx ldd 102 NumB X ;D ;X ;D ;X ß ß ß ß Data: M[R[xys]] NumC X + 2 D + NumD X – 2 CPU Y SP Index Registers 10 Register Indirect Addressing with Automatic Pre-decrement (Indexed) • Operand: opr3,(xys) 100 NumA – Decrement register by 1 to 8 – Specified by new address in register – More flexible than absolute • Variable content residing at • Variable pre-decremented address #$106 2,-x addd 2,-x 104 NumC 106 NumD 108 NumE 10A NumF Memory – Example ldx ldd 102 NumB X ;X ;D ;X ;D ß ß ß ß X - 2 NumC X – 2 D + NumB Data: M[R[xys]-opr3] CPU Y SP Index Registers 11 Register Indirect Addressing with Automatic Pre-increment (Indexed) • Operand: opr3,(xys) 100 NumA – Increment register by 1 to 8 – Specified by new address in register – More flexible than absolute • Variable content residing at • Variable pre-decremented address #$102 2,+x addd 2,+x 104 NumC 106 NumD 108 NumE 10A NumF Memory – Example ldx ldd 102 NumB X ;X ;D ;X ;D ß ß ß ß X + 2 NumC X + 2 D + NumD Data: M[R[xys]+opr3] CPU Y SP Index Registers 12 Memory Indirect from Register Indirect with Displacement (Indexed Indirect) • Operand: ((opr16,xysp)) 100 NumA – Memory address for data is in memory 102 NumB • Base address in index register • Signed displacement (i.e., constant offset) 104 NumC 106 NumD – More flexible than register indirect NumC • Variable content residing at • Variable address with offset – Example ldx #$106 ; &NumD ldd [-2,x] ; D ß M[NumC] ;same as ldy -2,x ; ldd ,y – Data: MM[[R[xysp]+opr]] Data Memory -2 + CPU X Y SP PC Index Registers 13 Memory Indirect from Register Indirect with Index (Indexed Indirect) • Operand: (d,xysp) 100 NumA – Memory address for data is in memory 102 NumB • Base address in index register • Unsigned displacement in accumulator D 104 NumC 106 NumD – More flexible than register indirect • Variable content residing at • Variable address with variable offset – Example ldx ldd ldab ;same ; #$100 #4 [d,x] ;M[NumC] as ldy d,x ldab ,y – Data: MM[[R[xysp]+R[abd]]] D NumC Data Memory + CPU X Y SP PC Accumulator Index Registers 14 String • Array of bytes—ASCII codes • Used extensively for I/O – Prompt output to user – Response input from user • Typically sequential access Individual bytes (characters) 15 String Example Problem • Create a string of the first n characters of the alphabet • n Î [1, 26] is stored in variable N • String created will be stored in memory starting at address with label STRING 16 String Example One #define LETTERS (26) char char int8 int8 Letter; String[LETTERS]; Index; N = LETTERS; Letter = ‘A’; for (Index=0; Index<N; Index++) { STRING[Index] = Letter++; } ; A: Letter ; X: Pointer to STRING ; B: Index LETTERS: EQU 26 Init: ldaa #LETTERS staa N ldaa #’A’ ldx #String ForInit: clrb ForCond: cmpb N bge ForEnd ForBody: staa ,x adda #1 inx ForStep: addb #1 bra ForCond ForEnd: ; . . . Done: bra * MyData: SECTION String DS.B 26 N DS.B 1 17 MOVSize Source,Destination S12CPUV2 Reference Manual, p. 58 18 MOV Source,Destination S12CPUV2 Reference Manual, p. 236 19 String Example One v.2 #define LETTERS (26) char char int8 int8 Letter; String[LETTERS]; Index; N = LETTERS; Letter = ‘A’; for (Index=0; Index<N; Index++) { STRING[Index] = Letter++; } ; A: Letter ; X: Pointer to STRING ; B: Index LETTERS: EQU 26 movb ldaa ldx #LETTERS,N #’A’ #String ForInit: clrb ForCond: cmpb bge N ForEnd staa inca b,x ForBody: ForStep: ForEnd: Done: incb bra ForCond ; . . . bra * MyData: String N SECTION DS.B 26 DS.B 1 20 ...
View Full Document

Ask a homework question - tutors are online