Go to file
n loewen f69e4533a1 Add shebangs to run-scripts 2023-08-07 11:00:04 +01:00
notes Move To Do list to its own file; Update To Do list 2023-08-07 10:48:41 +01:00
sketches Move early sketches to 'sketches' folder 2023-08-07 10:39:28 +01:00
test-programs Assembler: always add an END at the end of the output 2023-08-03 15:53:59 +01:00
assembler.js Add JSdoc annotatinos 2023-08-03 16:42:19 +01:00
display.js Add JSdoc annotatinos 2023-08-03 16:42:19 +01:00
jsconfig.json Turn on Jsdoc-based type checking 2023-08-03 16:24:51 +01:00
logging.js Turn on Jsdoc-based type checking 2023-08-03 16:24:51 +01:00
machine.config.js Move display memory back to $00 to make programming easy 2023-08-03 08:34:58 +01:00
package-lock.json Install jsdoc and jsdoc-to-markdown 2023-08-03 16:51:42 +01:00
package.json Add shebangs to run-scripts 2023-08-07 11:00:04 +01:00
readme.md Move To Do list to its own file; Update To Do list 2023-08-07 10:48:41 +01:00
run-assembler.js Add shebangs to run-scripts 2023-08-07 11:00:04 +01:00
run-cpu.js Add shebangs to run-scripts 2023-08-07 11:00:04 +01:00
simulator.js Add JSdoc annotatinos 2023-08-03 16:42:19 +01:00

readme.md

Paper computer simulator experiment

Run the assembler/simulator

Assemble source code:
npm run asm source_code.asm

Assemble source code, with debug output:
npm run asmdebug source_code.asm

Assemble and run, with animated display of screen memory:
npm run rundisplay source_code.asm

Assemble and run, with debug output:
npm run rundebug source_code.asm

Instruction set

00   END
01   STO lit#   ; store ... mem[lit#] <- A
02   STO addr   ; store ... mem[mem[addr]] <- A
03   LDA lit#   ; load  ... A <- lit#
04   LDA addr   ; load  ... A <- mem[addr]
05   ADD lit#   ; add   ... A <- A + lit#      ... and un/set carry flag
06   ADD addr   ; add   ... A <- A + mem[addr] ... and un/set carry flag
07   SUB lit#   ; sub   ... A <- A - lit#      ... and un/set carry flag
08   SUB addr   ; sub   ... A <- A - mem[addr] ... and un/set carry flag
09   HOP lit#   ; hop   ... skip next instruction if A == lit# ... when true: IP <- PC + 2
0A   HOP addr   ; hop   ... skip next instruction if A == addr ... when true: IP <- PC + 2
0B   JMP lit#   ; jump  ... IP <- lit#
0C   JMP addr   ; jump  ... IP <- addr
0D   CCF ————   ; clear Carry Flag ... CF = 0
0E   CHP ————   ; carry hop ... skip next instruction if Carry Flag is set ... when true: IP <- PC + 2
0F   NOP ————   ; no operation
  • Instructions are two bytes long: one byte for the opcode, one for the argument

Nice features that didn't fit

  • Hop IF< and hop IF>
  • MUL and DIV
  • Rotates and shifts

Registers and Flags

  • A - accumulator
  • IP - instruction pointer (aka program counter)
  • CF - carry flag

Memory map / Peripherals

  • 00-0F - display (4x4)
  • 10-1F - keypad? (details TBD)
  • 20 - pointer to display memory
  • 21 - pointer to keypad memory
  • 22-2F - reserved for future use / variable storage
  • 30 - initial value for IP
  • 30-FF - free

Maybe someday

  • Timer (for a version in software/electronic-hardware)

Assembly language

ADD $01         ; comments follow a `;`

ADD $FF         ; this is direct addressing
ADD ($CC)       ; this is indirect addressing

END             ; END, CFC, and CHP don't require arguments
                ; (a default value of 0 will be used as their operand)

@subroutine     ; create a label
    ADD $01     ; (it must be on the line before the code it names)
    ADD $02

JMP @subroutine ; use a label as an argument
                ; the label will be replaced with
                ; the address of the label

=foo $FF        ; define a constant
                ; (must be defined before it is referenced)

ADD =foo        ; use a constant as an operand
  • Hexadecimal numbers are preceded by a $
  • Whitespace is ignored