-
-
Notifications
You must be signed in to change notification settings - Fork 54
Description
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.
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$4Dor$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 thejpinstruction 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
reptdirective instead ofds(it's more broadly useful later on, for repeating code or data). That would also allow us to use thenopinstruction instead ofdb 0, since "instructions" are an already-introduced concept. The repetition count could again be$4Dor$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.