Assembler Directives

z80 » Advanced

Your assembler is a powerful tool. Assembler directives are commands that tell the assembler to do some sort of calculation for you and incorporate those calculations into the output file. Your assembler can do all the thinking for you if you know how to use it. I'm going to give you some of the many useful assembler directives that you can use to your advantage.

Note: These are specific to Telemark Assembler (TASM)

#include

#include "arg1" - Pastes the file named arg2 in the same directory (or in the search path specified in your assembler's settings if it has any) into your source file right where you put the #include directive just as if you had typed the file in manually.
#include 'asm86.inc'
#include "asm86.inc"
#include asm86.inc
#include asm86

#define

#define arg1[(arg2, arg3, ...)] arg4 - Whenever arg1 is encountered, the assembler instead puts arg4 in that place with possible input such as arg2, arg3, ... incorporated.
#define ClLCD call _clrLCD		;'call _clrLCD' where ClLCD is

#define i_am_bored (i am bored)		;"(i am bored)"

#define i_am_bored i am bored		;"i am bored"

#define m_coords(x,y) ld bc,(x<<8)+y / ld (_penCol),bc
	;puts the 'ld b,x and following with / meaning a new line

#define coords(x,y) ld bc,(y<<8)+x / ld (_curRow),bc
	;puts the 'ld b,x and following with / meaning a new line

#define coords(x,y) ld bc,(y*256)+x / ld (_curRow),bc	;same as above

#defcont

#defcont arg1[(arg2, arg3, ...)] arg4 - Use this in conjunction with #define to roll the define over onto multiple lines (DEFine CONTinue). Useful so that the text doesn't go way out to the right of the screen.
#define coords(x,y)	push hl
#defcont		\ ld h,x
#defcont		\ l,y
#defcont		\ ld (_penCol),hl
#defcont		pop hl

.db

.db arg1[, arg2, arg3, ...] - This inserts direct values into the source as bytes. It's called the Data Byte directive. It's used a ton for strings, characters, and values. You can put several bytes in a row by separating them by commas. In a string, each letter is a byte.
.db 0
.db $ff
.db %00110011, 'J', $f0, 23-$10, 2*5
.db "This is a string."
.db "This"," is"," a"," string."
.db "Zero terminated string.",0
.db 22,"Length indexed string."
.byte "Stupid"
.byte 'A',$f0,0,%01010000

.dw

.dw arg1[, arg2, arg3, ...] - This is almost exactly like .db byte it inserts things as words (2 bytes) instead of single bytes. It's useful for addresses.
.dw AddressOne
.dw $1234
.dw 4345
.word address_one
.word $ffff

$

$ - Just like how the Program counter is updated after every command, the assembler is keeping track of where it is while it's compiling. It records this in relation to the address you designate as the origin (.org). Useful in other aliases, it is also called the Instruction Pointer because it points to (holds) the address of the next instruction following.
new_address = $+4	;new_address=current address+4

.end

.end - Tells the assembler to quit; it's done compiling your file and everything after this command is ignored.
.end

=

arg1 = arg2 - Takes label arg1 and assigns it the value of arg2. This is like an alias or an AKA.
_clrLCD = $4a7e
Number_Three = 3
Binary_for_Three = %00000011
Binary_for_Three equ %00000011
Binary_for_Three .equ %00000011

.org

.org arg1 - Tells assembler to make all absolute jumps and all absolute calls considering the source start at address arg1. All addresses after this directive are in relation to arg1.
.org 0
.org _asm_exec_ram
.org $23a4

.pad

.pad arg1 - This inserts zeroes from the current position to the address specified by arg1.
.pad address_later_in_source
.pad $ + 8	;from current address ('$') to 8 bytes later

.text

.text "arg1" - This is just like .db when you use it for strings. It puts arg1 as a string into the source and automatically adds a 0 at the end to zero terminate it.
.text "Stupid"	;= .db "Stupid",0

/

arg1 / arg2 - This treats the commands of arg1 and arg2 as if they were on separate lines.
ld b,6 / ld c,4
call _clrLCD / xor a

; the above is the same as the below

ld b,6
ld c,4
call _clrLCD
xor a


More from z80 » Advanced
All The Ports // APD // Assembler Directives // Entry Stack // User Fonts // IM 1 // IM 2 // Index, Shadow, and Other Registers // User Interrupt // Morphic Code // On-Off // Reading Keypresses from Port // Shift and Rotate // Simulating Key Presses // Sound // Square-Root Programs // System Flags of TI-OS