Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to make decoder

Tags:
  1. Oct 22, 2014 #1
    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 (Text):

    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 deactivate


    1 0 0 1 1 ?

    1 1 0 1 1 ?


    If I know Input then how to decide which function will decode ?
     
  2. jcsd
  3. Oct 22, 2014 #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 ?
     
  4. Oct 23, 2014 #3

    Mark44

    Staff: Mentor

    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.
     
  5. Oct 23, 2014 #4

    berkeman

    User Avatar

    Staff: Mentor

  6. Oct 23, 2014 #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 (Text):


    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
     
  7. Oct 23, 2014 #6

    berkeman

    User Avatar

    Staff: Mentor

    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?
     
  8. Oct 23, 2014 #7

    phinds

    User Avatar
    Gold Member
    2016 Award

    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.
     
  9. Oct 23, 2014 #8
    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
     
  10. Oct 23, 2014 #9

    Mark44

    Staff: Mentor

    Please answer the questions that berkeman asked.
     
  11. Oct 23, 2014 #10
    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
     
  12. Oct 24, 2014 #11

    Mark44

    Staff: Mentor

    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 (Text):
    MOV R1, #5
     
    The above copies the immediate value 5 to register R1.
    The machine code, in binary, would be
    Code (Text):
    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.
     
  13. Oct 24, 2014 #12
    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 (Text):
    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.
     
  14. Oct 24, 2014 #13

    Mark44

    Staff: Mentor

    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.
    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 (Text):
    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.
     
  15. Oct 25, 2014 #14
    What do you mean by "decoder"? A disassembler?
     
  16. Oct 26, 2014 #15

    Mark44

    Staff: Mentor

    Yeah, I'm not too clear on what he's asking, either.
     
  17. Oct 26, 2014 #16
    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 (Text):

    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 (Text):

    opcode                source            destination                         data
    0010                     R101                   00                              data
     
    load data directly into R2
    mov R2#data
    Code (Text):

    opcode                              source                                     destination                          data
    0010                                  R2 10                                        00                                data
     
    load data directly into R3
    mov R3#data
    Code (Text):

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

    Code (Text):

    opcode                                  source                                  destination                           data
    0010                                    00                                           A  01                                data
     
    mov the content of R1 into Accumulator
    mov A, R1
    Code (Text):

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

    opcode                                source                              destination              
    0010                                 R2 10                                      01                          
     

    mov the content of R3 into Accumulator
    mov A, R3
    Code (Text):

    opcode                                source                              destination              
    0010                                 R3 11                                      01                          
     


    don't use any register disable
    Code (Text):

    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
     
  18. Oct 27, 2014 #17

    Mark44

    Staff: Mentor

    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.
     
  19. Oct 27, 2014 #18
    mov instruction = 0010
    here I am using only one Instruction

    I am using 4 memory register and A accumulator for all operation
    Code (Text):

    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: Oct 27, 2014
  20. Oct 27, 2014 #19

    Mark44

    Staff: Mentor

    Now that I understand what you're doing, it seems reasonable.
     
  21. Oct 28, 2014 #20

    vela

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper
    Education Advisor

    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: How to make decoder
  1. How does software make? (Replies: 18)

Loading...