In this project, Verilog code for a microcontroller is presented. Before implementing, the instruction set architecture for the microcontroller is presented in this part. (Part-2 and Part-3)
Instruction Set Architecture:
Each instruction is 12 bits. There are 3 types of instructions by encoding, shown as following:
- M type: one operand is accumulator (sometimes ignored) and the other operand is from data memory; the result can be stored into accumulator or the data memory entry (same entry as the second operand).
- I type: one operand is accumulator and the other operand is immediate number encoded in instruction; the result is stored into accumulator.
- S type: special instruction, no operand required. (e.g. NOP)
The instruction encoding space is shown in the following table.
Code space
(binary)
|
Code space
(hex)
|
Type
|
Number of Instructions
|
Note
|
0000_0000_0000 - 0000_1111_1111
|
000-0FF
|
special instructions (S type)
|
256
|
Currently only NOP
used,255 free slots
|
0001_0000_0000 - 0001_1111_1111
|
100-1FF
|
unconditional jump
(I type)
|
1
|
GOTO
|
0010_0000_0000 - 0011_1111_1111
|
200-3FF
|
ALU instructions
(M type)
|
32
|
16 instructions, 2 destination choices
|
0100_0000_0000 - 0111_1111_1111
|
400-7FF
|
conditional jump
(I type)
|
4
|
JZ, JC, JS, JC
|
1000_0000_0000 - 1111_1111_1111
|
800-FFF
|
ALU instructions
(I type)
|
8
|
Currently 7 used, 1 free
slot
|
These instructions can be grouped into 4 categories by function.
1. ALU instruction: using ALU to compute result;
2. Unconditional branch: the GOTO instruction;
3. Conditional branch: the JZ, JC, JS, JO instruction;
4. Special instruction: the NOP.
M type instructions
The general format of M type instruction is shown as following.
The following table contains the detailed information of each M type instruction. Note that “aaaa” encodes the 4 bit address of data memory, and the “d” bit means destination of the result, i.e. if d = 1, result is written to Acc, otherwise the result is written to the same memory location as the operand
Note that all M type instructions are ALU instructions.
Comments:
1. For circulative shift, only the operand from memory entry is rotated, i.e. flags are not involved. For example, if 8’b1000_0000 is shifted left circulative for 1 bit, it becomes 8’b0000_0001, and no flag is affected.
2. For logical shift instructions, 0 is always filled in, and C flag is set to the last bit that is shifted out. For example, if 8’b1000_0000 is shifted left logically for 1 bit, it becomes 8’b0000_0000, and C = 1. Another example, if 8’b0000_0100 is shifted right logically for 3 bit, it becomes 8’b0000_0000, and C = 1. If no bit is shifted out, Z flag and C flag are not affected.
3. For arithmetic shift right instructions, the MSB is filled in, and C flag is set to the last bit that is shifted out. For example, if 8’b1000_0001 is shifted right arithmetically for 1 bit, it becomes 8’b1100_0000, and C = 1. Another example, if 8’b0000_0100 is shifted right arithmetically for 3 bit, it becomes 8’b0000_0000, and C = 1. If no bit is shifted out, Z flag and C flag are not affected.
I type instructions
The general format of M type instruction is shown as following.
The following table contains the detailed information of each M type instruction.
Note that I type instructions contains unconditional branch, conditional branch, and ALU instructions.
S type instructions
The general format of S type instruction is shown as following.
There is only one S type instruction, i.e. the NOP instruction.
Sample Testing Program |
After completion the hardware implementation of the MCU, you need to write testbench and load instructions to verify the design by simulation. Below is some testing programs to verify the MCU.
Test1: Program loading, accumulator, and memory loading, GOTO
Test2: Addition and subtraction (M type)
Test3: Logic operation (M type)
Test4: Addition, subtraction, logic operation (I type)
Part 3 will be the Verilog code for the whole microcontroller.
29. Verilog code for Multiplexers
You may like this:
A complete 8-bit Microcontroller in VHDL
Single-cycle MIPS Processor in Verilog
Verilog Code for 16-bit RISC Processor
32-bit 5-stage Pipelined MIPS Processor in Verilog (Part-1)
32-bit 5-stage Pipelined MIPS Processor in Verilog (Part-2)
32-bit 5-stage Pipelined MIPS Processor in Verilog (Part-3)
What is FPGA Programming? FPGA vs Software programming
Recommended and affordable Xilinx FPGA boards for students
Recommended and affordable Altera FPGA boards for students
Recommended Verilog projects:
A complete 8-bit Microcontroller in VHDL
Single-cycle MIPS Processor in Verilog
Verilog Code for 16-bit RISC Processor
32-bit 5-stage Pipelined MIPS Processor in Verilog (Part-1)
32-bit 5-stage Pipelined MIPS Processor in Verilog (Part-2)
32-bit 5-stage Pipelined MIPS Processor in Verilog (Part-3)
What is FPGA Programming? FPGA vs Software programming
Recommended and affordable Xilinx FPGA boards for students
Recommended and affordable Altera FPGA boards for students
Recommended Verilog projects:
2. Verilog code for FIFO memory
3. Verilog code for 16-bit single-cycle MIPS processor
4. Programmable Digital Delay Timer in Verilog HDL
5. Verilog code for basic logic components in digital circuits
6. Verilog code for 32-bit Unsigned Divider
7. Verilog code for Fixed-Point Matrix Multiplication
8. Plate License Recognition in Verilog HDL
9. Verilog code for Carry-Look-Ahead Multiplier
10. Verilog code for a Microcontroller
11. Verilog code for 4x4 Multiplier
12. Verilog code for Car Parking System
13. Image processing on FPGA using Verilog HDL
14. How to load a text file into FPGA using Verilog HDL
15. Verilog code for Traffic Light Controller
16. Verilog code for Alarm Clock on FPGA
17. Verilog code for comparator design
18. Verilog code for D Flip Flop
19. Verilog code for Full Adder
20. Verilog code for counter with testbench
21. Verilog code for 16-bit RISC Processor
22. Verilog code for button debouncing on FPGA
23. How to write Verilog Testbench for bidirectional/ inout ports
3. Verilog code for 16-bit single-cycle MIPS processor
4. Programmable Digital Delay Timer in Verilog HDL
5. Verilog code for basic logic components in digital circuits
6. Verilog code for 32-bit Unsigned Divider
7. Verilog code for Fixed-Point Matrix Multiplication
8. Plate License Recognition in Verilog HDL
9. Verilog code for Carry-Look-Ahead Multiplier
10. Verilog code for a Microcontroller
11. Verilog code for 4x4 Multiplier
12. Verilog code for Car Parking System
13. Image processing on FPGA using Verilog HDL
14. How to load a text file into FPGA using Verilog HDL
15. Verilog code for Traffic Light Controller
16. Verilog code for Alarm Clock on FPGA
17. Verilog code for comparator design
18. Verilog code for D Flip Flop
19. Verilog code for Full Adder
20. Verilog code for counter with testbench
21. Verilog code for 16-bit RISC Processor
22. Verilog code for button debouncing on FPGA
23. How to write Verilog Testbench for bidirectional/ inout ports
24. Tic Tac Toe Game in Verilog and LogiSim
25. 32-bit 5-stage Pipelined MIPS Processor in Verilog (Part-1)
26. 32-bit 5-stage Pipelined MIPS Processor in Verilog (Part-2)
27. 32-bit 5-stage Pipelined MIPS Processor in Verilog (Part-3)
28. Verilog code for Decoder25. 32-bit 5-stage Pipelined MIPS Processor in Verilog (Part-1)
26. 32-bit 5-stage Pipelined MIPS Processor in Verilog (Part-2)
27. 32-bit 5-stage Pipelined MIPS Processor in Verilog (Part-3)
29. Verilog code for Multiplexers
30. N-bit Adder Design in Verilog
30. N-bit Adder Design in Verilog
31. Verilog vs VHDL: Explain by Examples
32. Verilog code for Clock divider on FPGA
33. How to generate a clock enable signal in Verilog
34. Verilog code for PWM Generator
35. Verilog coding vs Software Programming
36. Verilog code for Sequence Detector using Moore FSM
30. N-bit Adder Design in Verilog
31. Verilog vs VHDL: Explain by Examples
32. Verilog code for Clock divider on FPGA
33. How to generate a clock enable signal in Verilog
34. Verilog code for PWM Generator
35. Verilog coding vs Software Programming
36. Verilog code for Sequence Detector using Moore FSM
No comments:
Post a Comment