Skip to content

Assembler directives

alfie275 edited this page May 28, 2016 · 1 revision

Directives

Default syntax of directives :

[.]name [value0[, list of values]]

For example :

    .DAT 0, 1 ,2 ,3    ; OK
    dat 0              ; OK
    .fill 0, 10        ; OK

List of directives

DAT

DAT puts raw data, for example :

    .dat 0xDEAD, 0xBEEF

Would put on the output binary file, the values 0xDEAD and 0xBEEF

DAT accepts one or more values.

ORG

ORG macro indicates to DASM that the next instructions/data would be at the address indicated by ORG (ORiGin). For example :

        org 0x100
myvar:  .reserve 1

Would define a label at address 0x100 called "myvar"

Note that ORG only changes the logical address of symbols/labels. For example :

        org 0
        .dat 0xDEAD

        org 0x100
        .dat 0xBEEF

Would result on a output binary file that contains 0xDEAD, 0xBEEF, without any 0's filling/pading the 0xBEEF. DASM can emplace it (like one could expect), if the flag ARRANGECHUNKS is enabled.

FILL

FILL puts repeated raw data. Accepts only two arguments : value and amount .fill 0xCA, 10 ; Would put 0xCA ten times on the output binary file Note that amount quantity, could be an expression evaluated by DASM. This could be used to pad data.

DEFINE

DEFINE or DEF allows to define a symbol with a value. Have this syntax : .def SYMBOL_NAME, EXPRESSION or .def SYMBOL_NAME EXPRESSION

For example : .def MAGIC_NUMBER 0x55AA

Would make that every time that the DASM find the symbol "MAGIC_NUMBER", replaces it by the value 0x55AA

FLAG

Pass/enables flags to DASM :

  • IGNORELABELCASE -> DASM would ignore case on lables/symbols
  • ARRANGECHUNKS -> DASM would emplace code/data at absolute address indicated by ORG macro
  • STRICTDEFINECOMMAS -> If true, DEF directive will not allow the comma-less version

MACRO

Syntax : .MACRO symbol = [a-bA-B-0-9]* Defines a inline macro, that can accept parameters. Certain strings have special meaning:

%n will be replaced by a newline

%[number] will be replaced by the string of that parameter, so %0 gets the first parameter, %1 the second one etc.

%e[number] is the same as above, but the parameter is evaluated into a number before.

Eg:

MACRO dat_and_set=DAT %1%n SET %0, %1 

Then using dat_and_set A, 1+1 would expand to:

DAT 1+1
SET A, 1+1 

Whereas MACRO dat_and_set_eval=DAT %e1%n SET %0, %e1 and then dat_and_set_eval A, 1+1 would expand to:

DAT 2
SET A, 2 

This is useful as you can do stuff like:

def num0, 5
def num1, 7
def num2, 2
def num3 12
def num_counter, 0
macro dat_num=dat num%e0
macro do_num=dat_num num_counter %n def num_counter, num_counter+1 

and

do_num
do_num
do_num

would expand to

dat num0
def num_counter, num_counter+1
dat num1
def num_counter, num_counter+1
dat num2

DAsm by default has the following macros set, though note that a macro will overwrite macros of same name so they can be redefined.

asciiz

This macro works like DAT for a single parameter, but emplace a null character (a '0') at the end of the data

reserve

This is an alias of FILL with 0s as value

ret

This is an alias to SET PC, POP

OPCODE

This lets you define new opcodes, in the format OPCODE [opcode name],[opcode value],[operand type] where opcode value is the corresponding value (like when looking in the spec), and [operand type] is either A or AB depending on number of operands. Eg:

OPCODE BLAH, 0x1F, A

would define an opcode with value 0x1F, taking a single operand and assigned to the name "BLAH", allowing you to the do:

BLAH C
BLAH 5
BLAH [label]

etc as you can with any other opcode.

Clone this wiki locally