/README.md

https://github.com/reinventingthewheel/assembler · Markdown · 55 lines · 43 code · 12 blank · 0 comment · 0 complexity · b05406307c3c8edfb7075496276d0a54 MD5 · raw file

  1. # Assembler
  2. This is the second step in abtraction from the brainfuck machine.
  3. It's a assembly to micro-assembly compiler. Please see the
  4. [micro-assembler](http://github.com/reinventingthewheel/micro-assembler)
  5. projects for details in this lower level language.
  6. ## Specification
  7. There are six registers for general use, and they can hold integers (or
  8. chars), named:
  9. A, B, C, D, E, F
  10. There is also a special register `IP` (instrucion pointer) which holds the
  11. current instruction address in the program.
  12. There is a special stack data structure for general use. It can be accessed by
  13. the instructions `PUSH`, `POP` and `TOP`.
  14. The instruction set is:
  15. * `ADD <REG> [$]<V>` Adds to `<REG>` the value of `<V>`.
  16. * `SUB <REG> [$]<V>` Substracts from `<REG>` the value of `<V>`.
  17. * `MUL <REG> [$]<V>` Multiplies `<REG>` by the value of `<V>`.
  18. * `DIV <REG> [$]<V>` Performs a integer division of `<REG>` by the value of `<V>`.
  19. * `MOD <REG> [$]<V>` Performs a integer modulus of `<REG>` by the value of `<V>`.
  20. * `ABS <REG>` Calculates the absolute value of `<REG>`.
  21. * `SQR <REG>` Calculates the square root of `<REG>`.
  22. * `MOV [$]<X> [$]<V>` Copies from `<V>` into `<X>`.
  23. * `PUSH [$]<V>` Pushes to stack the value '<V>`.
  24. * `POP <REG>` Pops from stack into `<REG>`.
  25. * `TOP <REG>` Checks the last pushed value from stack into `<REG>`.
  26. * `JMP [$]<V>` Jumps to instruction at the address in `<V>`.
  27. * `GOTO <LABEL>` Goto label (Jump to label, where `<LABEL>` is a identifier
  28. followed by commas).
  29. * `WRITE [$]<V>` Writes to output the value of `<V>`.
  30. * `READ <REG>` Reads from input into `<REG>`.
  31. * `EQ [$]<V> [$]<V>` Skips next instruction if arguments are equal.
  32. * `NEQ [$]<V> [$]<V>` Skips next instruction if arguments are not equal.
  33. * `GT [$]<V> [$]<V>` Skips next instruction if first argument is bigger than the second.
  34. * `LT [$]<V> [$]<V>` Skips next instruction if first argument is less than the second.
  35. * `GTE [$]<V> [$]<V>` Skips next instruction if first argument is greater or equal to the second.
  36. * `LTE [$]<V> [$]<V>` Skips next instruction if first argument is less or equal to the second.
  37. * `NOP` Does nothing (no operation).
  38. Where `<REG>` is a register name (A, B, C, D, E or F). `<V>` is whether a
  39. register or a integer (denoting a memory address). `<X>` is a register or a
  40. integer, but, in the latter case, it's always interpreted as a memory address.
  41. The optional `$` in some operands specifies the indirect addressing mode. It
  42. denotes the value in the address pointed by the subsequent value - which can be
  43. an integer or an register name (i.e. C/C++ style pointer `&`).