Re: A92: serious help here please


[Prev][Next][Index][Thread]

Re: A92: serious help here please




Getting back to the original question regarding certain addressing modes
not being understood...

    (d16,An)
    (d8,An,Xn)
    (d16,PC)
    (d8,PC,Xn)

I noticed that Aaron posted addressing modes for the 68020 and greater
processors so you can ignore the part about "*SCALE"...the 68000 does
not accept this as part of its addressing modes (although I wish it did
;-).

Ok...most 68000 assemblers should accept the following format, which is
slightly different from the above (notice that the "displacement" value
is normally outside of the parentheses...the 68020 and higher have
slightly different, additional addressing modes where the displacement
is within them):

    d16(An)           - Indirect Addressing w/ 16-bit Displacement
    d8(An,Xn.size)    - Indirect Indexed Addressing w/ 8-bit
Displacement
    d16(PC)           - PC Relative w/ 16-bit Displacement
    d8(PC,Xn.size)    - PC Relative Indexed w/ 8-bit Displacement

let me set up the definitions, then I'll elaborate...

    d8 = 8-bit signed displacement (has a value from -128 to +127
decimal)
    d16 = 16-bit signed displacement (has a value from -32768 to +32767
decimal)
    An = any address register where 'n' is the register number (eg- A1)
    Xn = any register...this may be an address or a data register...you
decide
    PC = Program Counter (use this form to write "relocatable" code)
    .size = allowable sizes for Xn are .W and .L (note: .W is sign
extended)

ok...here's how the 68000 computes the effective address for d16(An) and
d16(PC) modes:

    ( 1 )  The contents of the An or PC register is taken as the BASE
address pointer
    ( 2 )  The DISPLACEMENT value is then added to the BASE address
pointer
    ( 3 )  The 68000 accesses the memory location pointed to by BASE +
DISPLACEMENT

    note: the DISPLACEMENT lets you access up to 32K before or after the
base pointer

and...here's how the 68000 computes the effective address for
d8(An,Xn.size) and d8(PC,Xn.size) modes:

    ( 1 )  The contents of the An or PC register is taken as the BASE
address pointer
    ( 2 )  The DISPLACEMENT value is then added to the BASE address
pointer
    ( 3 )  The contents of the Xn.size register is also added to the
pointer
    ( 4 )  The 68000 accesses the memory location pointed to by BASE +
DISPLACEMENT + INDEX

    note: the DISPLACEMENT is very small allowing a -128/+127 byte range

    note: if .size = .W then the index is sign extended (allows
-32768/+32767 range)
          if .size = .L then the range is -2147483648/+2147483647 bytes
            ( watch your binary arithmetic!! Xn.L has a 32-bit range,
but only 24-bits
              are used to compute the address )

an example using this, you say... (I'm not versed w/ A68K, so bear with
me)


    ; define structure of an address-book record

addName:      EQU    0        ; text of name appears first ... allow 40
bytes
addAdd:       EQU    40       ; street address is next     ... allow 30
bytes
addApt:       EQU    70       ; apartment/suite number     ... allow 8
bytes
addCity:      EQU    78       ; text of city name          ... allow 20
bytes
addState:     EQU    98       ; text of state inits        ... allow 2
bytes
addZip:       EQU    100      ; zip code                   ... allow 5
bytes
addPhone:     EQU    105      ; phone number               ... allow 10
bytes
add_sizeof:   EQU    115      ; the total size of one address-book entry

    ; let's pretend we've got 100 of these records in memory and we have
the
    ; following subroutine to return a pointer to the address field of
any
    ; record in memory (note: all of these records are in one continuous

    ; piece of memory, one record right after the other).


;------------------------------------------------------------------------------------

    ; FindAddress - a subroutine to find the address field of a select
record
    ;
    ; Inputs:  A0.L = pointer to start of first record (the base address
of everything)
    ;          D0.W = a record number ( 1 to 100 )
    ;
    ; Outputs: A0.L = pointer to the address field of the requested
record number
    ;
FindAddress:  SUBQ.W  #1,D0                ; convert 1-100 range -->
0-99 range
              EXT.L   D0                   ; convert 16-bit to 32-bit
value
              MULU.W  #add_sizeof,D0       ; compute "offset" to start
of requested record
              LEA.L   addAdd(A0,D0.L),A0   ; A0 = base + record_offset +
field_offset
              RTS                          ; return to caller with A0
pointing where it should

In that example the d8(An,Xn.size) mode was used:
    d8 = "addAdd" the displacement from the start of a record to the
street address field
    An = a pointer that points to the first byte of 100 records in
memory
    Dn = an index (when added to An becomes a pointer to the first byte
of a specific record)

The displacement is always present (even if it is zero).

Now for your other question:

> if you had the following:
> a0=$0002
> d0=$0004
> d1=$0006
> $0006=#8
> $0016=#10
> would "ADD 16(a0,d0),d1" be:
> a) d1=30    (16+indirect(a0+d0)+d1)
> b) d1=16    (indirect(a0+d0+16)+d1)
> and if the answer is (b) then why is 16 outside parentheses?

With the registers as you have them defined, an equivilant statement
would be:

    ADD 16+2+4,D1  -> which is ->  ADD $16,D1  -> which yields D1=16 (b)

I hope that helps you understand how it works and from my example why it
might be useful.
Once you learn to let the assembler do all of the work for you, you can
write some fairly
elegant and structured assembly language code.  After you gain a bit of
experience with
assembly language, you'll really begin to appreciate the "symbolic" in
Symbolic Assembler.

TTFN - ta ta for now.
=====================
Keith Kirton
kkirton@acex.com