Tuesday, August 13, 2013

Explaination how an instruction executed

Any given instruction set can be implemented in a variety of ways. All ways of implementing an instruction set give the same programming model, and they all are able to run the same binary executablesThe various ways of implementing an instruction set give different tradeoffs between cost, performance, power consumption, size, etc.
When designing the microarchitecture of a processor, engineers use blocks of "hard-wired" electronic circuitry (often designed separately) such as adders, multiplexers, counters, registers, ALUs etc. Some kind of register transfer language is then often used to describe the decoding and sequencing of each instruction of an ISA using this physical microarchitecture. There are two basic ways to build a control unit to implement this description (although many designs use middle ways or compromises):
  1. Early computer designs and some of the simpler RISC computers "hard-wired" the complete instruction set decoding and sequencing (just like the rest of the microarchitecture).
  2. Other designs employ microcode routines and/or tables to do this—typically as on chip ROMs and/or PLAs (although separate RAMs have been used historically).
There are also some new CPU designs which compile the instruction set to a writable RAM or flash inside the CPU or an FPGA (reconfigurable computing). The Western Digital MCP-1600 is an older example, using a dedicated, separate ROM for microcode.
An ISA can also be emulated in software by an interpreter. Naturally, due to the interpretation overhead, this is slower than directly running programs on the emulated hardware, unless the hardware running the emulator is an order of magnitude faster. Today, it is common practice for vendors of new ISAs or microarchitectures to make software emulators available to software developers before the hardware implementation is ready.
Often the details of the implementation have a strong influence on the particular instructions selected for the instruction set. For example, many implementations of the instruction pipeline only allow a single memory load or memory store per instruction, leading to a load-store architecture(RISC). For another example, some early ways of implementing the instruction pipeline led to a delay slot.
The demands of high-speed digital signal processing have pushed in the opposite direction—forcing instructions to be implemented in a particular way. For example, in order to perform digital filters fast enough, the MAC instruction in a typical digital signal processor (DSP) must be implemented using a kind of Harvard architecture that can fetch an instruction and two data words simultaneously, and it requires a single-cycle multiply–accumulate multiplier.

Code density

n early computers, memory was expensive, so minimizing the size of a program to make sure it would fit in the limited memory was often central. Thus the combined size of all the instructions needed to perform a particular task, the code density, was an important characteristic of any instruction set. Computers with high code density often have complex instructions for procedure entry, parameterized returns, loops etc. (therefore retroactively named Complex Instruction Set Computers,CISC). However, more typical, or frequent, "CISC" instructions merely combine a basic ALU operation, such as "add", with the access of one or more operands in memory (using addressing modes such as direct, indirect, indexed etc.). Certain architectures may allow two or three operands (including the result) directly in memory or may be able to perform functions such as automatic pointer increment etc. Software-implemented instruction sets may have even more complex and powerful instructions.
Reduced instruction-set computersRISC, were first widely implemented during a period of rapidly growing memory subsystems and sacrifice code density in order to simplify implementation circuitry and thereby try to increase performance via higher clock frequencies and more registers. RISC instructions typically perform only a single operation, such as an "add" of registers or a "load" from a memory location into a register; they also normally use a fixed instruction width, whereas a typical CISC instruction set has many instructions shorter than this fixed length. Fixed-width instructions are less complicated to handle than variable-width instructions for several reasons (not having to check whether an instruction straddles a cache line or virtual memory page boundary[4] for instance), and are therefore somewhat easier to optimize for speed. However, as RISC computers normally require more and often longer instructions to implement a given task, they inherently make less optimal use of bus bandwidth and cache memories.
Minimal instruction set computers (MISC) are a form of stack machine, where there are few separate instructions (16-64), so that multiple instructions can be fit into a single machine word. These type of cores often take little silicon to implement, so they can be easily realized in an FPGA or in a multi-core form. Code density is similar to RISC; the increased instruction density is offset by requiring more of the primitive instructions to do a task.
There has been research into executable compression as a mechanism for improving code density. The mathematics of Kolmogorov complexity describes the challenges and limits of this.

Number of operands

struction sets may be categorized by the maximum number of operands explicitly specified in instructions.
(In the examples that follow, ab, and c are (direct or calculated) addresses referring to memory cells, while reg1 and so on refer to machine registers.)
  • 0-operand (zero-address machines), so called stack machines: All arithmetic operations take place using the top one or two positions on the stack: push apush baddpop c. For stack machines, the terms "0-operand" and "zero-address" apply to arithmetic instructions, but not to all instructions, as 1-operand push and pop instructions are used to access memory.
  • 1-operand (one-address machines), so called accumulator machines, include early computers and many small microcontrollers: most instructions specify a single right operand (that is, constant, a register, or a memory location), with the implicit accumulator as the left operand (and the destination if there is one): load aadd bstore c. A related class is practical stack machines which often allow a single explicit operand in arithmetic instructions: push aadd bpop c.
  • 2-operand — many CISC and RISC machines fall under this category:
    • CISC — often load a,reg1add reg1,bstore reg1,c on machines that are limited to one memory operand per instruction; this may be load and store at the same location
    • CISC — move a->cadd c+=b.
    • RISC — Requiring explicit memory loads, the instructions would be: load a,reg1load b,reg2add reg1,reg2store reg2,c
  • 3-operand, allowing better reuse of data:[4]
    • CISC — It becomes either a single instruction: add a,b,c, or more typically: move a,reg1add reg1,b,c as most machines are limited to two memory operands.
    • RISC — arithmetic instructions use registers only, so explicit 2-operand load/store instructions are needed: load a,reg1load b,reg2add reg1+reg2->reg3store reg3,c; unlike 2-operand or 1-operand, this leaves all three values a, b, and c in registers available for further reuse.
  • more operands—some CISC machines permit a variety of addressing modes that allow more than 3 operands (registers or memory accesses), such as the VAX "POLY" polynomial evaluation instruction.
Due to the large number of bits needed to encode the three registers of a 3-operand instruction, RISC processors using 16-bit instructions are invariably 2-operand machines, such as the Atmel AVR, and some versions of the ARM Thumb. RISC processors using 32-bit instructions are usually 3-operand machines, such as processors implementing the Power Architecture, the SPARC architecture, the MIPS architecture, the ARM architecture, and the AVR32 architecture.
Each instruction specifies some number of operands (registers, memory locations, or immediate values) explicitly. Some instructions give one or both operands implicitly, such as by being stored on top of the stack or in an implicit register. If some of the operands are given implicitly, fewer operands need be specified in the instruction. When a "destination operand" explicitly specifies the destination, an additional operand must be supplied. Consequently, the number of operands encoded in an instruction may differ from the mathematically necessary number of arguments for a logical or arithmetic operation . Operands are either encoded in the "opcode" representation of the instruction, or else are given as values or addresses following the instruction.

8085 Instruction set & Example

INSTRUCTION DETAILS



DATA TRANSFER INSTRUCTIONS

Copy from source to destination
MOV
Rd, Rs
This instruction copies the contents of the source register into the destination register, the contents of Rd, M the source register are not altered.  If one of the operands is a memory location, its location is specified by the contents of the HL registers.
Example:  MOV B, C   or  MOV B, M
M, Rs
Rd, M


Move immediate 8-bit
MVI
Rd, data
The 8-bit data is stored in the destination register or memory.  If the operand is a memory location, its location is specified by the contents of the HL registers.
Example:  MVI B, 57H  or  MVI M, 57H
M, data

Load accumulator
LDA
16-bit address
The contents of a memory location, specified by a 16-bit address in the operand, are copied to the accumulator. The contents of the source are not altered.
Example:  LDA 2034H

Load accumulator indirect
LDAX
B/D Reg. pair
The contents of the designated register pair point to a memory location.  This instruction copies the contents of that memory location into the accumulator.  The contents of either the register pair or the memory location are not altered.
Example:  LDAX B

Load register pair immediate
LXI
Reg. pair, 16-bit data
The instruction loads 16-bit data in the register pair designated in the operand. Example:  LXI H, 2034H  or  LXI H, XYZ

Load H and L registers direct
LHLD
16-bit address
The instruction copies the contents of the memory location pointed out by the 16-bit address into register L and copies the contents of the next memory location into register H.  The contents of source memory locations are not altered.
Example:  LHLD 2040H

Store accumulator direct
STA
16-bit address
The contents of the accumulator are copied into the memory location specified by the operand.  This is a 3-byte instruction, the second byte specifies the low-order address and the third byte specifies the high-order address.
Example:  STA 4350H

Store accumulator Indirect
STAX
Reg. pair
The contents of the accumulator are copied into the memory location specified by the contents of the operand (register pair).  The contents of the accumulator are not altered.
Example:  STAX B

Store H and L registers direct
SHLD
16-bit address
The contents of register L are stored into the memory location specified by the 16-bit address in the operand and the contents of H register are stored into the next memory location by incrementing the operand.  The contents of registers HL are not altered.  This is a 3-byte instruction, the second byte specifies the low-order address and the third byte specifies the high-order address.
Example:  SHLD 2470H

Exchange H and L with D and E
XCHG
none
The contents of register H are exchanged with the contents of register D, and the contents of register L are exchanged with the contents of register E.
Example:  XCHG

Copy H and L registers to the stack pointer
SPHL
none
The instruction loads the contents of the H and L registers into the stack pointer register, the contents of the H register provide the high-order address and the contents of the L register provide the low-order address.  The contents of the H and L registers are not altered.
Example:  SPHL

Exchange H and L with top of stack
XTHL
none
The contents of the L register are exchanged with the stack location pointed out by the contents of the stack pointer register.  The contents of the H register are exchanged with the next stack location (SP+1); however, the contents of the stack pointer register are not altered.
Example:  XTHL

Push register pair onto stack
PUSH
Reg. pair
The contents of the register pair designated in the operand are copied onto the stack in the following sequence.  The stack pointer register is decremented and the contents of the high- order register (B, D, H, A) are copied into that location.  The stack pointer register is decremented again and the contents of the low-order register (C, E, L, flags) are copied to that location.
Example:  PUSH B or PUSH A

Pop off stack to register pair
POP
Reg. pair
The contents of the memory location pointed out by the stack pointer register are copied to the low-order register (C, E, L, status flags) of the operand.  The stack pointer is incremented by 1 and the contents of that memory location are copied to the high-order register (B, D, H, A) of the operand.  The stack pointer register is again incremented by 1.
Example:  POP H or POP A

Output data from accumulator to a port with 8-bit address
OUT
8-bit port address
The contents of the accumulator are copied into the I/O port specified by the operand.
Example:  OUT F8H





Input data to accumulator from a port with 8-bit address
IN
8-bit port address
8-bit port address The contents of the input port designated in the operand are read and loaded into the accumulator.
 Example:  IN 8CH

Saturday, July 13, 2013

Advantages & Disadvantages

Advantages of Microcontrollers

a)      Microcontrollers act as a microcomputer without any digital parts.
b)     As the higher integration inside microcontroller reduce cost and size of the system.
c)      Usage of microcontroller is simple, easy for troubleshoot and system maintaining.
d)     Most of the pins are programmable by the user for performing different functions.
e)      Easily interface additional RAM, ROM,I/O ports.
f)       Low time required for performing operations.

Disadvantages of Microcontrollers

a)      Microcontrollers have got more complex architecture than that of microprocessors.
b)     Only perform limited number of executions simultaneously.
c)      Mostly used in micro-equipments.
d)     Cannot interface high power devices directly.

Comparison between Microprocessor & Microcontroller

Microprocessors                                                                                          Microcontrollers
1It is only a general purpose computer CPUIt is a micro computer itself
2Memory, I/O ports, timers, interrupts are not available inside the chipAll are integrated inside the microcontroller chip
3This must have many additional digital components to perform its operationCan function as a micro computer without any additional components.
4Systems become bulkier and expensive.Make the system simple, economic and compact
5Not capable for handling Boolean functionsHandling Boolean functions
6Higher accessing time requiredLow accessing time
7Very few pins are programmableMost of the pins are programmable
8Very few number of bit handling instructionsMany bit handling instructions
9Widely Used in modern PC  and laptopswidely in small control systems
E.g.INTEL 8086,INTEL Pentium seriesINTEL8051,89960,PIC16F877

Block Diagram & Function of Microcontroller

Block Diagram

  • CPU
CPU is the brain of a microcontroller .CPU is responsible for fetching the instruction, decodes it, then finally executed. CPU connects every part of a microcontroller into a single system. The primary function of CPU is fetching and decoding instructions. Instruction fetched from program memory must be decoded by the CPU.
  • Memory
The function of memory in a microcontroller is same as microprocessor. It is used to store data and program. A microcontroller usually has a certain amount of RAM and ROM (EEPROM, EPROM, etc) or flash memories for storing program source codes.
  • Parallel input/output ports
Parallel input/output ports are mainly used to drive/interface various devices such as LCD’S, LED’S, printers, memories, etc to a microcontroller.
  • Serial ports
Serial ports provide various serial interfaces between microcontroller and other peripherals like parallel ports.
  • Timers/counters
This is the one of the useful function of a microcontroller. A microcontroller may have more than one timer and counters. The timers and counters provide all timing and counting functions inside the microcontroller. The major operations of this section are perform clock functions, modulations, pulse generations, frequency measuring, making oscillations, etc. This also can be used for counting external pulses.
  • Analog to Digital Converter (ADC)
ADC converters are used for converting the analog signal to digital form. The input signal in this converter should be in analog form (e.g. sensor output) and the output from this unit is in digital form. The digital output can be use for various digital applications (e.g. measurement devices).
  • Digital to Analog Converter (DAC)
DAC perform reversal operation of ADC conversion.DAC convert the digital signal into analog format. It usually used for controlling analog devices like DC motors, various drives, etc.
  • Interrupt control
The interrupt control used for providing interrupt (delay) for a working program .The interrupt may be external (activated by using interrupt pin) or internal (by using interrupt instruction during programming).
  • Special functioning block
Some microcontrollers used only for some special applications (e.g. space systems and robotics) these controllers containing additional ports to perform such special operations. This considered as special functioning block.


Introduction of Microcontroller

microcontroller (sometimes abbreviated µCuC or MCU) is a small computer on a single integrated circuit containing a processor core, memory, and programmable input/output peripherals. Program memory in the form of NOR Flash or OTP ROM  is also often included on chip, as well as a typically small amount of RAM. Microcontrollers are designed for embedded applications, in contrast to the microprocessors used in personal computers or other general purpose applications.


1) A microcontroller basically contains one or more following components:
  • Central processing unit(CPU)
  • Random Access Memory)(RAM)
  • Read Only Memory(ROM)
  • Input/output ports
  • Timers and Counters
  • Interrupt Controls
  • Analog to digital converters
  • Digital  analog converters
  • Serial interfacing ports
  • Oscillatory circuits
2) A microcontroller internally consists of all features required for a computing system and functions as a computer without adding any external digital parts in it.
3) Most of the pins in the microcontroller chip can be made programmable by the user.
4) A microcontroller has many bit handling instructions that can be easily understood by the programmer.
5) A microcontroller is capable of handling Boolean functions.
6) Higher speed and performance.
7) On-chip ROM structure in a microcontroller provides better firmware security.
8 ) Easy to design with low cost and small size.

System Bus

system bus is a single computer bus that connects the major components of a computer system. The technique was developed to reduce costs and improve modularity. It combines the functions of a data bus to carry information, an address bus to determine where it should be sent, and a control bus to determine its operation. Although popular in the 1970s and 1980s, modern computers use a variety of separate buses adapted to more specific needs.


There are three buses in Microprocessor:
1.Address Bus
2.Data Bus
3.Control Bus




1.Address Bus:-Genearlly, Microprocessor has 16 bit address bus. The bus over which the CPU sends out the address of the memory location is known as Address bus. The address bus carries the address of memory location to be written or to be read from.
The address bus is unidirectional. It means bits flowing occurs only in one direction, only from microprocessor to peripheral devices.

2.Data Bus:-8085 Microprocessor has 8 bit data bus. So it can be used to carry the 8 bit data starting from 00000000H(00H) to 11111111H(FFH). Here 'H' tells the Hexadecimal Number. It is bidirectional. These lines are used for data flowing in both direction means data can be transferred or can be received through these lines. The data bus also connects the I/O ports and CPU. The largest number that can appear on the data bus is 11111111.

It has 8 parallel lines of data bus. So it can access upto 2^8 = 256 data bus lines.

3.Control Bus:-The control bus is used for sending control signals to the memory and I/O devices. The CPU sends control signal on the control bus to enable the outputs of addressed memory devices or I/O port devices.

Some of the control bus signals are as follows:
1.Memory read
2.Memory write
3.I/O read
4.I/O write.



Saturday, July 6, 2013

Internal Structure and Basic Operation of Microprocesor

Arithmetic Logic Unit The ALU, or the arithmetic and logic unit, is the section of the processor that is involved with executing operations of an arithmetic or logical nature. It works in conjunction with the register array for many of these, in particular, the accumulator and flag registers. The accumulator holds the results of operations, while the flag register contains a number of individual bits that are used to store information about the last operation carried out by the ALU. More on these registers can be found in the register array section.
Control Unit The control unit is arguably the most complicated part of this model CPU, and is responsible for controlling much of the operation of the rest of the processor. It does this by issuing control signals to the other areas of the processor, instructing them on what should be performed next

Accumulator or A register is an 8-bit register used for arithmetic, logic, I/O and load/store operations.

Program counter is a 16-bit register.

Stack pointer is a 16 bit register. This register is always incremented/decremented by 2.

Fetching & Execution Cycles

Fetching cycle is the basic operation cycle of a computer. It is the process by which a computer retrieves a program instruction from its memory, determines what actions the instruction requires, and carries out those actions. This cycle is repeated continuously by the central processing unit (CPU), from bootup to when the computer is shut down.

Execute cycle is the instruction in order to work out what actions should be performed to execute it. This involves examining the opcode to see which of the machine codes in the CPU's instruction set it corresponds to, and also checking which addressing mode needs to be used to obtain any required data. Therefore, using the CPU model from this tutorial, bits 16 to 23 should be examined.

Definition

NIBBLE - In computing, a nibble (often nybble or even nyble to match the vowels of byte) is a four-bit aggregation,or half an octet. As a nibble contains 4 bits, there are sixteen possible values, so a nibble corresponds to a single hexadecimal digit (thus, it is often referred to as a "hex digit" or "hexit").

 BYTE - A byte is a unit of measurement used to measure data. One byte contains eight binary bits, or a series of eight zeros and ones. Therefore, each byte can be used to represent 2^8 or 256 different values. The byte was originally developed to store a single character, since 256 values is sufficient to represent all standard lowercase and uppercase letters, numbers, and symbolsA byte is a unit of measurement used to measure data. One byte contains eight binary bits, or a series of eight zeros and ones. Therefore, each byte can be used to represent 2^8 or 256 different values.

 WORD - word is a term for the natural unit of data used by a particular processor design. A word is basically a fixed-sized group of bits that are handled as a unit by the instruction set and/or hardware of the processor. The number of bits in a word (the word size, word width, or word length) is an important characteristic of any specific processor design or computer architecture.

Evolution of MicroP

Basic Components Computer System using Block Diagram

The Figure of Basic Computer System with block diagram..