Welcome, Guest. Please login or register.

Author Topic: Assembler (68k) help (about dc pseudo op)  (Read 26613 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline xeron

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 2533
    • Show all replies
    • http://www.petergordon.org.uk
Re: Assembler (68k) help (about dc pseudo op)
« on: January 13, 2003, 05:25:22 PM »
Kronos explained it all quite well, I just wanted to add the following:

If you want to make sure some data is on an even boundary, (ie address ends in 0, 2, 4, 6 etc.) you can do this:

[color=000099]    even
marker:
    dc.l 0
[/color]

And if you want it on a longword boundary (IE ends in 0, 4, 8 or a), you can do this:

[color=000099]    cnop 0,4
marker:
    dc.l 0
[/color]

Also, what I tend to do is pick an address register, and reference all my variable like this:

[color=000099]    lea    my_vars(pc),a4
    move.w #123,my_word(a4)
    move.l #123,my_long(a4)
    rts

               rsreset
my_word        rs.w 1
my_long        rs.l 1
my_vars_length rs.b 0

my_vars        ds.b my_vars_length
[/color]

A little explanation:

"rsreset" resets a pre-processor counter that is supported by PhxAss, AsmOne and AsmPro (I *think* devpac supports it too, but i cant remember).

rs.w sets the label to the current counter value, and adds 2 to the counter (.b adds 1, .l adds 4), so, its the same as:

my_word = 0
my_long = 2
my_vars_length = 6

(the reason we use the rscounter is that we can insert new variables without changing the offsets for all the ones after it).

Finally, we allocate the ram for our variables with the ds.b statement.

There are several reasons for doing this:

1) You can write to and read from bytes, words and longwords all referenced via your variable register (= faster. You can't do as many operations relative to PC)

2) Flexibility. You can assign space in your executable for variable RAM, like above, but you could just as easily allocate my_vars bytes with AllocMem (and your code could become re-entrant with no changes), or even just allocated on the stack with LINK (for subroutines with local variables).

I hope you understood all that... ddd[/color]
Playstation Network ID: xeron6