4 ms·
The following is an interesting construct in this Assembler code: IF COLECO LD HL,($006C) ; MSX BIOS chars LD DE,-128 ADD HL,DE ELSE LD
by peter_d_sherman 3y ago
The following is an interesting construct in this Assembler code:
IF COLECO
LD HL,($006C) ; MSX BIOS chars
LD DE,-128
ADD HL,DE
ELSE
LD HL,($0004) ; MSX BIOS chars
INC H
ENDIF
Not because of the LD's or the ADD or the INC! But because its an Assembler macro that contains a primitive form of higher-level languages if.. then.. (AKA "conditional") statement.
See, the variable COLECO is defined at the start of the program (basically it's just a memory address):
COLECO: EQU 0
So "IF COLECO" -- will be replaced by something like the following steps in Assembler psuedocode:
1) Maybe PUSH a register to be used for comparison to the stack (optional if we want to recover the register's previous value)
2) Move (Copy) the contents of the memory address referenced by COLECO to a register to be used for comparison;
3) Make the comparison between the contents of that register and 1 (True).
4) Do nothing / fall through if they are equal.
5) But if they are not equal, JUMP to the memory address of the ELSE statement -- which (since the ELSE statement is removed on Assembly by the Assembler, because it is only "syntactic sugar"; a placeholder for the address of the next actual instruction) is the memory address of the LD HL,($0004) instruction.
6) (Optional, if comparison register preservation is desired) Restore the value of the comparison register pre-comparison, in either code path, before additional code is executed (requires inserting additional instructions).
Now the above is based on me thinking in x86 Assembler, which the above code clearly is not...
Some popular 8-bit chips of the era had a "code page" -- Basically the first 256 bytes of memory could be used almost like registers... so there may have been a direct comparison operator in Z-80 Assembler (I do not know much about Z-80 Assembler, so forgive me if anything I'm saying is incorrect or missing) which would have obviated the need for the use of a comparison register.
But my main, most general point, remains -- it's a very interesting higher-level code construct, implemented via macro -- inside of a very low-level programming language.
Basically it's a step -- between an Assembler and a Compiler...
Anyway, an excellent article(!) -- and it's fun to look at retro 8-bit assembly code codebases!