Upload
madhurimapatra1987
View
39
Download
5
Tags:
Embed Size (px)
Citation preview
Instruction format
And
Addressing modes
Prepared by Madhurima Patra
14401062011
Instruction format
• An instruction format defines the layout of the bits of an instruction, in terms of its constituent parts .
• The bits of the instruction are divided into groups called fields. The most common fields are• An operation code that specifies the operation to be
performed.
• An address field that specifies a memory address or register.
• A mode field that tells us how the operand or the effective address of the operand is to be found out.
Types of instruction formats
Various types of instruction formats
• Three address instructions• Two address instructions• One address instructions• Zero address instructions
Three address instructions
• Computers with three address instructions use three address fields to specify either a processor register or a memory operand.
• For example
ADD R1, A, B R1M[A] + M[B] As shown, it is clear that in the instruction 3 addresses
are specified. In the above instruction one register address and two memory addresses are specified.
Example of computer using this type of instructions
Cyber 170.
Two address instructions
• Computers that use this type of instruction have two addresses specified in their instructions.
• For example
ADD R1, A R1 R1 + M[A] In this instruction one register is specified and one
memory operand is specified.
In this instruction register R1 is both the source and the destination.
Most commercial computers use this type of instructions.
One address instructions
• In this type of instructions an implied accumulator register is used for all data manipulation.
• For example
LOAD A ACM[A] ADD B ACAC + M[B] All operations are done between the AC register and
a memory operand.
Commercially available computers also use this type of instruction format.
Zero address instructions
• A stack organized computer does not require an address field for computational instructions.
• Due to the absence of the address field it is known as zero address instructions .
• For example
PUSH A TOSA PUSH B TOSB ADD TOS(A+B) The ADD instruction does not need any address field.
Example Burroughs large systems
Addressing modes
• What is addressing mode?
• The addressing mode specifies a rule for interpreting or modifying the address field of the instruction before the operand is actually referenced.
• The way the operands are chosen is dependent on the addressing mode.
Addressing Modes
• Implied addressing mode• Immediate addressing mode• Direct addressing mode• Indirect addressing mode• Register addressing mode• Register Indirect addressing mode• Autoincrement or Autodecrement addressing mode• Relative addressing mode• Indexed addressing mode• Base register addressing mode
Implied addressing mode
• In this mode the operands are specified implicitly in the definition of the instruction.
• Example – ‘complement accumulator’ instruction
CMA• Reason – from the definition itself it is obvious that
we have to complement the operand that is placed in the accumulator.
• All register reference instructions that use an accumulator are implied mode instructions.
Implied addressing mode diagram
Opcode
CMA
Instruction
Immediate addressing mode
• Operand is part of instruction• Operand = address field• Example ADD 5
• Add 5 to contents of accumulator• 5 is operand
Advantages and disadvantages• No memory reference to fetch data• Fast• Limited range
Immediate addressing mode diagram
OperandOpcode
Instruction
ADD 5
Direct addressing mode
• Address field contains address of operand• Effective address (EA) = address field (A)• e.g. LDA A
• Look in memory at address A for operand which is to be loaded in the accumulator.
• Load contents of cell A to accumulator
Advantages and disadvantages
• Single memory reference to access data
• No additional calculations to work out effective address
• Limited address space
Direct addressing mode diagram
Address AOpcode
Instruction
Memory
OperandA
Indirect addressing mode
• Memory cell pointed to by address field contains the address of (pointer to) the operand.
• EA = address contained in memory location M• Look in M, find address contained in M and look there
for operand
• For example
ADD @M
• Add contents of memory location pointed to by contents of M to accumulator
Indirect addressing mode diagram
Address MOpcode
Instruction
Memory
Operand
Pointer to operand
Register addressing mode • Operand is held in register named in the address field.• EA = R• Example ADD BAdvantages and disadvantages• No memory access. So very fast execution. • Very small address field needed .
• Shorter instructions• Faster instruction fetch
• Limited number of registers.• Multiple registers helps performance
• Requires good assembly programming or compiler writing
Register addressing mode diagram
Register Address ROpcode
Instruction
Registers
Operand
Register Indirect addressing mode
• In this the instruction specifies a register whose contents give the address of the operand in memory.
• Therefore EA = the address stored in the register R• Operand is in memory cell pointed to by contents of
register R• Example LDAX BAdvantage• Less number of bits are required to specify the
register.• One fewer memory access than indirect addressing.
Register Indirect addressing mode diagram
Register Address ROpcode
Instruction
Memory
OperandPointer to Operand
Registers
Autoincrement or Autodecrement addressing mode
• This mode is similar to register indirect mode except that the register is automatically incremented or decremented after its value is used to access memory.
• This mode is specially useful when we want to access a table of data.
• For example
INR R1 will increment the register R1.
DCR R2 will decrement the register R2.
Autoincrement or Autodecrement addressing mode diagram
Register Address ROpcode
Instruction
Memory
Operandvalue
Registers
value++
Operand
Relative addressing mode
• In this mode the contents of the program counter is added to the address field of the instruction in order to obtain the effective address.
• EA = A + contents of PC• Example : PC contains 825 and address part of
instruction contains 24.
After the instruction is read from location 825, the PC is incremented to 826. So EA=826+24=850. The operand will be found at location 850 i.e. 24 memory locations forward from the address of the next instruction.
Relative addressing mode diagram
Opcode
Instruction
Memory
OperandContents of register
Program counter
Address A
+
Indexed addressing mode• The contents of an index register is added to the
address field of the instruction to get the effective address.
• The address field of the instruction is the beginning address of the data array in the memory.
• Index register contains a index value which can be incremented or decremented as required.
• Therefore EA = A + IR• Example MOV AL , DS: disp [SI]Advantage• Good for accessing arrays.
Indexed addressing mode diagram
I ROpcode
Instruction
Memory
OperandContents of register
Index Register
Address A
+
A
Base Register addressing mode
• In this mode the content of a base register is added to the address part of the instruction to obtain the effective address.
• The base register contains the address of the beginning of the data array.
• Therefore
EA= A + BR• For example:
MOV AL, disp [BX]
Segment registers in 8086
Base Register addressing mode diagram
BROpcode
Instruction
Memory
OperandContents of register
Base Register
Address A
+
Value of BR