Address Register Indirect with Displacement: d(An) - PowerPoint PPT Presentation

libitha
address register indirect with displacement d an l.
Skip this Video
Loading SlideShow in 5 Seconds..
Address Register Indirect with Displacement: d(An) PowerPoint Presentation
Download Presentation
Address Register Indirect with Displacement: d(An)

play fullscreen
1 / 23
Download Presentation
Address Register Indirect with Displacement: d(An)
319 Views
Download Presentation

Address Register Indirect with Displacement: d(An)

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Address Register Indirect with Displacement: d(An) Frequently we package data in blocks, where each block represents a single logical entity =object HLLs provide therecord = class = structures Class Results { int StudentNumber; byte 1ba1Mark; byte 1ba2Mark; byte 1ba3Mark; byte 1ba4Mark; byte 1ba5Mark; byte 1ba6Mark; }; 1BA3 – G Lacey – Lecture 23

  2. Address Register Indirect with Displacement: d(An) In the case of 68000 assembly language, such a construct does not exist directly. An addressing mode is provided to make it easy to implement records. To determine the actual memory location addressed by d(An), we add the displacement d to the current contents of An. movea.l #$4100,a0 move.b 8(a0),d0 -> Byte value stored at $4108 is loaded into d0. 1BA3 – G Lacey – Lecture 23

  3. Negative Displacement We can also specify negative displacement: movea.l #$4108,a0 move.b -4(a0),d0 In this case, the byte at $4104 is loaded into d0. The displacement is sign-extended before adding to the 32-bit address in a0. The displacement is a 16-bit value -> has a signed range of -32768 to +32767 1BA3 – G Lacey – Lecture 23

  4. How do we use this to implement records? Consider how a number of records will be arranged in memory: 1BA3 – G Lacey – Lecture 23

  5. Access individual elements of the record Use an address register to point to the start of the record, and use displacement values to access individual elements of the record: movea.l #$4108,a0 *start of record move.w 0(a0),d0 *StudentNumber move.b 2(a0),d1 *1ba1Mark move.b 6(a0),d2 *1ba5Mark 1BA3 – G Lacey – Lecture 23

  6. Use of the equ directive: To make this easier you could use the equ directive: SNUM equ 0 1BA1 equ 2 1BA2 equ 3  1BA6 equ 7 movea.l #$4108,a0 *record start move.w SNUM(a0),d0 *StudentNumber move.b 1BA1(a0),d1 *1ba1Mark move.b 1BA2(a0),d2 *1ba5Mark 1BA3 – G Lacey – Lecture 23

  7. If we have a list of these records in memory: • Address register points to the start of the records. • Displacement accesses individual elements. • Add number of bytes in the record to the address register to skip to the next record in memory. movea.l #$4100,a0 *1st record move.b 4(a0),d1 *1ba3 mark #1 adda.l #8,a0 *2nd record move.b 4(a0),d2 *1ba3 mark #2 1BA3 – G Lacey – Lecture 23

  8. Address Register Indirect with Index and Displacement: d(An,Xi.s) • The most flexible addressing mode. Is usually used to implement high level data structures (list/arrays of records). • d: an 8-bit signed displacement • An: any address register • Xi.s: either a data or address register of size: • s = {w/l} 1BA3 – G Lacey – Lecture 23

  9. The address of the data is obtained using: Address of operand = sign extended d + contents of An + contents of Xi.s (sign extended if s=w) Example: movea.l $4100,a0 move.w $fffe,d0 move.b 8(a0,d0.w),d1 1BA3 – G Lacey – Lecture 23

  10. What is the address of the data moved into d1? Address = $fffffffe (d0.w sign-extended) $00004100 (a0) $00000008 (d sign- extended) $00004106 1BA3 – G Lacey – Lecture 23

  11. Two Pointers When an address register points to the start of a list of records the 2nd register is used to index into the list of records; movea.l #$4100,a0 *list start move.w #0,d0 *1st record move.b 4(a0,d0.w),d1 *1ba3 mark #1 add.l #8,d0 *2nd record move.b 4(a0,d0.w),d2 *1ba3 mark #2 1BA3 – G Lacey – Lecture 23

  12. Program Counter with Displacement d(PC) • Modes involving the program counter are rarely used. • This mode is provided to allow full position-independence in the code. 1BA3 – G Lacey – Lecture 23

  13. Program Counter with Displacement and Index d(PC,Xi.s) This is the same as d(An,Xi.s) except the current value of the PC is used instead of the An register. 1BA3 – G Lacey – Lecture 23

  14. Example: 4000 6039 0001 move.b #1,d1 4004 103a 0002 move.b 2(PC),d0 4008 143b 1002 move.b 2(PC,d1.w),d2 400c 4e75 rts What are the contents of the d0 and d2 register after program execution? d0 = $14d2 = $75 Remember: The PC is incremented by 2 after the opcode is fetched. 1BA3 – G Lacey – Lecture 23

  15. Addressing Modes: Now you have seen all the addressing modes, and should fully understand the meaning of the source and destination field mode bits found in the instruction data-sheets. 1BA3 – G Lacey – Lecture 23

  16. Example: the move source effective address field Data Register Direct Address Register Direct Address Register Indirect (An) (An) with Post-increment (An) with Pre-decrement (An) with Displacement (An) with Displacement & Index Absolute short Address Absolute long Address (PC) with Displacement (PC) with Displacement & Index Immediate 1BA3 – G Lacey – Lecture 23

  17. Useful Instructions LEA We frequently use: movea.l #addr,an The 68000 provides an instruction to allow loading of addresses into address register: lea $4100,a0 move.w (a0),d0 There is no size field specified -> long operands only 1BA3 – G Lacey – Lecture 23

  18. Be Careful (LEA) The <ea> field of the lea instruction is restricted to an operant which is an address (-(An) and (An)+ not allowed). d0 is not an address -> following instruction is not allowed! lea d0,a0 The lea instruction is fundamentally different from the movea instruction. 1BA3 – G Lacey – Lecture 23

  19. More LEA Both the following instructions are the same: movea.l #$4100,a0 lea $4100,a0 But the following 2 instructions are not the same: movea.l (a1),a0 lea (a1),a0 • The first loads the long-word stored in memory at the location specified in a1 into a0. The second loads the effective address of (a1) into An. • movea moves the contents of the operand into An. • lea moves the effective address into An. 1BA3 – G Lacey – Lecture 23

  20. CMPM Most useful for comparing blocks of data, -> address register indirect with post increment mode only is allowed. 1BA3 – G Lacey – Lecture 23

  21. CMPM Example lea $4100,a0 *p1=1st list lea $4200,a1 *p2=2nd list move.w #16,d0 *count=16 do_wh *do cmpm.b (a0)+,(a1)+ * count-- dbeq d0,do_wh *while count!=0 * and (p1)=(p2) cmp #0,d0 *if Count=0 then bne else move.w #1,d1 * Result=True bra endif *else else move.w #0,d1 * Result=False endif rts 1BA3 – G Lacey – Lecture 23

  22. CLR Used to clear locations (set to zero): clr.b d0 clr.l (a0)+ Note it is not permitted to clear an address register the way. The lea instruction should be used: clr.l a0 * wrong lea 0,a0 * correct 1BA3 – G Lacey – Lecture 23

  23. CCR After X N Z V C 0 0 1 0 1 Move to/from CCR • Useful to be able the set contents of the CCR flags: • To circumvent normal flow control • Or as a way of specifying results on exit from a program move.w #$05,CCR move.w CCR,d0 • Any source mode may be used except An • Both form allows word size operations only. 1BA3 – G Lacey – Lecture 23