Address register indirect with displacement d an
Download
1 / 23

Lecture 23 - PowerPoint PPT Presentation


  • 284 Views
  • Uploaded on

Address Register Indirect with Displacement: d(An) Frequently we package data in blocks, where each block represents a single logical entity = object HLLs provide the record = class = structures Class Results { int StudentNumber; byte 1ba1Mark; byte 1ba2Mark; byte 1ba3Mark;

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Lecture 23' - libitha


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Address register indirect with displacement d an l.jpg
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


Address register indirect with displacement d an2 l.jpg
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


Negative displacement l.jpg
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


How do we use this to implement records l.jpg
How do we use this to implement records?

Consider how a number of records will be arranged in memory:

1BA3 – G Lacey – Lecture 23


Access individual elements of the record l.jpg
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


Use of the equ directive l.jpg
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


If we have a list of these records in memory l.jpg
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


Address register indirect with index and displacement d an xi s l.jpg
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


The address of the data is obtained using l.jpg
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


What is the address of the data moved into d1 l.jpg
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


Two pointers l.jpg
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


Program counter with displacement d pc l.jpg
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


Program counter with displacement and index d pc xi s l.jpg
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


Example l.jpg
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


Addressing modes l.jpg
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


Example the move source effective address field l.jpg
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


Useful instructions l.jpg
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


Be careful lea l.jpg
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


More lea l.jpg
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


Slide20 l.jpg
CMPM

Most useful for comparing blocks of data, -> address register indirect with post increment mode only is allowed.

1BA3 – G Lacey – Lecture 23


Cmpm example l.jpg
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


Slide22 l.jpg
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


Move to from ccr l.jpg

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


ad