Instruction format
Instruction format
And
And
Addressing modes
Addressing modes
Prepared by Madhurima Patra Prepared by Madhurima Patra 14401062011
Instruction format
Instruction format
•
• An instruction format defines the layout of the bits of An instruction format defines the layout of the bits of
an instruction, in terms of its constituent parts . an instruction, in terms of its constituent parts . •
• The bits of the instruction are divided into groupsThe bits of the instruction are divided into groups
called fields. The most common fields are called fields. The most common fields are
•
• An operation code that specifies the operation to beAn operation code that specifies the operation to be performed.
performed.
•
• An address field that specifies a An address field that specifies a memory address ormemory address or
register. register.
•
• A mode field that tells us how the operand or theA mode field that tells us how the operand or the effective address of the operand is to be found out. effective address of the operand is to be found out.
Types of instruction formats
Types of instruction formats
Various types of instruction formats Various types of instruction formats •
• Three address instructionsThree address instructions
•
• Two address instructionsTwo address instructions
•
• One address instructionsOne 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
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
Immediate addressing mode diagram
Operand Opcode
Instruction
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 A Opcode Instruction Memory Operand AIndirect 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 M Opcode Instruction Memory Operand Pointer to operandRegister addressing mode
• Operand is held in register named in the address field. • EA = R
• Example ADD B
Advantages 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 R Opcode Instruction Registers OperandRegister 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 B Advantage
• Less number of bits are required to specify the register.
Register Indirect addressing mode diagram Register Address R Opcode Instruction Memory Operand Pointer 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
Autoincrement or Autodecrement addressing mode diagram Register Address R Opcode Instruction Memory Operand value 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
Relative addressing mode diagram
Opcode Instruction Memory Operand Contents 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
Indexed addressing mode diagram
I R Opcode Instruction Memory Operand Contents of register Index Register Address A + ABase 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]