## A program

Our computer needs a program in order to run. Before creating the program, we select an instruction to use.

From the OpenRisc Architecture page we can find the OpenRISC 100 Architecture Manual.

We look in the OpenRISC 100 Architecture Manual, and we find the instruction l.movhi rD, K on page 81. This instruction takes a 16-bit value K, and shifts it left by 16-bits, and then places the resulting value in the register rD.

We see the instruction format for l.movhi rD, K, with its different fields. There are

• a 6-bit opcode (TBD, URL) field, in bits 31-26 (where bit 31 is the most significant byte (URL)), with the value 6
• a 5-bit register destination field D, in bits 25-21, with the value being the number of the register rD
• 4 reserved bits, in bits 20-17
• a 1-bit opcode field, in bit 16, with the value 0
• a 16-bit field K, in bits 15-0, holding the value that shall be written into register rD

We can write the instruction, with the fields as described above, as a 32-bit binary word. This results in

```000110DDDDD----0KKKKKKKKKKKKKKKK
```

The binary instruction format for l.movhi rD, K can also be seen in Section 17 of the OpenRISC 100 Architecture Manual.

Suppose we want to make a program that first puts the value 1 in r0, 2 in r1 and 3 in r2. The program should then put the value 0 in registers r0, r1, and r2. Such a program would then have the binary representation

```00011000000----00000000000000001
00011000001----00000000000000010
00011000010----00000000000000011
00011000000----00000000000000000
00011000001----00000000000000000
00011000010----00000000000000000
```

Grouping the binary digits in groups of four gives

```0001 1000 000- ---0 0000 0000 0000 0001
0001 1000 001- ---0 0000 0000 0000 0010
0001 1000 010- ---0 0000 0000 0000 0011
0001 1000 000- ---0 0000 0000 0000 0000
0001 1000 001- ---0 0000 0000 0000 0000
0001 1000 010- ---0 0000 0000 0000 0000
```

We can now convert the program to a representation where we use hexadecimal numbers. This conversion results in the program

```18000001
18200002
18400003
18000000
18200000
18400000
```

Figure 10. A program using a l.movhi instruction for writing values into registers

This the Verilog view - other views are VHDL - SystemC-TLM