In all forms of programming, it is essential to add comments. These are bits of text that the assembler completely ignores - we add them in to help humans (including ourselves) to understand what the code is supposed to do (on a high level), and why it’s doing what it’s doing (on a low level).

There is one super-hugely-amazingly important reason to add comments to your code: you will forget what it’s doing and why it’s doing it in the way it does, and waste loads of time trying to figure it out. Save yourself the hassle by writing loads of helpful comments.

There are two types of comment: line and block.

Line comments

In WLA DX, everything that comes after a semicolon “;” is ignored until the end of the line.

Comment on what you’re doing:

ld b,10 ; Initialise the counter

What something is:

; Font data:
.incbin "font.bin"

You can also comment out code instead of deleting it:

; Initialise the counter
;ld b,10
ld b,20

Block comments

In WLA DX, everything that comes after “/*” is ignored until “*/” is found, across multiple lines.

This is useful for commenting out large blocks:

/* Skip outputting
    ld a,$00
    out ($bf),a
    ld a,$38|$40
    out ($bf),a
    ld hl,Message
-:      ld a,(hl)
        cp $00
        jp z,+
        sub $20
        out ($be),a
        ld a,$00
        out ($be),a
        inc hl
        jp -

Or for making large blocks of explanatory text:

 In loving memory of Acorn Computers Ltd.
      Mike G proudly presents the:

       BBC Micro Character Set!

 This source was created automatically
 from character data stored in the BBC
 Microcomputer operating system ROM.

 The BBC set is a nice, clear font which
 (unlike the classic Namco/Sega font)
 includes lower-case letters as well as

 Being a British micro, there's even a
 Pound Sterling currency symbol, which
 should come in handy when I begin to
 write financial apps on the SMS. (Just

 Hopefully by using binary representation
 it will be obvious how the character
 data is stored.


Although you can make these large blocks out of line comments too.

< Assembly concepts | Lesson 1 | Numbers >