Skip to content

Don't use ds $150 - @, 0 so early in the tutorial #152

@Rangi42

Description

@Rangi42

Section I.6, "Assembly basics", is going over the first few lines in hello-world.asm. It explains the concepts of "comments", "instructions", "directives", and "sections", which are all fundamental and important and widely used, all unavoidable complexity at this point. However, I think ds $150 - @, 0 is overly complicated this early on.

Image

Using the words "simply" and "simple" twice in explaining one line is probably a sign that it's not simple. The ds directive is not very useful outside of this particular context, and the @ symbol is also a pretty advanced concept, especially given the details of what its value is when used with instructions (it depends on the instruction size).

Given that the section is at a fixed address, the header is of a fixed size, the jp EntryPoint instruction is not going to change, and no code is going to be added here besides that one jp, I think it would be acceptable to hard-code the size of $4D here.

  • We could keep using ds, with size $4D or $150 - $100 - 3, 0. Either way we would need to explain in the subsequent paragraph that since the section is at address $100, we want to get to address $150, and the jp instruction takes up three bytes, then we need to skip $150 - $100 - 3 = $4D bytes. The choice is whether to show that calculation in the code (maybe it's more clear that way, but maybe it just looks noisy/intimidating).

  • Or, we could introduce the rept directive instead of ds (it's more broadly useful later on, for repeating code or data). That would also allow us to use the nop instruction instead of db 0, since "instructions" are an already-introduced concept. The repetition count could again be $4D or $150 - $100 - 3.

The main reason I can think of to keep ds $150 - @, 0 is that it's idiomatic in well-written code by an experienced dev. However, if that's the reasoning we're going with, I see a lot of lower-hanging fruit to tackle before introducing @ -- like the jr instruction, .local labels, calling subroutines, INCBINning data... all applicable to this Hello World example, and all more relevant to larger projects than @ is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions