Skip to content

Micro_programs

wild-pointer27 edited this page Aug 2, 2026 · 1 revision

How to write micro-programs

The micro-assembler uses this syntax for each instruction:

C = A operation B, memory_operation, jump_operation: hex_address;

Each section is divided by a comma. If you don't need to use a section, you can simply type the keyword: none. To do nothing, simply substitute the entire structure with nop;.

Argument A:

  • A
  • B
  • C
  • D
  • TC
  • TB
  • PC
  • MDR

Argument B:

  • A
  • B
  • C
  • D
  • TC
  • TB
  • PC
  • MDR

Destination:

  • noreg: The result is not stored into any of the registers
  • A
  • B
  • C
  • D
  • TC
  • TB
  • PC
  • MDR

Operation:

  • Addition: a + b
  • Subtraction: a - b
  • And: a and b
  • Or: a or b

Special operations syntax:

  • Get a register value: $a
  • Increment a: a + 1
  • Decrement a: a - 1
  • Not a: !a
  • Obtain a zero value: 0
  • Obtain a one value: 1
  • Negate a: -a

Memory operations:

  • Read: read
  • Write: write
  • Fetch: fetch

Jump operation:

  • If zero: ifz
  • If negative: ifn
  • Goto, unconditional jump: goto
  • Goto MDR, jumps to the value inside MDR: goto MDR

Shift and other symbols:

  • Left shift: <
  • Right shift: >
  • Single line comment: #

To shift the ALU result value, you must substitute the equal symbol with the shift symbols. To compute non-standard operations, you must use the special operation syntax where a and b are the register values on the buses. The micro-assembler is also case-sensitive, so the registers must be typed in caps.

The micro-assembler accepts hex values typed in any of these ways: Various syntaxes to insert the number 0x000f:

  • f
  • 0xf
  • 000f
  • 0x000f

Compilation

To compile the code, type:

./microglossum -cmc your_program.mmc

If all of the instructions are correct, the micro-assembler produces an output like this:

$ ./microglossum -cmc micro_instruction_programs/multiplication.mmc
Current instruction: 0) none,read,none;
        Compiled instruction: 0/1023 (0x0000), 0x00000004
Current instruction: 1) MAR=1,none,none;
        Compiled instruction: 1/1023 (0x0001), 0x00012048
Current instruction: 2) A=$MDR,none,none;
        Compiled instruction: 2/1023 (0x0002), 0x00001c08
Current instruction: 3) none,read,none;
        Compiled instruction: 3/1023 (0x0003), 0x00000004
Current instruction: 4) nop;
        Compiled instruction: 4/1023 (0x0004), 0x00000000
Current instruction: 5) B=$A,none,none;
        Compiled instruction: 5/1023 (0x0005), 0x00000010
Current instruction: 6) C=$MDR,none,none;
        Compiled instruction: 6/1023 (0x0006), 0x00001c18
Current instruction: 7) C=C-1,none,none;
        Compiled instruction: 7/1023 (0x0007), 0x0000c818
Current instruction: 8) noreg=$C,none,ifz:0x000B;
        Compiled instruction: 8/1023 (0x0008), 0x02d00800
Current instruction: 9) A=A+B,none,none;
        Compiled instruction: 9/1023 (0x0009), 0x00002088
Current instruction: 10) none,none,goto:0x0007;
        Compiled instruction: 10/1023 (0x000a), 0x01e00000
Current instruction: 11) MAR>1,none,none;
        Compiled instruction: 11/1023 (0x000b), 0x00032048
Current instruction: 12) MDR=$A,none,none;
        Compiled instruction: 12/1023 (0x000c), 0x00000040
Current instruction: 13) none,write,none;
        Compiled instruction: 13/1023 (0x000d), 0x00000002
Current instruction: 14) none,none,goto:0x000E;
        Compiled instruction: 14/1023 (0x000e), 0x03a00000

Compiled a total of instructions: 15
Data written successfully. Output file: micro_instruction_programs/multiplication.mcm

If the given micro-program contains an error, the compilation stops and the incorrect instruction is identified:

$ ./microglossum -cmc micro_instruction_programs/multiplication.mmc
Current instruction: 0) none,read,none;
        Compiled instruction: 0/1023 (0x0000), 0x00000004
Current instruction: 1) MAR=1,none,none;
        Compiled instruction: 1/1023 (0x0001), 0x00012048
Current instruction: 2) a=$MDR,none,none;
Instruction number 2
ERROR 3: Invalid instruction

The output is a file with the same filename but with the .mcm extension that contains pure bytecode.

Examples

The program comes with these two examples:

# This program reads from addresses 0 and 1 in the RAM, multiplies their values, and puts the result at index 3

none, read, none; # Reads the first number
MAR = 1, none, none; # Updates MAR for the next reading

A = $MDR, none, none;
none, read, none; # Reads the value at address 1
nop;
B = $A, none, none; # Stores the original value of A to perform the multiplication
C = $MDR, none, none; # The C register will act as a counter

# Acts as a do-while loop
C = C - 1, none, none; # Decrements the counter
noreg = $C, none, ifz:0x000B;
A = A + B, none, none; # Performs the addition
none, none, goto: 0x0007;

MAR > 1, none, none; # Changes MAR from 1 to 2
MDR = $A, none, none;
none, write, none; # Writes the result in memory
none, none, goto: 0x000E; # Loops back on the same instruction, used to stop the program from running
# This program performs the multiplication between 2 and 3 and stores the result in the first RAM cell

A < 1, none, none; # Sets A to 3
A = A + 1, none, none;

B = $A, none, none; # Sets B to A

C = B - 1, none, none; # Stores the value of 2 to act as a counter

# Acts as a do-while loop
C = C - 1, none, none; # Decrements the counter
C = $C, none, ifz:0x0008;
A = A + B, none, none; # Performs the addition
none, none, goto: 0x0004;

MDR = $A, none, none; # Stores the value inside to load it into RAM
none, write, none; # Writes it in the RAM

none, none, goto: 0x000a; # Loops back on the same instruction, used to stop the program from running

Go back home

Clone this wiki locally