ninezerozeronine / chip-computer

An 8 bit computer made from 74 series chips!
MIT License
0 stars 0 forks source link

Implement if and possbly else in assembler #30

Open ninezerozeronine opened 5 years ago

ninezerozeronine commented 5 years ago

Allow something like:

IF_ZERO_FLAG
    LOAD [#123] A
ADD A

Which would replace:

    JUMP_IF_ZERO_FLAG @if_instruction
    JUMP @continue
@if_instruction
    LOAD [#123] A
@continue
    ADD A

Need to be careful with indentation - it could give the impression that:

IF_ZERO_FLAG
    LOAD [#123] A
    LOAD [#23] B
ADD A

Would execute both only when the condition is true. If indentation is ignored (as it currently is it will always execute the second LOAD).

A decision also needs to be made about whether a couple of extra instructions are added for the compiler to use to skip 1-n lines, or to have the compiler always just hard code the instruction to jump to based on the size of the block.

Also need to decide if this extends to else bocks. Something to replace:

    JUMP_IF_ZERO_FLAG @if
    JUMP @else
@if
    LOAD [#123] A
    JUMP @continue
@else
    LOAD [#34] A
@continue
    ADD A

e.g.

    IF_ZERO_FLAG @if
        LOAD [#123] A
    ELSE
        LOAD [#34] A
    ADD A

This is straying into compiler territory...