A microprocessor, also known as a processor or central processing unit (CPU), is a semiconductor device that contains the basic computing, logic and control circuits that form the core of computer operations. A single chip microprocessor is a series of semiconductors, each of which contains its circuit in a single piece of silicon, usually a silicon gate chip.
The Intel Corporation introduced the Intel 4004 in 1971, it was the first commercially available microprocessor and it is one of the most popular microprocessors in the history of computing. It was a 4-bit CPU designed for use in high-performance computers such as the IBM PC-II and the Apple II. The chip, clocked at 740 kHz, used a 10um-2 process with silicon gates that executed 92, 000 commands per second, resulting in one instruction every 11 microseconds. It had a total of 2, 300 transistors.
The design of the chip began in April 1970, when Federico Faggin joined Intel, and under his leadership it was completed in January 1971. A major technical obstacle was the adaptation of silicon gate technology, which Faggin had been working on to adapt chip sizes that were economical and practicable in volume production. The aluminum gate MOS transistors consumed twice as much silicon, were three to four times slower, had a higher leakage current and lower reliability compared to silicon gate transistors. In order to manufacture silicon gates for this technology, he had to work with another type of transistor, an aluminum-metal-oxide semiconductor gate transistor (AMOS).
In March 1971, the fully functional 4004 was launched. The 4004 was a huge success, which eventually led to the 8088 chip driving the IBM PC and its clones, as well as the introduction of the Intel 4002 and 4003. The success of this product established the commercial feasibility of the microprocessor concept and led to a PC revolution that enabled the development of a wide range of PCs, from home and office computers to automotive and military computers.
Before we begin we must have a basic idea of two terms -
- registers - mainly used to store data while certain registers have special functions.
- flip-flops - used for storing and changing bits of data ; the essential element of what we call as memory
STACK :
Stack is an abstract data-type and data is filled in the format Last In First Out or LIFO. The picture below should be pretty much convincing. Push means adding something to the stack ; and pop means removing something from the stack. It's just like say a pile of books. I cannot get the lower most book out until all the books above it are removed. The last book on the stack is the first that can come out. A stack pointer points to the top of this stack.
Now why in microprocessor we use stack to store information ? There is a similar data-type named Queue which follows First In First Out or FIFO.
In most of the processors now a days stack is used instead of queue. This is because stack only needs one pointer to point to the top ; but Queue needs two pointers to denote the rear and the front and it is not that must efficient. Thus instructions are stored in stack format and the stack pointer points to the first one. As soon as the first instruction is fetched ; the stack pointer increments ; to point to the second instructions address. As soon as the information is fetched it is stored in instruction register.
A simple C program to show how a stack is implemented using array :
#include <stdio.h>
#define SIZE 20
int stack[SIZE];
int top = -1;
void push(int value)
{
if(top<SIZE-1)
{
if (top < 0)
{
stack[0] = value;
top = 0;
}
else
{
stack[top+1] = value;
top++;
}
}
else
{
printf("Stackoverflow!!!!\n");
}
}
int pop()
{
if(top >= 0)
{
int n = stack[top];
top--;
return n;
}
}
int Top()
{
return stack[top];
}
int isempty()
{
return top<0;
}
void display()
{
int i;
for(i=0;i<=top;i++)
{
printf("%d\n",stack[i]);
}
}
int main()
{
push(4);
push(8);
display();
pop();
display();
return 0;
}
Instruction register :
Instruction register is the part of a CPU's control unit that holds the instruction currently that is being executed or decoded. In the instruction cycle, the instruction is loaded into the instruction register after the processor fetches it from the memory location pointed to by the program counter. Decoding the op-code in the instruction register includes determining the instruction, determining where its operands are in memory, retrieving the operands from memory, allocating processor resources to execute the command. The output of the IR is available to control circuits, which generate the timing signals that control the various processing elements involved in executing the instruction.
Code pointer (or instruction pointer) points to code memory so that CPU knows which instruction should be fetched next; after execution of almost any instruction this pointer is automatically advanced - however various "jump" instructions may change its value arbitrarily; it has size of 12 bits so up to 4096 code cells could be addressed (each instruction takes either 1 or 2 cells);
Instruction Decoder :
The Instruction Decoder reads the next instruction in from memory, and sends the component pieces of that instruction to the necessary destinations. The machine reads the opcode( an opcode is the portion of a machine language instruction that specifies the operation to be performed. ) field to determine what type of instruction it is, and where the other data values are as needed. The instruction word may even be read in piece by piece, so decisions may be made at each stage as to how the remainder of the instruction word and any included data will be read. For each machine-language instruction, the control unit produces the sequence of pulses on each control signal line required to implement that instruction (and to fetch the next instruction).
Data bus :
A data bus is a system within a computer or device, consisting of a connector or set of wires, that provides transportation for data. Different kinds of data buses have evolved along with personal computers and other pieces of hardware. Data bus carries both information and data. After decoding the instruction ; the timing and control circuit is triggered and it then through the data bus all the required data is supplied to their locations. Say a 25H number is transported through data bus to the Accumulator .
Registers :
There are 16 general purpose register in pairs and one special purpose register called Accumulator. Registers are used for storing data. In 4004 we have 4-bit registers which when used in pair ; can store 8 bit values. As a reminder ; all calculations and information and everything are done or stored in Hexadecimal. So as I was saying we have two types of registers :
1. 16 General purpose registers from r0 to r15.
2. Accumulator which is also a general purpose register has much more power than others of it's kind.
Accumulator :
Accumulator gets it's name as it stores the output. In 8085 when we type ADD B ; it means the hexadecimal value in B register is fetched and is carried through the data bus, then the accumulator adds the value of B onto itself and stores in itself. Thus it is called the accumulator. Accumulator can do a lot of stuff ; like it can be incremented or decremented. It can be shifted left or right ; can be tested for odd-even ; negative-positive ; carry over ; and zero.
General purpose registers :
General purpose registers are mainly used for storing values and some supplementary functions to the accumulator. These resistors can be used even for 8 bit Arithmetic and Logic functions. Say addition ; when we add two 8-bot numbers ; then the 8 bit number is divided into two parts Lower four bit and higher four bit ; Now in 8085 ; the two lower four bits called lower nibble are added ; and if there is a carry then it is stored in supplementary carry ; Next the two higher four-bits called higher nibble and the carry are added and if there is again a carry then it is stored in carry Flag. But in 4004 ; there is no supplementary Carry flag. So there is only carry flag .
Carry (or CY
) stores the carry over of an operation. It keeps a single bit which is mainly used as fifth bit of Acc
in arithmetic operations. that is if we add 9+10 result is greater than 15
(maximum value which could be stored in 4
bits) so the highest bit is stored in the CY
flag.
Temp register : It stores the data fetched. Say when we want to add two numbers. one number is loaded into the accumulator and the other number is stored into any general purpose register and then stored into the temp register.
ALU( Arithmetic and Logical Unit ) : This unit does all the arithmetic and logic calculations like addition, subtraction and others.
This is the ALU of Microprocessors like 8085 which uses 8 bit data input.
Let's take an example of how addition is done and then we will write down a code to add two numbers ----
Below you can see how we can add two three bit binary number using one half-adder and two full adders :
Half adders adds two inputs and produces output along with carry ( C ) ; while Full adder can take two inputs along with carry ( Cin ) to produce output and carry ( Cout ) . So the basic difference is that half adder can take two inputs only----does not consider previous carry ; while full adder adds two inputs + the carry ( Cin ) which was left from a previous calculation . You find this concept very useful while understanding the code below
Now let's focus on the code below :
fim means fetch immediately ; that is fetch the hexadecimal number 49 in the register r0 and r1 as a pair ; as 49 in hexadecimal is a 8 bit number ; as the registers each can store a max of 4 bit. So higher bits is stored in r0 and the lower in r1.
ld means Load the value of a register into the accumulator ;
add r3 means -----value in ( accumulator=accumulator + r3 )
xch r1 means Exchange accumulators and r1's value.
After these operations r0:r1
shows results of $91
. When we added the higher nibbles ( 4+ 3 ) the Carry was also added from previous summation.
fim r0 $49 ; r0 = 4 and r1 = 9
fim r2 $37 ; r2 = 3 and r3 = 7
; Addition of lower nibbles (9 and 7)
clc ; carry = 0
ld r1 ; acc = r1
add r3 ; acc += r3
xch r1 ; store result back to r1
; the carry is not cleared after that
; concept of full adder
; Addition of higher nibbles (4 and 3)
ld r0 ; acc = r0
add r2 ; acc += r2
xch r0 ; store result to r0
Now let's pause and ponder what would happen when after the whole program is run ; time is inverted ; Every event will run backwards ; the clock pulse will move backwards ; the output seems to be fed in as input ----a single input giving two outputs ------which were initially the inputs. Can the adder circuit function in reverse ??????? What effect will the reverse time pulse have on it ?????
Flag flip-flips :
Flop-flops are electronic components which store 0 or 1 ; so their basic function is storing bits of data. There are majorly 4 types of flip flops, with the most common one being SR flip flop. This simple flip flop circuit has a set input (S) and a reset input (R). In this circuit when you Set “S” as active the output “Q” would be high and “ Q' ” will be low. Once the outputs are established, the wiring of the circuit is maintained until “S” or “R” go high, or power is turned off .
You can see that the last one is not a valid entry of the SR Flip flop . This condition is overcame by JK flip flop which is a modification of SR flip flop .
The J-K flip-flop is the most versatile of the basic flip-flops . If J and K are both low then no change occurs ; it is called the memory condition . If J and K are both high at the clock edge then the output will toggle from one state to the other called as race around condition which can be converted into toggling in JK masterslave . Rest of the times when J is not equal to K ; it behaves like SR flip flop .
You can see when J is 1 and K is 0 then Q is 1 ; and vice-versa for J= 0 . Therefore we can see that the J-K flip flop stores bits of data .
Using all these knowledge we will build our own 1 bit-RAM now .
The 1-bit RAM consists of a SR flip-flop , two AND gates , and one NOT gate . It is a 1-bit read/write memory having three inputs and one output . To read data out or to write data into the cell , the address input line is excited to state 1 . For the write operation , the write enable line is also excited to state 1 . If the write input is a logic state 1 , the circuit shows that S=1 and R=0 . Hence Y=1 that is the input 1 is stored in the memory . The output of the final AND gate that is the read out data is also 1 . This confirms that the write operation has been correctly executed . Similarly , the alternative logic state 0 can be written into or read out from the unit.
Now let's bring our focus back to 4004
There are four flip-flops in the flag register of 4004 :
- Sign(S)- checks sign of number.
- zero(z)- checks whether the number as input or output is 0 or not
- Parity(P) - checks whether the number is odd or even.
- Carry(C) - checks and stores the carry or higher bit.
Decimal adjust :
The DAA (Decimal Adjust after Addition) instruction allows addition of numbers represented in 8-bit packed BCD code. It is used immediately after normal addition instruction operating on BCD codes.
For the processor there is no difference between a BCD and a hexadecimal number, all numbers are seen as hexadecimal numbers. After performing an addition and the result is saved in the Accumulator register, conversion to decimal is carried out as follows:
- if the digit in the lower four nibbles of ACC is greater than 10 (decimal),
- then subtract 10 and
- add 1 to the digit in the higher four nibbles of ACC.
Example:
Suppose that the result obtained after adding 27 to 35, is 5CH. To convert this to the value that we would expect after a decimal addition, the DAA instruction is used.
- assume result = ACC = 5CH
- digit in the low four nibbles of ACC = C = 12
- then 12 - 10 = 2
- hence keep the 2 and
- add 1 to the digit in the higher four nibbles of ACC 5 + 1 = 6
- The result is thus: 62
Check out these basic instruction sets for a rough idea of microprocessor's functioning :
The pin diagram is best learnt from the original documentation of Intel :
Clock and Timing :
Now here comes the interesting part. Ok ! the title of the topic suggests that computer has it's own time which is different from human time but let's pause and ponder Can we reverse time in computer ?????
Like when we reverse time in computer, a program gives a output before it has been given an input. Then as time passes it slowly reveals the input. At a first glance it may seem a bit like machine learning. You have been given a output, you are trying to guess the input.. But a simple problem like A+B reveals the loophole in this idea. This is that ; there are millions and millions of combinations that can add up to a certain number. The number of cases increase as the size of the number increases and it becomes impossible to predict.
Computer memory consists of a basic element called flip-flops and registers. Various flip-flop stores various bits of data and those bits changes when they are triggered. Now comes the most interesting part, how the triggering occurs. It occurs due to a time pulse. Consider a pulse wave which is generated by exciting a Quartz crystal. Now a computer does not understand time as we do. So it should be constantly triggered to make it go on. Depending on the configuration and mode of application, Flips-flops are triggered to change their value based on various properties of this time wave. As for example, edge triggering. Say in Toggle flip-flop, when the signal goes from low to high, the flip-flop inverts the previously stored value and, when the time signal is low, it retains the value ; again when it goes from low to high it inverts the value. This example plays a various crucial part in 8085 microprocessor clocking as the Quartz crystal creates a pulse of 6 kilo Hz and say 30 duty cycle ; but the microprocessor needs 50 duty cycle ; so the toggle flip-flop plays an important role.
We all know that Christopher Nolan's movie TENET is going to release this year. It is based on time reversal or time inversion. It may seem a bit of Sci-fi but well ; it is not totally impossible. Human brain cells can sense upto 11 dimensions - a revelation thanks to the blue-brain project ; but it cannot sense the essence of space-time ; as we are all bound to the entropy of time ; where the arrow of time is forwards ; but as Stephen Hawking said there exists places in another universe ; where the arrow of time may be in the opposite direction.
In the series of DIGITAL TENET, we will explore how we can reverse time in our computers and how we can experience those things for real. But firstly we must study about basic microprocessor, so I gave you the rough idea of the most basic one------ Intel 4004. In the first part of this series we will discuss what will happen if we reverse time in the computer ; will time inversion effect how a computer works or will it work at all ??? We will explore the flaws in normal computing ; and thereafter how we can make a device which will work when the direction of time and the entropy of information reverses. we will also discuss, how to make a simple processor which will work even when time is inverted. It will be a lot of fun.
In the second part I will discuss how to use quantum computing to make the ultimate time reversible computer .
So I will recommend everyone to brush up your skills of microprocessor and quantum mechanics first ; then you will truly enjoy the series of DIGITAL TENET. Thank you.
Comments