.align

.align boundary

Align the following code to a particular boundary. This can be rather useful for speed - consider the following:

    ld l,(ix+0) ; Get the offset
    ld h,0
    ld de,_data
    add hl,de
    ld a,(hl)
    call _do_something
    
    ; snip
    
_data
    .incbin "datafile.bin"

We could speed this up by removing the addition and assignment to de (and also stop de from being destroyed!) by using the following code:

    ld l,(ix+0) ; Get the offset
    ld h,_data << 8
    ld a,(hl)
    call _do_something
    
    ; snip

.align 256    
_data
    .incbin "datafile.bin"

Because the alignment moves the code to the next boundary, there is a degree of wasted space.

You can align data manually (or in another assembler not supporting this directive) using the .org directive creatively - for example, a 256-byte alignment would be .org ($ + $FF) & $FF00 (where $ is the current instruction pointer).