Maker Pro
Maker Pro

decoder for 8051

Status
Not open for further replies.

hevans1944

Hop - AC8NS
Jun 21, 2012
4,878
Joined
Jun 21, 2012
Messages
4,878
There are many dimensions to electronics, ranging from the design of microscopic integrated circuits to complex systems with thousands or millions of components. I decided early in my career not to get too involved with the the minutia of circuit design, leaving that to others who did not mind devoting years of their life to obtaining a single ambitious goal. Those people exist and are well paid for what they do. Their end-product is millions of identical components that do wonderful and almost unimaginable things, sold at reasonable prices. Most of these folks design dozens or even hundreds of devices before the end of their career. Some even start their own companies based on their original designs. Pretty risky business, that, but no rewards without risk in this world.

My goal, first and foremost, was to always have fun. If I didn't enjoy what I was getting paid to do, the salary didn't matter. Time to move on to something more interesting if or when that occurs. To obtain this kind of flexibility requires a broad theoretical background coupled with practical experience and a spirit of adventure. The theoretical background is the bed rock on which you base your career. Without it, you are just a hobbyist hoping for the best, almost blindly trying this or that in the hope of succeeding. Nothing wrong with that, and it could be part of the learning process, but it is not a good basis for a professional career in electronics.

I happen to also be a hobbyist, going back to when I was about six years old or so, when I built my first "crystal set," a simple AM radio that needed no power to operate. Between then and graduation from University with a Bachelor of Electrical Engineering degree in 1978, some twenty-eight years later, was quite interesting. At first I thought I knew more than I really did. Then I found out how much I didn't know and took courses to correct the deficiency. Finally I reached my level of incompetence when I took an honors course in Linear Algebra. Had to drop out of that one somewhere in the neighborhood of Abelian Rings. Why did I take this course? Well, I enjoy designing control systems, and modern design typically uses a transfer matrix to describe the system. I thought linear algebra had something to do with that. I should have asked my adviser before signing up for the course.

Don't over emphasize the practical experience. When I obtained my current position I knew virtually nothing about particle accelerators and had zero experience operating or maintaining them. In fact, I was not their first choice to hire. The company wanted someone with experience who could not only operate particle accelerators (we had two of them) but also troubleshoot and maintain them. They spent several months intensively trying to recruit a local fellow who operated a low-energy ion implant accelerator for a semiconductor manufacturer whose headquarters was here in Dayton. This guy was basically an appliance operator. Someone gave him an implant recipe and he set up the accelerator. Fortunately he also knew his limitations. He may have been able to keep our low-energy accelerator running by replacing modules and components, but our high-energy tandem was way beyond his capabilities and experience. He turned their offers down, despite several interviews and pleas, and who-knows-what bonus incentives. Meanwhile, the physicist who did operate these two accelerators wasn't having fun, nor did he know how to maintain or repair them. He might have been a good physicist (he certainly understood how the accelerators operated), but he had neither the incentive or skills to troubleshoot and maintain them. He found a real physics position at Argonne National Laboratories and gave the company two or maybe three months notice to find his replacement.

One week before his departure they called me in for an interview. I had responded to a local newspaper ad months previously, submitting my resume but had received no response... not even an acknowledgement that someone had even looked at. I was unemployed at the time, working part-time through a temporary labor service to make ends meet. They hired me more or less on the spot and I received one week of on-the-job training from the departing physicist. I had no idea what I was getting into, but the salary offered was good. That was in 1997 and I am still having fun, although at age 70 semi-retired and working about 20 hours per week.

My advice: stick with the books and learn a lot of theory, even if you can't put it into practice immediately. I know it's hard to just read how or why something works without actually seeing how it works, but make the effort anyway. In particular, look into computer architectures to get an overall view of what is going on inside.

My first "real" microprocessor was an Intel 8080 which has an 8-bit data path to the outside world with a 16-bit linear address space. It fetches instructions as one-, two-, or three-byte sequences from memory. Inside, an instruction decoder addresses a ROM containing microcode that tells the internal circuits how to function. This "microcode" knows how many bytes to fetch for each op-code, and what to do with them. It takes 4, 5, 7, 10, or 11 clock cycles for these internal circuits to complete a single 8080 instruction, the length depending on what the instruction must fetch from internal register or external memory and what the instruction does with the operands. Decision instructions involving conditional branches take the largest number of cycles.

This is more than I ever wanted to know about 8080 internals. I didn't care then (and don't care now) how the program counter causes an instruction to be fetched, decoded, and one or two operands (if necessary) subsequently fetched before the instruction actually executes and the program counter moves on to the next instruction. Sometimes I did need to know how long this would take, as when writing interrupt service routines for real-time processing.
 

vead

Nov 27, 2011
473
Joined
Nov 27, 2011
Messages
473
Vead,
there are a few issues with your post(s):


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.
.
I followed your advice
I want to connect memory with some registers
read the value from program memory and store into register
store value from register to memory
Code:
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

I know I need program counter to execute next instruction

I want to use this value for alu operations

so for alu has three register

src1 register (input )
src2 register (input)
dsrc register (output)

now I want to tell the ALU , do the mov operation so I have to use decoder to decode Instruction
I need control signal that will tell ALU , do mov operation
 
Last edited:

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
You seem not to understand how a CPU operates. The ALU is the Arithmetic Logic Unit. It does, as the name says, arithmetic or logic operations on its operands.
For a mov instruction there is no arithmetic involved. You simply store the data into the respective register. Instead of loading the data into a hypotehtical data register and then move it to R1, a mov R1 data would fetch data from memory and directly store it into register R1.

Stick with your first topic, assuming data and addresses are available in registers that can be accessed by simply issuing the register's address. Keep aside the issue of how the data and addresses get into these registers and concentrate on that part of opcode decoding that handles the arithmetic nad logic functions.

I followed your advice
No, you don't. Instead of keeping focused on one problem, advancing to the next issue only after you have understood the first one, you jump from decoding opcodes for mathematical operations to decoding opcodes for data transfer operations. This is not the same.

Note also that decoding the opcode is only the first part of what is required for the CPU to execute an opcode. As you have described yourself in above post (#22) one opcode results in a sequence of events that are executed by the CPU. This sequence is typically referred to as microcode. It will involve a so called state machine to run where the different states are defined by the opcode.

You really need to read and learn more about how a CPU works before you can start designing your own (even a simple one). Many of the basic operations of a CPU can even be traced by following the states of the different components of a CPU manually on a sheet of paper. This simulator may help you.
 

vead

Nov 27, 2011
473
Joined
Nov 27, 2011
Messages
473
ok look my another effort

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         R1 01          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       data
0010         R1 01          01                  disable

mov the content of R2 into Accumulator
mov A, R2
Code:
opcode     source      destination       data
0010         R2 10          01                  disable

mov the content of R3 into Accumulator
mov A, R3
Code:
opcode     source      destination       data
0010         R3 11          01                 disable

don't use any register disable
Code:
opcode       source       destination       data
0010               00               00                 xx      don't use register
 
Last edited:

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
You'll have to explain that to me.

Why is there data if you move from a register to an accumulator? And what is the difference between an accumulator and a register?

You need to understand assembly language first. Which assembly language are you familiar with?
 

vead

Nov 27, 2011
473
Joined
Nov 27, 2011
Messages
473
Why is there data if you move from a register to an accumulator?
ok its my mistake
And what is the difference between an accumulator and a register?
register is ram memory register
alu has accumulator register , accumulator is destination resister for all other calculation

Which assembly language are you familiar with?[/
I know little bit about 8051 assembly language
 
Last edited:

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
I know little bit about 8051 assembly language
It might be a good idea if you knew a LOT about 8051 assembly language.

The 8051 architecture is a bit unusual, but IMO it's a nice design and well worth learning. It may be an old design, but NXP, Atmel and others make many 8051-based variants that are widely used, even now.

https://en.wikipedia.org/wiki/Intel_MCS-51#Derivate_vendors
http://www.computer-solutions.co.uk/info/micro-search/8051/8051_tutorial.htm

I suggest that you buy a few devices, get an 8051 assembler (there are lots of free ones available), and try writing a few programs. Just something that blinks an LED is a good start.

http://sourceforge.net/projects/mcu8051ide/
https://www.pjrc.com/tech/8051/

To be honest, I don't think the studying you have been doing so far has been improving your knowledge of microcontroller and microprocessor principles.

You could spend years learning the theory of microcontrollers, but a few weeks actually playing with one, and looking at the opcodes produced by your assembler, might really improve your understanding of microcontrollers in general.

(The links I've included here are all from the first page of Google searches on 8051 variants and 8051 assembler.)
 

vead

Nov 27, 2011
473
Joined
Nov 27, 2011
Messages
473
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.

data transfer instruction from A resistor to R1 resistor
Instruction set
Code:
c c c c c c a b b b b r r r r r data
----------- - ------- ---------
--opcode--- a --bit-- register data

6 bit op code - specify operation code such as add,mov ,subtract
A (choose memory registers or accumulator )
1 indicate A and 0 indicate memory register
4 bit data
4 bit source - specify the source
5 bit destination -specify the destination
mov A #data
load data with A register
Code:
100010  1  1111 11100 data
----------- - ------- ---------
--opcode--- a --bit-- register data
mov R1 #data
load data with R1 resistor
Code:
100010  0  1111 11100 data
----------- - ------- ---------
--opcode--- a --bit-- register data
 
Last edited:

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
I don't see any question in that post, and I don't know the purpose of it.

data transfer instruction from A resistor to R1 resistor
Code:
c c c c c c a b b b b r r r r r data
----------- - ------- ---------
--opcode--- a --bit-- register data
6 bit op code - specify operation code such as add,mov ,subtract
A (choose memory registers or accumulator )
1 indicate A and 0 indicate memory register
4 bit data
4 bit source - specify the source
5 bit destination -specify the destination
That doesn't really make sense. What are the 4-bit bit number for? What is the data for? If you're transferring data between two registers, or between a register and memory, there is no need to have any data field in the instruction.

I'm sorry to say this, but I really think you aren't "getting it". You seem to be going round in circles and not learning much. My suggestion is:
  • Get hold of some 8051 assembly language code to do something simple
  • Assemble it and program it into a device on a prototyping board with simple I/O
  • Experiment with it to see what it does
  • Analyse the code instruction by instruction and become familiar with the architecture and how each instruction is constructed
  • Experiment with the code to change its behaviour and add features
  • Work through the whole instruction set and try to find a way to use each instruction in the code
  • Keep modifying the code until it does what it should, using the new instruction.
If you have a definite block of code, a definite microcontroller, and some real hardware, we will be able to help you build your understanding, step by step. I don't think you will ever learn MCU architecture by studying and trying to create your own. You are just wasting time that you could be spending getting real hands-on experience and understanding.
 

vead

Nov 27, 2011
473
Joined
Nov 27, 2011
Messages
473
thank you very much to all members for helping me
look at my another effort

Instruction set
  • opcode - instruction name
  • operand - data or address
6 bit opcode +mode +5 bit source register + 6 bit for destination register
Mode
0 address (without #)
1 number (with #)

Code:
Opcode        instruction       mode                                         example
000000         nop                 0 address                                    ------
000001         Load               1 number                                  Ld A # 12
000010         Load               0 address                                 Ld 12
000100        Add                 0 address                                 Add 12
001000        Add                 1 number                                 Add A # 12
010000        Sub                 0 address                                 Sub 12
100000        Sub                 1 number                                 Sub A #  12
111111        Store               0 address                                ST  12

Assembly code
loads the number 12 into the accumulator
Ld A # 12
Bianry code
Code:
000001  1  00000  001100

Assembly code
Add # 12
Add the number 12 into the accumulator

binary code
Code:
001000  1  00000  001100


stores the result into memory location 12
ST 12
Memory
address number
11 10
12 24
13 05
saves the accumulator result (24) to the memory address 12
Bianry code
Code:
001000  0  00000  001100

Assembly code
Ld A # 12
Add A # 12
ST 12

binary code
Code:
000001  1  00000  001100
001000  1  00000  001100
001000  0  00000  001100

Q tell me theoretically IS this correct instruction set ?
 
Last edited:

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
6 bit opcode +mode +5 bit source register + 6 bit for destination register
There are a few problems there.

You only have five instructions: nop, load, add, sub, and store. You only need THREE bits for the opcode, not six - three bits gives EIGHT combinations.

Why would you have 5 bits to specify the source and 6 for the destination? They would normally be the same size.

In your examples at the end of your post, the 5-bit "source register" field is always 00000 and your instruction assumes "A" as the default register. If all operations use the "A" register, you don't need a source AND a destination field.

You aren't making much progress this way. Read my post 29 and do what I suggested. I don't think you understand the basics properly yet. You need to get something working, then figure out how it's done.
 

vead

Nov 27, 2011
473
Joined
Nov 27, 2011
Messages
473
There are a few problems there.

You only have five instructions: nop, load, add, sub, and store. You only need THREE bits for the opcode, not six - three bits gives EIGHT combinations.
.
I know. I wrote few instruction just for example .I have 256 instruction
Why would you have 5 bits to specify the source and 6 for the destination? They would normally be the same size.
I think it depend upon designer, so I used 1 bit for mode ,5 and 6 bit for other register
its ok I can use same size
In your examples at the end of your post, the 5-bit "source register" field is always 00000 and your instruction assumes "A" as the default register. If all operations use the "A" register, you don't need a source AND a destination field.

I wrote that example just for paper exercise

Ld A #5
Ld R1#3
Add A,R1

look this example here I am using source and destination register
my main problem that I don't understand how to specify the operand ?

If I have accumulator , memory register R1,R2 R3..................etc

Q1how to know that which register use as source register or destination register . ?

because both accumulator and memory register can be used as source or destination

Q2how to make binary sequence for instruction set ( opcode source and destination register ) ?

I already made some sequence but I am getting problem when I try to make binary sequence for following example
Add A,R1
 
Last edited:

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
So you want to be able to specify either register, memory, or immediate data.

Have a look at how it's done in existing processors. Most processors don't encode every instruction in a single instruction word; they usually have some instructions that take two or three words. If you want to encode every instruction in a single instruction word, you will need a long instruction word. I believe there are devices designed like this - VLIW (very long instruction word) RISC (reduced instruction set computer) processors.

If you want to go in that direction, how about using a two-bit register/memory/immediate field for the source and a separate register/memory bit for the destination? And designate a particular register as the accumulator; for example, R0.

If you have 8-bit registers, your immediate values need to be eight bits wide. This would then force your register number and memory address fields to be eight bits wide as well.

Here's a possible scheme. I do not recommend it!
Code:
Instruction word structure:
c c c c c c c c . . . . . . . . . . . . . . . . . . .  Opcode (8 bits)
. . . . . . . . s s s s s s s s s s . . . . . . . . .  Source specification (10 bits)
. . . . . . . . . . . . . . . . . . d d d d d d d d d  Destination specification (9 bits)
(Total instruction word length = 25 bits.)

Source specification:
0 0 i i i i i i i i  Immediate 8-bit value
0 1 x x x x x x x x  Not used
1 0 r r r r r r r r  Register
1 1 m m m m m m m m  Memory

Destination specification:
0 r r r r r r r  Register
1 m m m m m m m m  Memory
The source specification can be immediate data, register, or memory. Immediate data doesn't make sense for the destination, so you would only need one r/m (register/memory) bit.

There are better approaches. One is to map the registers into memory, so there's no difference between a "register" access and a memory access. Then you only need to distinguish between immediate and memory for the source, so the source specification would be nine bits wide, and the destination would always be a memory address. That would reduce the instruction word length from 25 to 23 bits.

As I said before, you should get familiar with the instruction sets used on various devices. The people who designed them had a lot of experience, and designed their instruction set and device architecture carefully, to be efficient, logical and clean. (Microchip PIC excepted LOL!)
 

vead

Nov 27, 2011
473
Joined
Nov 27, 2011
Messages
473
Instruction set
c c c c xxxxxx xxxxxx 4 bit opcode
xxxx s s s s s s xxxx xx 6 bit source register specification
xxxx xxxxxx d d d d d d 6 bit destination register

Source specification
00 xxxx Immediate
01 xxxx Not used
10 xxxx register
11 xxxx memory

destination specification
00 xxxx register
01 xxxx memory

source specification

00 xxxx Immediate

Code:
D       A          B                          example
0       00       0000                      mov #0
1       00       0001                      Mov  #1
2       00       0010                      mov#2
3       00       0011                      mov#3
4       00       0100                      mov#4
5       00       0101                      mov#5
6       00       0110                     mov#6
7       00      0111                       mov #7
8       00      1000                       mov #8
9       00      1001                       mov#9
10     00      1010                       mov#10
11     00      1011                       mov#11
12     00      1100                       mov #12
13     00       1101                      mov #13
14     00       1110                      mov #14
15     00        1111                     mov #15


10 xxxx register

Code:
  A          10          0000           mov A
  R1        10          0001           mov R1
  R2        10         0010           mov R2
  R3        10         0011           mov R3
  R4        10         0100           mov R4
  R5        10         0101           mov R5
  R6        10         0110           movR6
  R7         10        0111           movR7
  R8         10        1000           movR8
  R9         10        1001           movR9
  R10       10        1010           Mov R10
  R11       10       1011           mov R11
  R12       10       1100          MovR12
  R13       10       1101           MovR13
  R14       10       1110           MovR14
  R15       10       1111           MovR15

11 xxxx memory
I mean r instead of R
Code:
  R0         11       0000           mov R0
  R1        11        0001           mov R1
  R2        11         0010           mov R2
  R3        11         0011           mov R3
  R4        11         0100           mov R4
  R5        11         0101           mov R5
  R6        11         0110           movR6
  R7         11        0111           movR7
  R8         11        1000           movR8
  R9         11        1001           movR9
  R10       11        1010           Mov R10
  R11       11       1011           mov R11
  R12       11       1100          MovR12
  R13       11       1101           MovR13
  R14       11       1110           MovR14
  R15       11       1111           MovR15

destination specification
10 xxxx register
Code:
  A          00          0000           mov A
  R1        00          0001           mov R1
  R2        00         0010           mov R2
  R3        00         0011           mov R3
  R4        00         0100           mov R4
  R5        00         0101           mov R5
  R6        00         0110           movR6
  R7         00        0111           movR7
  R8         00        1000           movR8
  R9         00        1001           movR9
  R10       00        1010           Mov R10
  R11       00       1011           mov R11
  R12       10       1100          MovR12
  R13       10       1101           MovR13
  R14       10       1110           MovR14
  R15       10       1111           MovR15

11 xxxx memory
I mean r instead of R
Code:
  R0         11       0000           mov R0
  R1        11        0001           mov R1
  R2        11         0010           mov R2
  R3        11         0011           mov R3
  R4        11         0100           mov R4
  R5        11         0101           mov R5
  R6        11         0110           movR6
  R7         11        0111           movR7
  R8         11        1000           movR8
  R9         11        1001           movR9
  R10       11        1010           Mov R10
  R11       11       1011           mov R11
  R12       11       1100          MovR12
  R13       11       1101           MovR13
  R14       11       1110           MovR14
  R15       11       1111           MovR15

opcode

Code:
mov 1010
add   1011

assembly code
mov A # 4
mov R1#4
add A,R1

binary code from the table
Code:
Instruction set
c c c c                    4 bit opcode
s s s s s s            6 bit source register specification
d d d d  d d             6  bit destination register
00  specify source register  immediate value (00 0100),
10 specify destination register (10 0000 accumulator , 10 0001 R1 register

opcode   destination          source
1010     10      0000         00       0100       ;mov A # 4
1010      10     0001         00      0100       ;mov R1 # 4
1011      10     0000        10      0010        mov A,R1


destination specification
00 xxxx register
01 xxxx memory

I can specify destination like this
0 x xxxx register
1 x xxxx memory

I have doubt in above table ?
please look this table and tell me I am getting something ?
 
Last edited:

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
Source specification
00 xxxx Immediate
01 xxxx Not used
10 xxxx register
11 xxxx memory
That only allows you to load 4-bit immediate values into registers or memory locations. What size do you want your registers to be? 4-bit registers are only used on very simple micros - the kind that are used in digital watches.
destination specification
10 xxxx register
11 xxxx memory
Why have two bits to select between register and memory? The first bit is always 1.

Your instruction lists are wrong. I'll show you some example instructions using the instruction word allocation you specified.
Code:
c c c c . . . . . . . . . . . .  Opcode (4 bits):
0 0 0 0 . . . . . . . . . . . .  nop
0 0 0 1 . . . . . . . . . . . .  move from source to dest
0 0 1 0 . . . . . . . . . . . .  add source to dest
0 0 1 1 . . . . . . . . . . . .  subtract source from dest
. . . . t t d d d d . . . . . .  Source data type and specification:
. . . . 0 0 i i i i . . . . . .  Immediate (iiii is 4-bit data)
. . . . 0 1 x x x x . . . . . .  (not used)
. . . . 1 0 r r r r . . . . . .  Register (rrrr specifies the register)
. . . . 1 1 a a a a . . . . . .  Memory (aaaa specifies the address)
. . . . . . . . . . t t s s s s  Destination data type and specification:
. . . . . . . . . . 0 x x x x x  (not used)
. . . . . . . . . . 1 0 r r r r  Register (rrrr specifies the register)
. . . . . . . . . . 1 1 a a a a  Memory (aaaa specifies the address)

Instruction examples:

c c c c  t t  s s s s  t t  d d d d
0 0 0 0  x x  x x x x  x x  x x x x  nop
0 0 0 1  0 0  0 1 1 0  1 0  0 0 1 1  move #0,R3   (set R3 to zero)
0 0 0 1  1 0  0 0 1 1  1 0  1 1 0 1  move R3,R13  (copy value in R3 into R13)
0 0 0 1  1 1  1 0 0 1  1 0  0 1 0 1  move (9),R5  (load R5 from memory location 9)
0 0 0 1  1 0  0 1 0 1  1 1  1 0 0 1  move R5,(9)  (store R5 to memory at location 9)
0 0 1 0  0 0  0 0 1 1  1 0  0 1 0 1  add #3,R5    (add 3 to R5)
0 0 1 0  0 0  0 0 0 1  1 0  0 0 0 1  inc R1       (add 1 to R1)
0 0 1 0  0 1  0 1 0 1  1 1  1 0 0 1  add R5,9     (add R5 to memory at location 9)
0 0 1 1  0 0  0 0 0 1  1 0  0 0 0 1  dec R1       (subtract 1 from R1)
0 0 1 1  1 1  1 0 0 1  1 0  0 1 0 1  sub (9),R5   (subtract value in memory location 9 from R5)
See if you can make sense of those examples. If not, I think you haven't grasped the concepts of registers, memory, addressing, data, and so on. I strongly suggest that you follow my advice back in post #29. You have been working on this for months and you are just going round in circles.
 
Last edited:

vead

Nov 27, 2011
473
Joined
Nov 27, 2011
Messages
473
That only allows you to load 4-bit immediate values into registers or memory locations. What size do you want your registers to be? 4-bit registers are only used on very simple micros - the kind that are used in digital watches.

Why have two bits to select between register and memory? The first bit is always 1.

Your instruction lists are wrong. I'll show you some example instructions using the instruction word allocation you specified.
Code:
c c c c . . . . . . . . . . . .  Opcode (4 bits):
0 0 0 0 . . . . . . . . . . . .  nop
0 0 0 1 . . . . . . . . . . . .  move from source to dest
0 0 1 0 . . . . . . . . . . . .  add source to dest
0 0 1 1 . . . . . . . . . . . .  subtract source from dest
. . . . t t d d d d . . . . . .  Source data type and specification:
. . . . 0 0 i i i i . . . . . .  Immediate (iiii is 4-bit data)
. . . . 0 1 x x x x . . . . . .  (not used)
. . . . 1 0 r r r r . . . . . .  Register (rrrr specifies the register)
. . . . 1 1 a a a a . . . . . .  Memory (aaaa specifies the address)
. . . . . . . . . . t t s s s s  Destination data type and specification:
. . . . . . . . . . 0 x x x x x  (not used)
. . . . . . . . . . 1 0 r r r r  Register (rrrr specifies the register)
. . . . . . . . . . 1 1 a a a a  Memory (aaaa specifies the address)

Instruction examples:

c c c c  t t  s s s s  t t  d d d d
0 0 0 0  x x  x x x x  x x  x x x x  nop
0 0 0 1  0 0  0 1 1 0  1 0  0 0 1 1  move #0,R3   (set R3 to zero)
0 0 0 1  1 0  0 0 1 1  1 0  1 1 0 1  move R3,R12  (copy value in R3 into R12)
0 0 0 1  1 1  1 0 0 1  1 0  0 1 0 1  move (9),R5  (load R5 from memory location 9)
0 0 0 1  1 0  0 1 0 1  1 1  1 0 0 1  move R5,(9)  (store R5 to memory at location 9)
0 0 1 0  0 0  0 0 1 1  1 0  0 1 0 1  add #3,R5    (add 3 to R5)
0 0 1 0  0 0  0 0 0 1  1 0  0 0 0 1  inc R1       (add 1 to R1)
0 0 1 0  0 1  0 1 0 1  1 1  1 0 0 1  add R5,9     (add R5 to memory at location 9)
0 0 1 1  0 0  0 0 0 1  1 0  0 0 0 1  dec R1       (subtract 1 from R1)
0 0 1 1  1 1  1 0 0 1  1 0  0 1 0 1  sub (9),R5   (subtract value in memory location 9 from R5)
See if you can make sense of those examples. If not, I think you haven't grasped the concepts of registers, memory, addressing, data, and so on. I strongly suggest that you follow my advice back in post #29. You have been working on this for months and you are just going round in circles.

ok I will fallow your instruction
I have done few changes in your example
look following zip file

thank you very much for your every help
 

Attachments

  • Instruction word structure.zip
    12.5 KB · Views: 91

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
You seem to have changed the destination specification from a 2-bit type and a 4-bit number to a 1-bit type and a 5-bit number. I guess you did that because the destination type only needs one bit - register/memory. But I think you should keep the bit-width of the source and destination numbers the same. I have changed back to 2-bit type and 4-bit number for the destination, the same as the source specification.

Code:
c c c c  t t  s s s s  t t  d d d d
0 0 0 1  0 0  0 1 1 0  0 0  0 0 1 1  move #6,R3
KrisBlueNZ: That's right. Source is immediate 6,
and destination is register 3.

c c c c  t t  s s s s  t t  d d d d
0 0 0 1  1 0  0 0 1 1  0 0  1 0 1 1  move R3,R12
KrisBlueNZ: Right except for dddd, which is 1 0 1 1 = 11 (decimal).
My post had an error there too, which I've just fixed.

c c c c  t t  s s s s  t t  d d d d
0 0 0 1  1 0  0 1 0 1  1 0  1 0 0 0  move R5,(9)
KrisBlueNZ: That's right except for dddd which is 1 0 0 0
which is 8 decimal, not 9. Your use of 1 0 as the destination
type was right because you only had one bit for the
destination type specification.

c c c c  t t  s s s s  t t  d d d d
0 0 0 1  0 0  1 0 0 1  0 0  0 1 0 0  move (9),R5
KrisBlueNZ: the source type field needs to be 1 1 to
specify a memory address for the source. Your dddd
field needs to be 0 1 0 1 (5 decimal) to specify R5.

c c c c  t t  s s s s  t t  d d d d
0 0 1 0  1 0  0 1 0 1  1  add R5,9
KrisBlueNZ: You have only given eleven bits of the
instruction word.

c c c c  t t  s s s s  t t  d d d d
0 0 1 0  0 0  0 0 1 1  0 0  1 0 0 0  add #3,R5
KrisBlueNZ: Right except the dddd field needs to be
0 1 0 1 (5 decimal) to specify R5.

c c c c  t t  s s s s  t t  d d d d
0 0 1 0  0 0  0 0 0 1  0 0  0 0 1 0  inc R3
KrisBlueNZ: Right except th dddd field needs to be
0 0 1 1 (3 decimal) to specify R3.
 

vead

Nov 27, 2011
473
Joined
Nov 27, 2011
Messages
473
I think I understood the concept of Instruction set
thank you Mr. krisBlueNZ
now I want to Implement some component for processor from this instruction set
ALU
decoder
program counter

I think I have to use 4 bit alu

Q1 can I use 8 to 3 decoder ?
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
That's great that you're starting to understand how the instruction set works. But I think you should get a lot more familiar with what CPU cores do, before you try to design one. The amount of logic you need to build an ALU, an instruction decoder, etc is pretty large, even for a simple device. You need to have a THOROUGH grasp on what the core needs to do, and the best way to get that is to experiment with one that already works.
 

vead

Nov 27, 2011
473
Joined
Nov 27, 2011
Messages
473
That's great that you're starting to understand how the instruction set works. But I think you should get a lot more familiar with what CPU cores do, before you try to design one. The amount of logic you need to build an ALU, an instruction decoder, etc is pretty large, even for a simple device. You need to have a THOROUGH grasp on what the core needs to do, and the best way to get that is to experiment with one that already works.
ok I have done some homework for specification of 8 bit 8051 controller

8 bit microcontroller specification
8 bit data
8 bit instruction
8 bit alu
8 bit input port
8 bit output port
4k program memory on chip
8k data memory on chip
64k external program memory
64k external data memory
16 bit stack pointer
16 bit data pointer
16 bit program counter

1. The alu might be 4 bit , 8 bit , 16 bit or 32 bit
if data is 4 bit so I choose 4 bit alu

2 the data path may be same or different size
8 bit data with 8 bit instruction
8 bit data with 16 bit instruction
I choose 8 bit data with 8 bit instruction

3.port may be 4 bit , 8 bit depend upon our requirement
I choose 4 bit port

4 rom on chip
depend on how much big program I want to write
option 256,512 1k 4k 8 k

I choose 4k

5 ram on chip
It depend on how much data we want to store
option 256,512 1k 4k 8 k
I choose 4 k

6. 16 bit program counter can address 64 k of memory

7. 16 bit data pointer can address 64 k of memory

but I want to start with small controller


how to Implement specification for controller from instruction set, that is in post #37 ?


how to decide following component ?
1 how many bit for alu ?
2 how many bit for counter ?
3 how many bit for program memory ?
4 how many bit for data memory ?

 
Last edited:
Status
Not open for further replies.
Top