Skip to content

Problems with ldi reg 0 #6

@sparr

Description

@sparr

I should preface this by saying that I haven't built your computer yet, but I want to, either in a simulator or on breadboards, and I prefer to dive into the repository and code before getting physical. So, I'm sorry if some (or, hopefully not, all) of my "will" and "should" below are inaccurate or off base.

ldi {dst: reg} 0 => 0b11 @ 0b01 @ 0b00 @ dst[1:0]

This seems to convert ldi $a 0 into 0b11 01 00 00 which microcode.txt tells me is equivalent to sub $a $a instead of the move 0 $a that I would otherwise expect. While that instruction will produce the clearly desired effect of putting 0 into the a register, I think there are a few problems with this:

  1. sub sets flags while move does not. That means ldi $a 0 will set the zero flag, but ldi $a 1 will not clear the zero flag. As a programmer, this is not behavior I would expect or desire.
  2. ldi $b 0 is converted to 0b11 01 00 01 which is sub $a $b. Should the third crumb 0b00 here be another dst[1:0] instead so that this will produce 0b11 01 01 01 or sub $b $b?
  3. Both sub reg reg and move imm reg take 4 steps. This optimization saves a byte of code, but costs some power activating a bunch of extra control lines and circuits.
  4. dst[1:0] truncates the dst parameter to 2 bits, so ldi $sp 0 is accepted by the assembler and produces identical machine code to ldi $a 0, and ditto for $pc/$b and $out/$c. This line should include { assert(reg <= 4) ... } or equivalent.
    This concern also applies to {op: alu_op} {operand_1: reg} {operand_2: reg} => 0b11 @ op[1:0] @ operand_1[1:0] @ operand_2[1:0]
  5. No example programs use this pattern for any register other than a. The test suite program doesn't use it at all. Every separate line in the assembler definition probably deserves at lease one test case.

I hope at least some of this makes sense and is helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions