0

If I have:

0000 3304    alpha:    dc.w    5,16,4,-2

and my instruction is: sub.w alpha+2,D0

Is my alpha at 0000 33004 or is it at 00 05 00 01 00 04 FE?

d.moncada
  • 16,900
  • 5
  • 53
  • 82
Harold B
  • 23
  • 8

1 Answers1

3

dc.w a = define constant word, where a is the value to define

sb.w a,b = subtract word, where a is the source and b is the destination

Instruction

0000 3304    alpha:    dc.w    5,16,4,-2

is equivalent to:

0000 3304    alpha:    dc.w   05
             alpha:    dc.w   16
             alpha:    dc.w   04
             alpha:    dc.w  -02

To break up a bit more, the first instruction is saying starting at address 0000 3304, define a value of 5 then define a value of 16, then a value of 4 and so on. Since each of these values are instructed as a word, whenever a new value is defined, you must increment the address for that value by hex 2 for two bytes/the length for a word.

After the constants have all been defined, the following values will live at the following addresses

0000 3304 ->  0x05
0000 3306 ->  0x10       
0000 3308 ->  0x04
0000 330A ->  0xFE

What instruction sub.w alpha+2,D0 is saying, is to starting at alpha (address 0000 3304) move 2 bytes and subtract that value at that address from the value in data register D0.

so,

alpha+2 = address 0000 33006

which has a value of 0x10.

Whatever value is in data register D0, subtract 0x10 from it.

d.moncada
  • 16,900
  • 5
  • 53
  • 82
  • what do you mean subtract 0x04? – Harold B Apr 25 '13 at 06:38
  • @HaroldB you will subtract 4 from the value inside data register d0 – d.moncada Apr 25 '13 at 19:03
  • `alpha+2` means `alpha` plus 2 _bytes_, unless this is some exotic assembler I haven't heard of. – Michael Apr 25 '13 at 20:54
  • @Michael 2 bytes to the address or the value? I thought it was the address, as in incrementing a pointer by 2 – d.moncada Apr 25 '13 at 22:18
  • @moncadad: The address. Assemblers generally don't perform scaling in expressions like these, and for good reason (IMO). What if you had declared multiple types of data after `alpha`..? Which of them would you expect `alpha` to "be"? Or what if you had an expression like `alpha+beta`, where `beta` was another label followed by declaration of some other data type (or even code)? You can try this out with the GNU m68k assembler and see for yourself. – Michael Apr 26 '13 at 05:16