Programming the YGREC8

A project log for YGREC8

A byte-wide stripped-down version of the YGREC16 architecture

Yann Guidon / YGDESYann Guidon / YGDES 11/10/2017 at 09:260 Comments

2019 : Obsolete - needs an update because the instruction format has changed

Updated 20170116

Here, I'm giving a little crash course about how the YGREC8's instructions are translated from text to binary. Or, if you prefer, how the instructions are assembled. It's a mix of old and new and I favour simplicity and coherence, so the code is easy to understand and write. Fortunately, it is also very easy to assemble !

Let's start with how the instructions are represented in binary, with the diagram from the front page:

Then you can construct or write an instruction by following the diagram, reading it from left to right :

  1. Start with the opcode, one out of several specific words (see the opcode map).
    For example : ADD, for addition.
    The opcodes are grouped in 4 types: some perform boolean operations (OR, XOR, AND and ANDN), some perform arithmetic operations (ADD, SUB, from which CMPU and CMPS are derived), some move bits around (SHL, SHR, SAR, ROL), and the remaining opcodes move bytes around (IN, OUT, CALL, LDCH, LDCL, MOV).
  2. The opcode is followed by the name of a destination register. This is also one of the operands of arithmetic and logic operations.
    For example : "ADD R1" will use the put the result of an addition to the register R1, however one operand is missing.
  3. Then the operand can be a "long" immediate : Imm8 ranges from -128 to +127.
    For example : "ADD R1, 123" will add 123 to the register called R1.
    Another possibility is to use the short immediate, Imm3, ranging from -4 to +3.
    The last possibility is to use another register as operand : ADD R1, R2 will add R2 to R1.
  4. Eventually, in the last two cases, you can tell the processor to abort the operation if a given condition is met (or not). Typically, you can test if the Carry flag is set (or not), if the last result was Zero (or not) or its sign (Negative op Positive). The corresponding optional conditions are : IFZ, IFNZ, IFC, IFB/IFNC (the same), IFP, IFN. Other conditions are possible and will be defined later, the current names are IF0, IF1, IF2, IF3, IFN0, IFN1, IFN2, IFN3.
    For example : ADD R1 1 IFC will add 1 to R1 if the carry flag was set.

So yes, if you want to write an instruction, just follow the above diagram and choose the branch that corresponds to your needs and constraints. The 3 possible combinations of operands should be enough to solve most programming problems. That, and the way the registers work and are used.

On top of that, the idea is the same, for writing assembly language in text, or when using the "hardware assembler" of the front panel !

More on the assembly language at Assembly language and syntax