How to Make Decoder for Microcontroller

  • Thread starter vead
  • Start date
  • Tags
    Decoder
In summary: 11 00
  • #1
vead
92
0
Hello ,

I am going to make decoder for micro controller , I want to know how does decoder make for microcontroller
so I made following example just for learning
I have 4 registers
I =Instruction Register
A= Address register
R1= register R1
R2 =register R2

Code:
I A R1 R2 
0000                         0000000000000001
0001                         0000000000000010
0010                         0000000000000100
0011                         0000000000001000
0100                        0000000000010000
0101                        0000000000100000 
0110                        0000000001000000 
0111                        0000000010000000 
1000                        0000000100000000
1001                       0000001000000000
1010                       0000010000000000
1011                       0000100000000000
1100                       0001000000000000
1101                      0010000000000000
1110                      0100000000000000
1111                      1000000000000000
1111 1000000000000000

Logic 0= deactivate

Logic 1= activate
Output = input

I A R1 R2 out

1 1 1 0 1 '' mov R1 '' // I,A R1, activate R2 deactivate

1 1 0 1 1 '' mov R2 '' // I,A R1, activate R2 deactivate1 0 0 1 1 ?

1 1 0 1 1 ?If I know Input then how to decide which function will decode ?
 
Technology news on Phys.org
  • #2
hello
4 bits can decode 16 things.

5 bits can decode to 32 things,

6 bits can decode 64 things.
etc, etc..
8 bit can decode 256 things
16 bit can decode 512 things
can anyone tell me which decoder is used for 8051 microcontroller ?
 
  • #3
vead said:
hello
4 bits can decode 16 things.

5 bits can decode to 32 things,

6 bits can decode 64 things.
etc, etc..
8 bit can decode 256 things
16 bit can decode 512 things
can anyone tell me which decoder is used for 8051 microcontroller ?
My understanding, which is limited, is that the decoder is part of the CPU, which is one of the components that make up the 8051 microcontroller. The basic 8051 instruction set consists of 256 op codes, which can be represented in 16 bits.
 
  • #4
vead said:
can anyone tell me which decoder is used for 8051 microcontroller ?

The wikipedia article on the 8051 is pretty helpful: http://en.wikipedia.org/wiki/8051

:)
 
  • #5
I am using following thing in my processor
  • Program memory address bus -
  • Program memory data bus -
  • Program memory read enable;
  • Register memory address bus -
  • Register memory data bus
  • Register memory read enable;
  • Register memory write enable.
  • address register
  • instruction register
  • data register
  • program counter
  • general purpose register
Code:
Code:
ADDRESS               INSTRUCTION   REGISTER       DATA
01                   MOV                           R1               DATA
10                    01                            00                   10

how to fetch decode and execute this one mov instruction ?
which register is used to fetch decode and execute instruction
 
  • #6
Did you read the wikipedia article on the 8051? What other tutorials have you read about how microprocessors and microcontrollers work?

Is this for schoolwork? What is the overall problem/project definition?
 
  • Like
Likes Medicol
  • #7
vead said:
how to fetch decode and execute this one mov instruction ?
which register is used to fetch decode and execute instruction

These questions suggest that your level of understanding of computer architecture is such that you need to study the basics more before you move on the something as complicated as what you seem to be taking on. That is, without some further study of the basics you are likely to find this a frustrating project.
 
  • #8
berkeman said:
Did you read the wikipedia article on the 8051? What other tutorials have you read about how microprocessors and microcontrollers work?

Is this for schoolwork? What is the overall problem/project definition?
ok I am starting with very basic

Code:
ADDRESS INSTRUCTION REGISTER DATA
01 MOV R1 DATA
10 01 00 10

send read signal to program memory -
program memory read enable =1

read program memory and store instruction into Instruction register
instruction register =mov=01

read program memory and store address into address register
address register =01

read program memory and store data into data register
data register =10

what do you think about this work. I have taken simple example to understand big things
 
  • #9
berkeman said:
Did you read the wikipedia article on the 8051? What other tutorials have you read about how microprocessors and microcontrollers work?

Is this for schoolwork? What is the overall problem/project definition?
Please answer the questions that berkeman asked.
 
  • #10
Mark44 said:
Please answer the questions that berkeman asked.
yes I read some useful information , few month ago I made post on microcontroller design. its not school work
so I want to use ram rom and some registers I did some work in post #8
 
  • #11
vead said:
ADDRESS INSTRUCTION REGISTER DATA
01 MOV R1 DATA
10 01 00 10
Are the numbers in the last row supposed to mean something? As far as I can tell, they don't mean anything.

You mentioned the 8051 processor before, so let's talk about that one.
Suppose this is the assembly code:
Code:
MOV R1, #5
The above copies the immediate value 5 to register R1.
The machine code, in binary, would be
Code:
0111 1001  0000 0101
The left-most 5 bits indicate that this is a MOV instruction.
The next 3 bits, 001, indicate that the destination register is R1
The 8 bits on the right represent the immediate value (5 = 0000 01012) that is to be copied.

As far as instruction decoding, I don't know what the processor does to decode instructions, and I pretty much don't care. All I care about is that the processor is able to
1. Read the value in PC (program counter), which holds the address of the next instruction in program memory.
2. Execute the current instruction.
3. Increment the program counter.

Some of what you wrote makes sense, but some seems to be just a random guess, especially the numbers you have.
vead said:
send read signal to program memory -
program memory read enable =1

read program memory and store instruction into Instruction register
instruction register =mov=01 ? what does mov=01 mean?

read program memory and store address into address register
address register =01 I don't think this happens at all

read program memory and store data into data register
data register =10 ?
 
  • #12
Mark44 said:
Are the numbers in the last row supposed to mean something? As far as I can tell, they don't mean anything.

You mentioned the 8051 processor before, so let's talk about that one.
Suppose this is the assembly code:
Code:
MOV R1, #5
The above copies the immediate value 5 to register R1.
The machine code, in binary, would be

The left-most 5 bits indicate that this is a MOV instruction.
The next 3 bits, 0.
ok I think its little bit correct
MOV R1, #5
here data store directly
mov @R1,#5
look machine code just for handy example
Code:
0111 1001  0000 0101
The left-most 5 bits indicate that this is a MOV instruction.
The next 3 bits, 001, indicate that the address of destination register is R1
The 8 bits on the right represent the immediate value (5 = 0000 01012) that is to be copied.
 
  • #13
Your post is difficult to understand since some of what is there is stuff that I wrote, but without quoting it, it appears that you wrote it.
vead said:
mov @R1,#5
look machine code just for handy example
This instruction copies the immediate value 5 to the address pointed to by the value (treated as an address) in R1.
The machine code in binary for mov @R1, #5 would be
Code:
0111 0111  0000 0101
The 8 bits on the left indicate the type of MOV instruction, and the 8 bits on the right contain the immediate value, 5, which in binary is 0000 0101.
As far as I can tell, there are only two mov instructions of this type, in which an immediate value is copied to the address pointed to by either R0 or R1.

The processor uses bit 7 (counting from the left) to determine whether to use the address in R0 or the address in R1.
mov @R0, #data
0111 0110 xxxx xxxx

mov @R1, #data
0111 0111 xxxx xxxx
The 8 bits marked as xxxx xxxx are the immediate value.
I got this information from http://www.keil.com/support/man/docs/is51/is51_opcodes.htm.
 
  • #14
What do you mean by "decoder"? A disassembler?
 
  • #15
DrZoidberg said:
What do you mean by "decoder"? A disassembler?
Yeah, I'm not too clear on what he's asking, either.
 
  • #16
Mark44 said:
Yeah, I'm not too clear on what he's asking, either.
first I wanted to make decoder for microcontroller but now I want to learn how instruction set implement

8 bit instruction set
4 bit opcode + 2 bit source register +2 bit destination register+ 4 bit data

accumulator A
memory register R1
memory register R2
memory register R3

Code:
opcode                                 source                       destination                       data
0010                                       00                                00                                    xx
                                                R1 01                          A 01                                 xx
                                                R2 10                            XX                                  xx
                                                R3 00                            XX                                  xx
load data directly into R1
mov R1#data
Code:
opcode                source            destination                         data
0010                     R101                   00                              data

load data directly into R2
mov R2#data
Code:
opcode                              source                                     destination                          data
0010                                  R2 10                                        00                                data

load data directly into R3
mov R3#data
Code:
opcode                                source                           destination                              data
0010                                    R3 11                                  00                                   data

load data directly into A
mov A#data

Code:
opcode                                  source                                  destination                           data
0010                                    00                                           A  01                                data

mov the content of R1 into Accumulator
mov A, R1
Code:
opcode                                source                              destination              
0010                                 R1 01                                      01

mov the content of R2 into Accumulator
mov A, R2
Code:
opcode                                source                              destination               
0010                                 R2 10                                      01
mov the content of R3 into Accumulator
mov A, R3
Code:
opcode                                source                              destination               
0010                                 R3 11                                      01
don't use any register disable
Code:
opcode                              source                                     destination                      data
0010                                 00                                                 00                       don't use register

the link you provided in post #13 is very useful
I am trying to execute one mov instruction
 
  • #17
vead said:
first I wanted to make decoder for microcontroller but now I want to learn how instruction set implement

8 bit instruction set
4 bit opcode + 2 bit source register +2 bit destination register+ 4 bit data

accumulator A
memory register R1
memory register R2
memory register R3

Code:
opcode                                 source                       destination                       data
0010                                       00                                00                                    xx
                                                R1 01                          A 01                                 xx
                                                R2 10                            XX                                  xx
                                                R3 00                            XX                                  xx
load data directly into R1
mov R1#data
Code:
opcode                source            destination                         data
0010                     R101                   00                              data
I can see that you put a lot of effort in your last post, but it doesn't make a lot of sense if we're talking about a real, functioning processor. I think it's partly a language problem, since English isn't your first language, but it also seems partly due to a lack of knowledge about what processors do and how they work.

Some of the major problems I see are these:
1. Every op code you show is 0010. Each instruction needs its own op code.
2. Since you have only 4 bits for the op code, there can only be 16 instructions. In your list you had six or seven instructions, all but one of which are mov instructions. You don't have many left for all the other instructions that you'll probably need, like add or subtract, or whatever operations the processor needs to be able to do.
 
  • #18
1. Every op code you show is 0010. Each instruction needs its own op code.
mov instruction = 0010
here I am using only one Instruction

Since you have only 4 bits for the op code, there can only be 16 instructions
I am using 4 memory register and A accumulator for all operation
Code:
Code (Text):

opcode                              source                                     destination                          data
                                   R                                                 A                            data
NOP 4'b0000              xx                                            xx                                   xx
ADD 4'b0001              xx                                             xx                                    xx
mov 4'b0010               xx                                            xx                                    xx
SUB 4'b0011               xx                                            xx                                    xx
DIV 4'b0100                xx                                             xx                                   xx
DA 4'b0101                xx                                             xx                                    xx
NOT 4'b0110              xx                                            xx                                      xx    
AND 4'b0111             xx                                               xx                                    xx
XOR 4'b1000             xx                                              xx                                       xx  
OR 4'b1001               xx                                               xx                                      xx
RL 4'b1010                 xx                                              xx                                       xx
RLC 4'b1011              xx                                              xx                                      xx
RR 4'b1100                xx                                               xx                                     xx
RRC 4'b1101              xx                                               xx                                    xx
INC 4'b1110                xx                                                xx                                     xx
XCH 4'b1111                xx                                              xx                                       xx

I know I need other register like psw , pc and other I will use later so don't mind its just handy idea
 
Last edited:
  • #19
Now that I understand what you're doing, it seems reasonable.
 
  • #20
DrZoidberg said:
What do you mean by "decoder"? A disassembler?
A decoder converts n input lines to 2n (or fewer) output lines. Each output line goes active for only one combination of the inputs. For example, if the input is 000, then output line 0 goes active; if the input is 001, output line 1 goes active, and so on.

Take the example of the 8051 move instruction above. There's the three-bit field which encodes which register to use. I don't remember the details of the 8051 processor, but say it has 8 eight-bit registers, which are likely implemented as 8 sets of 8 flip-flops. When the processor executes that instruction, each set of 8 flip-flops needs a signal to tell it whether to update its contents or not. To get those signals, you run the three bits from the instruction through a decoder.
 

FAQ: How to Make Decoder for Microcontroller

1. How does a decoder work?

A decoder is a combinational logic circuit that takes an n-bit input and produces a 2^n outputs, with one output being active at a time. It essentially takes a binary input and activates the corresponding output line, while keeping all other output lines inactive.

2. What is the purpose of a decoder in a microcontroller?

A decoder is used in a microcontroller to expand the number of output lines available. This allows the microcontroller to control more devices or perform more complex tasks by activating different combinations of output lines.

3. How can I make a decoder for a microcontroller?

To make a decoder for a microcontroller, you will need to design a combinational logic circuit using logic gates such as AND, OR, and NOT gates. The number of inputs and outputs will depend on your specific project needs.

4. What tools and materials do I need to make a decoder for a microcontroller?

You will need a breadboard, logic gates, resistors, wires, and a power source. You may also need a microcontroller development board and a programming language such as C or assembly to program the decoder.

5. Are there any online resources or tutorials for making a decoder for a microcontroller?

Yes, there are many online resources and tutorials available for making a decoder for a microcontroller. You can find step-by-step guides, videos, and forums where you can ask for help and advice from other electronics enthusiasts and experts.

Back
Top