Instruction Implementations

In this section we will show how some of the microinstruction of the Vondel Language are implemented in the microprogram.

Operations Summary

HALT

HALT is a special microinstruction to indicate that the program has ended. In this design this opcode is achieved by seting all 64 bits of the microinstruction to 1.

This constant is avalible as a shortcut in the CtrlStore struct.

MOV

Syntax: mov r0, ..., rn <- x.

Action: Store the value of the register x on the registers r0, ..., rn.

High Level

mov r15, r13 <- r14

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100000001100000000000000000000101000011101111100000000
111111111111111111111111111111111111111111111111111111111111111

ADD

Syntax: add r0, ..., rn <- x, y.

Action: Stores the result of x + y on the registers r0, ..., rn.

High Level

add r0, r1 <- r2, r3

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100000011110000001100000000000000000010110110000000000
111111111111111111111111111111111111111111111111111111111111111

SUB

Syntax: sub r0, ..., rn <- x, y.

Action: Stores the result of x - y on the registers r0, ..., rn.

High Level

sub r0 <- r2, r3

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100000011111100001000000000000000000011000011000000000
111111111111111111111111111111111111111111111111111111111111111

AND

Syntax: and r0, ..., rn <- x, y.

Action: Stores the result of x & y on the registers r0, ..., rn.

High Level

and r1 <- r2, r3

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100000000110000000100000000000000000010110110000000000
111111111111111111111111111111111111111111111111111111111111111

OR

Syntax: or r0, ..., rn <- x, y.

Action: Stores the result of x | y on the registers r0, ..., rn.

High Level

or r0, r1, r14, r15 <- r2, r3

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100000001110000001100000000000011000010110110000000000
111111111111111111111111111111111111111111111111111111111111111

XOR

Syntax: xor r0, ..., rn <- x, y.

Action: Stores the result of x ^ y on the registers r0, ..., rn.

High Level

xor r0, r1, r14, r15 <- r2, r3

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100000100110000001100000000000011000010110110000000000
111111111111111111111111111111111111111111111111111111111111111

NOT

Syntax: not r0, ..., rn <- x.

Action: Stores the result of !x on the registers r0, ..., rn.

High Level

not r0, r15 <- r3

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100000001101000001000000000000001000011001111100000000
111111111111111111111111111111111111111111111111111111111111111

SLL

Syntax: sll r0, ..., rn <- x.

Action: Stores the result of x << 8 on the registers r0, ..., rn.

High Level

sll r0, r15 <- r3

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100010001100000001000000000000001000011001111100000000
111111111111111111111111111111111111111111111111111111111111111

SLA

Syntax: sla r0, ..., rn <- x.

Action: Stores the result of x << 1 on the registers r0, ..., rn.

High Level

sla r0, r15 <- r3

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100011001100000001000000000000001000011001111100000000
111111111111111111111111111111111111111111111111111111111111111

SRA

Syntax: sra r0, ..., rn <- x.

Action: Stores the result of x >> 1 on the registers r0, ..., rn.

High Level

sra r0, r15 <- r3

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100001001100000001000000000000001000011001111100000000
111111111111111111111111111111111111111111111111111111111111111

READ

Syntax: read r0, ..., rn <- [addr].

Action: Stores the memory word at addr on the registers r0, ..., rn.

High Level

read r0, r15 <- 0x00008

Microprogram

Precondition: 0x00008 should be stored at MAR.

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100000000000000000000000000000000010111111111100000000
100000001000000001100000001000000000000001000000001111100000000
211111111111111111111111111111111111111111111111111111111111111

WRITE

Syntax: write [addr] <- x.

Action: Stores the memory value of x at addr on the memory.

High Level

write 0x00001 <- r14

Microprogram

Precondition: 0x00001 should be store at MAR.

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100000001100010000000000000000000000011101111100000000
100000001000000000000000000000000000000001100111111111100000000
211111111111111011111111111111111111111111111111111111111111111

JAL

Syntax: jal [addr].

Action: Jumps to the instruction of id (address) addr.

High Level

jal 0x0A

Microprogram

JMPC bit is used to nconditional branch, so we have to find some way of storing 0x0A into MBR and then use JMPC to jump to that address. For that the number 10 (0x0A) must be stored at memory and its address should be stored in PC. So, let's store 10 in the current address of the PC, by default the PC is 0, so let's store it there.

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100000000000000000000000000000000010111111111100000000
100000001010000000000000000000000000000000000111111111100000000
---------
1011111111111111111111111111111111111111111111111111111111111111

In a nutshell the operations are the following:

  1. Fetch the memory.
  2. Set JMPC to 1.

BEQ

Syntax: beq x, y.

Action: Jump if the value of the register x is equal to the value of the register y.

High Level

beq r14, r15

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100100011111100000000000000000000000101111001100000000
---------
25711111111111111111111111111111111111111111111111111111111111111

BNE

Syntax: bne x, y.

Action: Jump if the value of the register x is not equal to the value of the register y.

High Level

bne r14, r15

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000101000011111100000000000000000000000101111001100000000
100000001001000011111100000000000000000000000110001001000000000
---------
25711111111111111111111111111111111111111111111111111111111111111
25811111111111111111111111111111111111111111111111111111111111111

BLT

Syntax: blt x, y.

Action: Jump if the value of the register x is less than the value of the register y.

High Level

blt r14, r15

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000101000011111100000000000000000000000110001001000000000
---------
25711111111111111111111111111111111111111111111111111111111111111

BGT

Syntax: bgt x, y.

Action: Jump if the value of the register x is greater than the value of the register y.

High Level

bgt r14, r15

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000101000011111100000000000000000000000101111001100000000
---------
25711111111111111111111111111111111111111111111111111111111111111

MUL

Syntax: mul r0, ..., rn <- x, y.

Action: Multiply the value of x by y .

High Level

mul r13 <- r6, r7

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000101000011111100000000000000000000000100000101000000000
100000001000000001100000001000000000000000000100001111100000000
200000001100000011111100000100000000000100000011111111100000000
300000010000100011011000001000000000000000000010011111100000000
400000001100000011110000000000000000000100000101100010100000000
500000001100000011111100000100000000000100000100001111100000000
611111111111111111111111111111111111111111111111111111111111111
---------
25700000010100000001100000001000000000000000000011111111100000000
---------
26000000011000000000000000000000000000000000000000000000000000000

In a nutshell the operations are the following:

  1. Jump to 0b100000001 (257) if r6 - r7 is negative.
  2. Case 1 (has not jumped), therefore r6 >= r7
    1. Store the value of r7 on r0
    2. Store the value of r6 on r1 and r13
    3. Store the value of r0 - 1 into r0 or jump to the TERMINATE code (260) if equals to 0.
    4. Stores the value of r13 + r1 into r13.
  3. Case 2 (has jumped), therefore r6 < r7
    1. Store the value of r6 on r0
    2. Store the value of r7 on r1 and r13 and goto the step 3 of the case 1.

In another words, the smallest number is stored at r0 and the greater is stored in r1 and we aways make r0 * r1. This optimization is necessary because a multiplication is computed as sequential additions, and making less additions save some clock cycles.

In the real assembly implementation the registers used to store the temporary values are T0 (to store the minimum), T1 (to store the sum) and T2 (to store the maximum), so be caution when using this registers at the same time as the mul operation.

MUL2

Syntax: mul2 r0, ..., rn <- x, y.

Action: Multiply the value of x by y .

The difference between mul2 and mul are that mul is a software addition, in other words, a sequential sum of a number, on the other hand mul2 is hardware implemented (uses a multiplication circuit).

High Level

mul2 r0, r1 <- r2, r3

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100000101110000001100000000000000000010110110000000000
111111111111111111111111111111111111111111111111111111111111111

DIV

Syntax: div r0, ..., rn <- x, y.

Action: Divide the value of x by y .

High Level

div r0, r1 <- r2, r3

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100000110110000001100000000000000000010110110000000000
111111111111111111111111111111111111111111111111111111111111111

MOD

Syntax: mod r0, ..., rn <- x, y.

Action: Calculate the remainder of the division of x by y.

High Level

mod r0, r1 <- r2, r3

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100000111110000001100000000000000000010110110000000000
111111111111111111111111111111111111111111111111111111111111111

LUI

Syntax: lui r0, ..., rn <- [byte].

Action: Store the the immediate value of byte on the registers r0, ..., rn.

High Level

lui r15 <- 0xFF

This program stores 0xFF (255) to r15, but 255 is not stored in any register (it is a immediate value).

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100000001100000000000000000000001000010001111111111111
111111111111111111111111111111111111111111111111111111111111111

ADDI

Syntax: addi r0, ..., rn <- x, [byte].

Action: Stores the value of x + [byte] on the registers r0, ..., rn.

High Level

addi r14 <- r14, 0x05

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100000011110000000000000000000010000010001001000000101
111111111111111111111111111111111111111111111111111111111111111

SUBI

Syntax: subi r0, ..., rn <- x, [byte].

Action: Stores the value of x - [byte] on the registers r0, ..., rn.

High Level

subi r14 <- r14, 0x05

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100000011111100000000000000000010000010001001000000101
111111111111111111111111111111111111111111111111111111111111111

ANDI

Syntax: andi r0, ..., rn <- x, [byte].

Action: Stores the value of x & [byte] on the registers r0, ..., rn.

High Level

andi r14 <- r14, 0xFF

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100000000110000000000000000000010000010001001011111111
111111111111111111111111111111111111111111111111111111111111111

ORI

Syntax: ori r0, ..., rn <- x, [byte].

Action: Stores the value of x | [byte] on the registers r0, ..., rn.

High Level

ori r14 <- r14, 0x00

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100000001110000000000000000000010000010001001000000000
111111111111111111111111111111111111111111111111111111111111111

XORI

Syntax: xori r0, ..., rn <- x, [byte].

Action: Stores the result of x ^ [byte] on the registers r0, ..., rn.

High Level

xori r0, r1, r14, r15 <- r2, 0x02

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100000100110000001100000000000011000010000011000000010
111111111111111111111111111111111111111111111111111111111111111

MULI

Syntax: muli r0, ..., rn <- x, [byte].

Action: Stores the result of x * [byte] on the registers r0, ..., rn.

High Level

muli r0, r1, r14, r15 <- r2, 0x02

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100000101110000001100000000000011000010000011000000010
111111111111111111111111111111111111111111111111111111111111111

DIVI

Syntax: divi r0, ..., rn <- x, [byte].

Action: Stores the result of x / [byte] on the registers r0, ..., rn.

High Level

divi r0, r1, r14, r15 <- r2, 0x02

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100000110110000001100000000000011000010000011000000010
111111111111111111111111111111111111111111111111111111111111111

MODI

Syntax: modi r0, ..., rn <- x, [byte].

Action: Stores the result of x % [byte] on the registers r0, ..., rn.

High Level

modi r0, r1, r14, r15 <- r2, 0x02

Microprogram

IDNEXTJAMALUC BUSMEMABIMMEDIATE
000000000100000111110000001100000000000011000010000011000000010
111111111111111111111111111111111111111111111111111111111111111