decoder for 8051

Status
Not open for further replies.

vead

Nov 27, 2011
473
Joined
Nov 27, 2011
Messages
473
can anyone tell me which decoder is used for 8051 microcontroller ?

4 bits can decode 16 things.
5 bits can decode to 32 things,
6 bits can decode 64 things.
8 bit can decode 256 things
16 bit can decode 65536 things
etc, etc..

suppose I am using 16 bit input
,ram_rd_sel ,ram_wr_sel ,src_sel1 src_sel2,alu_op,wr ,psw_set ,cy_sel ,pc_wr ,pc_sel ,imm_sel ,src_sel3 ,comp_sel ,bit_addr ;,rom_addr_sel ,ext_addr_sel

16 bits can represent 65536 states example nop, mov , movc, add addc ........upto 65536
when all input will 0 then perform nop state
as same we can decode different state at different input

I am not sure that I am going to correct way . ?
 

hevans1944

Hop - AC8NS
Jun 21, 2012
4,968
Joined
Jun 21, 2012
Messages
4,968
So what are you trying to do? Build an 8051 from open-source IP? Use an 8051 in a circuit?
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
A 16-bit-wide instruction opcode can specify 65536 different instructions. No processor needs that many distinctly different instructions, so the instruction word is generally divided into bitfields.

For example, there might be a single instruction to copy the contents of one register to another register, on a processor with 32 general purpose registers. This instruction might be encoded like this:
Code:
c c c c c c s s s s s d d d d d
----------- --------- ---------
--opcode--- -source-- destination
i.e. a six-bit opcode that identifies the instruction as a register-to-register copy, with a five-bit field to specify the source register and a five-bit field to specify the destination register, for a total instruction word width of 16 bits.

Other instructions might be encoded differently. For example, there might be instructions to set or clear one specific bit in any register, which might be encoded like this:
Code:
c c c c c c a b b b b r r r r r
----------- - ------- ---------
--opcode--- a --bit-- register
This category of instruction needs a four-bit bit number (assuming registers are 16 bits wide), and a 5-bit register number. The action to be performed on the specified bit in the specified register- i.e. whether the bit is to be set or cleared - can be specified in another bit which I've called 'a'. That's ten bits, leaving (again) six bits for the opcode part of the instruction word.

The example signals you have appear to be control signals generated by the processor core for communication with external devices such as RAM or I/O space. These are generated by the instruction decoder, which takes the instruction word and interprets it. The instruction decoder knows what each opcode needs to do, and generates the right control signals in the right order so that the processor core performs the requested operation.

For example, for a register-to-register data copy, the instruction decoder recognises the top six bits of the instruction as a register-to-register data copy. It takes the 5-bit source register specification from the instruction word and puts it on the internal register address bus, then performs a read access of that memory space, to get the contents of that register. It stores the data in an internal holding register. Then it takes the 5-bit destination register specification from the instruction word and puts it on the internal register address bus, then perform a write to that memory space, with the holding register providing the data to be written. Once those two steps are up, it is ready to load and execute the next instruction.

The steps that are required in order to execute the instruction are encoded in a "microcode ROM" that is indexed by the opcode, and tells the instruction decoder what sequence of internal operations it needs to perform in order to execute the current instruction. These internal operations are performed by controlling the signals you listed - ram_rd_sel, ram_wr_sel, src_sel1, and so on.

This describes a fairly simple CPU. Real world CPUs, especially powerful and/or fast CPUs, use tricks to make the execution of instructions much quicker and more complicated. But a simple device like the original 8051 will just do it step-by-step according to the information stored in the microcode.

I hope this explains the missing link between instruction words and control signals.
 
Last edited:

vead

Nov 27, 2011
473
Joined
Nov 27, 2011
Messages
473
look at following handy example
8 bit Instruction set
first 4 bit for Alu function
last 4 bit for register
A=address register 4bit
I=instruction register 4bit
R1= register 4 bit
R2= register 4 bit
Code:
alu function                      AIR1R2
ALU_NOP 4'b0000            XXXX

ALU_ADD 4'b0001             XXXX

ALU_SUB 4'b0010              XXXX

ALU_MUL 4'b0011             XXXX

ALU_DIV 4'b0100              XXXX

ALU_DA 4'b0101               XXXX

ALU_NOT 4'b0110             XXXX

ALU_AND 4'b0111            XXXX

ALU_XOR 4'b1000             XXXX

ALU_OR 4'b1001             XXXX

ALU_RL 4'b1010             XXXX

ALU_RLC 4'b1011            XXXX

ALU_RR 4'b1100              XXXX

ALU_RRC 4'b1101            XXXX

ALU_INC 4'b1110             XXXX

ALU_XCH 4'b111               XXXX

ALU_RL 4'b1010 XXXX
1010 AIR1R2 // 1110 ie R2=0 don't use R2 register
mov R1

same for another

ALU_RL 4'b1010 XXXX
1010 AIR1R2 // 1101 ie R1=0 don't use R1 register
mov R2

tell me I am getting something correct.
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
I don't know what the code or the instruction examples mean.

I understand that you have an 8-bit instruction word, divided into a 4-bit opcode and a 4-bit register specification.

The ALU has an accumulator, which is the "other" register for all two-register operations, and the destination register for all calculations.

I don't think you have made the connection from the instruction word to the various control signals that are needed inside the processor core in order to perform each type of instruction.

For example, an ADD instruction has an opcode of b'0001, so the instruction ADD R3 would be encoded as an instruction word of b'00010011. The top four bits are the opcode and the bottom four bits are the register number.

To execute that instruction, the ALU needs to perform several actions, in order. These actions roughly correspond to the clock cycles or phases in the execution of the instruction.
  • Copy the register specification from the opcode to the internal address bus that addresses the register bank;
  • Perform a read operation on the register bank at that address to get the value of that register (register 3) and store it in a temporary register;
  • Perform an arithmetic ADD operation using the temporary register and the accumulator as the inputs to the ADD function;
  • Copy the result of the addition (the sum) from the temporary result register to the accumulator.
  • Then the processor core moves on to the next instruction.
These steps are coordinated by the microcode. Each instruction opcode has a corresponding section of microcode in the microcode ROM, which determines the activity on the address, data, and control signals within the ALU and the processor core, and allows the core to perform those four steps as described above.
 

vead

Nov 27, 2011
473
Joined
Nov 27, 2011
Messages
473
ok look here

8 bit instruction set

4-bit opcode and a 4-bit register specification
0001xxxx - load immediate value into registers (I have 4 general purpose registers
0011xxxx - load register R1 from location specified in the R3
0101xxxx - save register R1 to location specified in the R2
0111xxxx - jump to the location in the R3 if register R2 is zero
1111xxxx - perform the ALU function on the registers, R1R2

I don't think you have made the connection from the instruction word to the various control signals that are needed inside the processor core in order to perform each type of instruction.


now If I want to decode 5 instruction then I think I have to use 2 control signal
but If I want to decode 256 instruction then I think I have to use 8 control siganal

  • For example, there might be a single instruction to copy the contents of one register to another register, on a processor with 32 general purpose registers.

  • 4-bit opcode and a 4-bit register specification
If I have general 32 registers but In my instruction set I can use only 4 registers so how can I use 32 registers
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
You can't address 32 registers if your instruction word only has a 4-bit register specification. That was an example that I created because you said you wanted a 16-bit-wide instruction word. I divided those 16 bits into a 6-bit opcode, a 5-bit source register number, and a 5-bit destination register specification. This would allow you to have an instruction such as ADD R9,R23, where R9 and R23 would be the inputs to the addition operation, and one of them would receive the result.

If you have an 8-bit-wide instruction word, and you divide it into a 4-bit opcode and a 4-bit register specification, you can only have 16 registers. And you can only have 16 different instructions, unless some of the 4-bit opcodes don't need a register specification, in which case you can use some or all of the bottom bits to widen the opcode width.

If you only have one register specification in the instruction word, you have to have a default register to be used as one of the source values for the operation. Normally this would be an "accumulator" register. This would have instructions like ADD R9 where R9 and the accumulator would be the inputs to the addition, and normally, the accumulator would receive the result.

I hope that answers your question, because I can't make sense of the rest of your post.
 

vead

Nov 27, 2011
473
Joined
Nov 27, 2011
Messages
473
I started with small one
opcode I have 4 instruction
Nop 00
Mov 01
Add 10
And 11

mov data
Code:
Mov R1    01   00 
Mov R2    01   01
Mov R3    01   10
Mov R4    11   11
add register to register
Code:
Add R1R2   10   00
Add R1R3   10   01
Add R1R4   10   10
Add R2R4   10   11
and logic
Code:
And R1R2    11   00
And R1R3    11   01
And R1R4    11   10
And R2R4    11   11
nop
Code:
Nop  0000

now I want to make decoder so how to make decoder
how many control signal I have to use ?
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
  • Program memory address bus - 8 bits (PA0~7);
  • Program memory data bus - 4 bits (PD0~3);
  • Program memory read enable;
  • Register memory address bus - 2 bits (RA0,1);
  • Register memory data bus - 4 bits (RD0~3);
  • Register memory read enable;
  • Register memory write enable.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
14,271
Joined
Nov 17, 2011
Messages
14,271
The number of control signals required depends on the number of control signal inputs of your ALU plus any additional control signals that are required e.g. to address registers or other functional units.
  • Define the binary opcodes for your 13 instructions (4 instructions where 3 of them have 4 different register addresses associated)
  • Find out which control signals of the ALu need to be activated (with which logic level) for the different instructions.
  • Find the logic function that map the opcodes to the control signals.

You may want to re-define the opcodes to simplify the logic mapping the opcodes to the control signals (you ma e.g. be able to use certain bits of the opcode directly as a control signal without any additional logic, although this method will work only for relatively few opcodes).


Here is an instructable for building an 8 bit cpu including references to helpful literature.
 

vead

Nov 27, 2011
473
Joined
Nov 27, 2011
Messages
473
ok I know how to make table for decoder look the following 4 to 16 decoder here is 4 control signal
I don't understand how to decide control signal for above example
Code:
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
 

vead

Nov 27, 2011
473
Joined
Nov 27, 2011
Messages
473
  • Program memory address bus - 8 bits (PA0~7);
  • Program memory data bus - 4 bits (PD0~3);
  • Program memory read enable;
  • Register memory address bus - 2 bits (RA0,1);
  • Register memory data bus - 4 bits (RD0~3);
  • Register memory read enable;
  • Register memory write enable.
If I use 7 control signal Then I think I have to use 7 to 128 decoder
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
No. That's a total of 8+4+1+2+4+1+1 = 21 signals. There is no reason to use a decoder with them.

What are you trying to achieve?
 

vead

Nov 27, 2011
473
Joined
Nov 27, 2011
Messages
473
No. That's a total of 8+4+1+2+4+1+1 = 21 signals. There is no reason to use a decoder with them.

What are you trying to achieve?
first I wanted to learn how does instruction set make so I made handy example look post #9
there 16 instruction
then I want to decode 16 instruction so I have to make decoder
so I know how to make table for decoder look post #12

but I don't understand how to decode 16 instruction ?
I don't understand what will control signal and what will be output signal ?
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
Address buses will be outputs from the instruction execution unit (IEU) (which includes the instruction decoder) to the other components of the CPU core. That's because the IEU needs to tell the program memory, or the data memory, which location it wants to read or write.

The data bus to the program memory will be input-only to the IEU because the program memory is read-only. This bus will carry the instruction words to the IEU.

The data bus to the register memory will be bidirectional because the IEU needs to be able to read AND write the registers.

The read and write enable signals will be outputs from the IEU. The IEU uses them to tell the other memories when to read and write data.

You don't need a decoder that decodes (for example) a 4-bit-wide opcode to one of 16 signals. Instruction decoding is normally done using a microcode ROM, which is indexed by the opcode.

All of this information is thoroughly explained in many places; if you're doing a course on it, your notes should explain it in great detail. There is no point in me trying to rewrite those articles. You need to read them and understand them. It seems to me that you aren't really "getting it" at all. There's no point continuing a course and hoping that it will all make sense at the end. You have to understand it all the way from the start. I think you should have a long talk with your tutor.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
14,271
Joined
Nov 17, 2011
Messages
14,271
Vead,
there are a few issues with your post(s):
1) You're posting the same questions on at least 2 other fora. While this is not forbidden, it generates a lot of extra work for many people.
2) Most of your questions can be answered by searching the internet with a search engine of your choice. You do not show any inclination to do some of your own research. While we are happy to help people if they do not understand an issue, we're not other peoples's search engines.
3) Your questions are often incomplete, lacking useful information about what you really are trying to achieve. We are not magicians. We cannot divine your thoughts. Give us clear information!
4) Your answers often do not show that you have read and understood the previous answer given to you by another member of this forum. Quoting another post doesn't mean you've understood it. Take your time. Read the answers thouroughly. Try to grasp their meaning. Come back for clarification, if necessary.


It seems that your learning doesn't keep pace with what you're trying to do. Your projects are ahead of your knowledge.

Step back for a moment and consider what you have learned so far with respect to the issue at hand (here: how a microcontroller works). Find literature (websites and books - yes: books) that enable you learn step by step. Start with small and simple projects - designing a microcontroller is not a very basic project.

Using the example that started this thread:
Start from a simple 1 bit opcode, encoding just 2 operations. Then add a second bit, thus encoding 4 operations. Find the operating principle behind opcode decoding, only then move on to longer opcodes. Also for starters you could work with fixed (hard-coded) addresses, extending the opcode-decoder to recognizing addresses only once you have understood the principle of opcode decoding.

If you keep wasting people's time you risk being banned (at least temporarily) from this forum.
 

hevans1944

Hop - AC8NS
Jun 21, 2012
4,968
Joined
Jun 21, 2012
Messages
4,968
I remember when I got my hands on the Texas Instruments ALU, a TTL LSI integrated circuit sometime in the 1970s. Wow! I could now build a computer! Fortunately, around the same time, Intel started building NMOS microcontrollers so I didn't have to.

From the code examples @vead provided, it looks like a course in integrated circuit design using Verilog. Ugg! Why re-invent that wheel unless you anticipate earning big bucks in that field? The day when a single designer could map out something as complicated as a modern microprocessor are long gone. It requires a team and years of architecture planning to build a modern computer. So, @vead, if that is your goal, to become a member of a design team, learning the internals of early microprocessor design may be a good place to start. What, exactly, is your goal?
 

vead

Nov 27, 2011
473
Joined
Nov 27, 2011
Messages
473
you risk being banned (at least temporarily) from this forum.
If you will not banned me I want to say something to hevans

@@vead, if that is your goal, to become a member of a design team, learning the internals of early microprocessor design may be a good place to start. What, exactly, is your goal?
I want to become design engineer, as student I learn only theory teacher don't tell us how the component connect together in big product (microcontroller )
but when any company make electronic product they don't use only one component they used all component and make one big product
so I did start to learn about how does company make 8051 controller
my main problem when we read books they give only principles like what is decoder ram ... I know what is alu , decode ,counter but when I want to assemble together I always get trouble

I have only one source Internet so when I don't understand anything practically. I post on forum and people always try to help me
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
14,271
Joined
Nov 17, 2011
Messages
14,271
ok I know how to make table for decoder look the following 4 to 16 decoder here is 4 control signal
I don't understand how to decide control signal for above example

Your example is a specific type of decoder: binary to 1-out-of-n
Decoders can take many forms. Any decoder takes a set of input codes and for each input code outputs an output code. This is called a mapping an is often done using a ROm (see Kris post #3). You have to realize that different decoders can give different outputs for the same inputs. This is where knowledge of the required control signals for the ALU comes into play (see my pos #13). You need to know which control signals are required to achieve the operation that is encoded by the opcode. Then you can find the maping from the opcode to the control signals.

At the bottom of this Wikipeda article you'll find a few useful references, I'd like to emphasize this breakdown of a simple CPU completely realized in TTL.
 
Status
Not open for further replies.
Top