Why isn't # needed before numbers with DC.W (Define Constant), only instructions?
Asked Answered
S

2

6

I have this line of code:

X   DC.W    5   

This means basically X = 5 But shouldn't be X DC.W #5 ?

When using MOVE I need always #

MOVE.B  #1,VAR
Sweaty answered 29/4, 2012 at 18:44 Comment(0)
D
8

#1 means immediate value, i.e. the value 1. Without the #, it would mean the contents of the memory location 1.

With DC.* you place values (I guess you can call them "immediate" values) into memory locations specified by X. It is not a processor instruction, but the instruction for the assembler to reserve memory and fill it with specified value(s).

Dania answered 29/4, 2012 at 19:15 Comment(0)
J
1

Typically dc.(b/w/l) is used for hardcoded data being put into a table in ROM. E.g. if you wanted to create a table of four bytes, it'd look like the following:

EITHER ONE WILL WORK:

  • dc.b 4, 2, $10, $1A

OR

  • dc.b 4
  • dc.b 2
  • dc.b $10
  • dc.b $1A

They both mean the same thing, as they are declaring 4 bytes of data. Now, using MOVE is a little bit different, in that it is moving data to a data register, or a location in RAM. This data can be from... say, the table we created above, from a data register, or a simple number value starting with this '#', like so:

  • move.b #$11,($FFFFFE00).w

This moved the value $11 to the RAM address I specified. Hope that clears this up.

Jeffers answered 27/6, 2014 at 3:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.