sam-astro / Astro8-Computer

Custom 16-bit homebrew CPU, emulator, renderer, PCB, and language

Repository from Github https://github.comsam-astro/Astro8-ComputerRepository from Github https://github.comsam-astro/Astro8-Computer

`jmp` instruction is limited between 0-2047, so any programs longer than that fail

sam-astro opened this issue · comments

Describe the bug
jmp instruction is limited between 0-2047, so any programs longer than that fail

A new jmpl instruction should be added for jumping to large addresses (larger than 2047). This will use the following word as an address, rather than the 11-bit instruction area.

Currently J is always using the lowest 12 bits of the instruction:

{ // J
//cout << ("J ");
//cout<<Line(DecToBinFilled(InstructionReg, 16));
//cout<<Line(DecToBinFilled(InstructionReg, 16).Substring(4, 12));
programCounter = BitRange(InstructionReg, 0, 11);
}

Even though all jump instructions (JMP, JMPZ, JMPC) are also executing micro instruction IR (setting the lowest 12 bits of the instruction to the bus):

"jmp( 2=ir,j & 3=ei", // Jump <addr>
"jmpz( 2=ir,j | zeroflag & 3=ei", // Jump if zero <addr>
"jmpc( 2=ir,j | carryflag & 3=ei", // Jump if carry <addr>

This seems like a bug in the emulator, since the README states that the bus should is used:

J : write from bus to counter current value

If we fix the micro instruction J to use the bus instead, we can make a new instruction JMPL that does the following:

  1. NOOP
  2. CR read value from counter to bus
    AW write lowest 12 bits from bus to mem. addr. register
  3. RM read from memory to bus at the address in mem addr. register
    AW write lowest 12 bits from bus to mem. addr. register
  4. RM read from memory to bus at the address in mem addr. register
    J write from bus to counter current value
    CE enable incrementing of counter
  5. EI end instruction, resets step counter to move to next instruction

This is just like the LDLGE instruction, but instead of WA we do J.

Fixed in v0.2.0, thanks!