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