Machine Instructions & Addressing Modes | Computer Architecture & Organisation (CAO) - Computer Science Engineering (CSE) PDF Download

Machine Instructions

Machine Instructions are commands or programs written in machine code of a machine (computer) that it can recognize and execute.

  • A machine instruction consists of several bytes in memory that tells the processor to perform one machine operation.
  • The processor looks at machine instructions in main memory one after another and performs one machine operation for each machine instruction.
  • The collection of machine instructions in the main memory is called a machine language program.

Machine code or machine language is a set of instructions executed directly by a computer’s central processing unit (CPU). Each instruction performs a very specific task, such as a load, a jump, or an ALU operation on a unit of data in a CPU register or memory. Every program directly executed by a CPU is made up of a series of such instructions.

The general format of machine instruction is

Machine Instructions & Addressing Modes | Computer Architecture & Organisation (CAO) - Computer Science Engineering (CSE)

  •  Brackets indicate that a field is optional
  • Label is an identifier that is assigned the address of the first byte of the instruction in which it appears. It must be followed by “:”
  • Inclusion of spaces is arbitrary, except that at least one space must be inserted; no space would lead to an ambiguity.
  • Comment field begins with a semicolon “ ; ”

Example:

Machine Instructions & Addressing Modes | Computer Architecture & Organisation (CAO) - Computer Science Engineering (CSE)

Question for Machine Instructions & Addressing Modes
Try yourself:
What is machine code or machine language?
View Solution
 

Machine instructions used in 8086 microprocessor

1. Data transfer instructions move, load exchange, input, output.

  • MOV :Move byte or word to register or memory .
  • IN, OUT: Input byte or word from the port, output word to port.
  • LEA: Load effective address
  • LDS, LES Load pointer using data segment, extra segment .
  • PUSH, POP: Push word onto stack, pop word off stack.
  • XCHG: Exchange byte or word.
  • XLAT: Translate byte using look-up table.

2. Arithmetic instructions – add, subtract, increment, decrement, convert byte/word and compare.

  • ADD, SUB: Add, subtract byte or word
  • ADC, SBB :Add, subtract byte or word and carry (borrow).
  • INC, DEC: Increment, decrement byte or word.
  • NEG: Negate byte or word   (two’s complement).
  • CMP: Compare byte or word (subtract without storing).
  • MUL, DIV: Multiply, divide byte or word (unsigned).
  • IMUL, IDIV: Integer multiply, divide byte or word (signed)
  • CBW, CWD: Convert byte to word, word to double word
  • AAA, AAS, AAM,AAD: ASCII adjust for add, sub,  mul, div .
  • DAA, DAS: Decimal adjust for addition, subtraction (BCD numbers)

3. Logic instructions – AND, OR, exclusive OR, shift/rotate and test

  • NOT :   Logical NOT of byte or word (one’s complement)
  • AND:  Logical AND of byte or word
  • OR: Logical OR of byte or word.
  • XOR: Logical exclusive-OR of byte or word
  • TEST: Test byte or word (AND without storing).
  • Shift, rotate instruction- SHL, SHR Logical shift left, right byte or word? by 1or CL
  • SAL, SAR Arithmetic shift left, right byte or word? by 1 or CL
  • ROL, ROR Rotate left, right byte or word? by 1 or CL .
  • RCL,  RCR Rotate left, right through carry byte or word? by 1 or CL.

5. String manipulation instruction – load, store, move, compare and scan for byte/word

  • MOVS: Move byte or word string
  • MOVSB, MOVSW: Move byte, word string.
  • CMPS:  Compare byte or word string.
  • SCAS S: can byte or word string (comparing to A or AX)
  • LODS, STOS:  Load, store byte or word string to AL.

6. Control transfer instructions – conditional, unconditional, call subroutine and return from subroutine.

  • JMP:Unconditional jump .it includes loop transfer and subroutine and interrupt instructions.

 7. Loop control instructions-

  •  LOOP: Loop unconditional, count in CX, short jump to target address.
  • LOOPE (LOOPZ): Loop if equal (zero), count in CX, short jump to target address.
  • LOOPNE (LOOPNZ): Loop if not equal (not zero), count in CX, short jump to target address.
  • JCXZ: Jump if CX equals zero (used to skip code in loop).
  • Subroutine and Interrupt instructions-
  • CALL, RET:  Call, return from procedure (inside or outside current segment).
  • INT, INTO:  Software interrupt, interrupt if overflow.IRET: Return from interrupt.

8. Processor control instructions-

Flag manipulation:

  • STC, CLC, CMC:  Set, clear, complement carry flag.
  • STD, CLD:  Set, clear direction flag.STI, CLI: Set, clear interrupt enable flag.
  • PUSHF, POPF: Push flags onto stack, pop flags off stack.

Question for Machine Instructions & Addressing Modes
Try yourself:
Which instruction is used to move a byte or word to a register or memory in the 8086 microprocessor?
View Solution

Example: Consider the sequence of machine instructions given below:

MUL R5, R0, R1
DIV R6, R2, R3
ADD R7, R5, R6
SUB R8, R7, R4

In the above sequence, R0 to R8 are general purpose registers. In the instructions shown, the first register stores the result of the operation performed on the second and the third registers. This sequence of instructions is to be executed in a pipelined instruction processor with the following 4 stages: (1) Instruction Fetch and Decode (IF), (2) Operand Fetch (OF), (3) Perform Operation (PO) and (4) Write back the Result (WB). The IF, OF and WB stages take 1 clock cycle each for any instruction. The PO stage takes 1 clock cycle for ADD or SUB instruction, 3 clock cycles for MUL instruction and 5 clock cycles for DIV instruction. The pipelined processor uses operand forwarding from the PO stage to the OF stage. The number of clock cycles taken for the execution of the above sequence of instructions is ___________
(A) 11
(B) 12
(C) 13
(D) 14

Answer: (C)

Explanation:

Machine Instructions & Addressing Modes | Computer Architecture & Organisation (CAO) - Computer Science Engineering (CSE)

Addressing Modes

The term addressing modes refers to the way in which the operand of an instruction is specified. The addressing mode specifies a rule for interpreting or modifying the address field of the instruction before the operand is actually executed.

Addressing modes for 8086 instructions are divided into two categories:

  1. Addressing modes for data
  2. Addressing modes for branch

The 8086 memory addressing modes provide flexible access to memory, allowing you to easily access variables, arrays, records, pointers, and other complex data types.  The key to good assembly language programming is the proper use of memory addressing modes.

An assembly language program instruction consists of two parts that are given below:

Machine Instructions & Addressing Modes | Computer Architecture & Organisation (CAO) - Computer Science Engineering (CSE)

Important Terms

  • The starting address of the memory segment.
  • Effective address or Offset: An offset is determined by adding any combination of three address elements: displacement, base and index.
  • Displacement: It is an 8 bit or 16-bit immediate value given in the instruction.
  • Base: Contents of base register, BX or BP.
  • Index: Content of index register SI or DI.

Question for Machine Instructions & Addressing Modes
Try yourself:
Which of the following addressing modes allows flexible access to memory in 8086 instructions?
View Solution

Different Addressing Modes Used by 8086

According to different ways of specifying an operand by 8086 microprocessor, different addressing modes are used by 8086.

Addressing modes used by the 8086 microprocessor are discussed below:

  • Immediate mode: In immediate addressing, the operand is specified in the instruction itself. In this mode, the data is 8 bits or 16 bits long and data is the part of instruction.Machine Instructions & Addressing Modes | Computer Architecture & Organisation (CAO) - Computer Science Engineering (CSE) Example:  MOV AL, 35H (move the data 35H into AL register)
  • Register modeIn register addressing the operand is placed in one of 8 bit or 16-bit general-purpose registers. The data is in the register that is specified by the instruction.
    Machine Instructions & Addressing Modes | Computer Architecture & Organisation (CAO) - Computer Science Engineering (CSE)Example: MOV AX, CX (move the contents of CX register to AX register)
  • Register Indirect mode: In this addressing the operand’s offset is placed in any one of the registers BX, BP, SI, DI as specified in the instruction. The effective address of the data is in the base register or an index register that is specified by the instruction.Machine Instructions & Addressing Modes | Computer Architecture & Organisation (CAO) - Computer Science Engineering (CSE)The 8086 CPUs let you access memory indirectly through a register using the register indirect addressing modes.
    MOV AX, [BX](move the contents of memory location s addressed by the register BX to the register AX)
  • Auto-increment mode: Effective address of the operand is the contents of a register specified in the instruction. After accessing the operand, the contents of this register are automatically incremented to point to the next consecutive memory location.
    Example: Add R1, (R2)+  
    OR
    R1 = R1 +M[R2]
    R2 = R2 + d

Note: Useful for stepping through arrays in a loop. R2 – start of array d – size of an element.

  • Auto-decrement modeEffective address of the operand is the contents of a register specified in the instruction. Before accessing the operand, the contents of this register are automatically decremented to point to the previous consecutive memory location. Example: Add R1,-(R2)  
    OR
    R2 = R2-d
    R1 = R1 + M[R2]

Note: Auto decrement mode is same as  auto increment mode. Both can also be used to implement a stack as push and pop . Auto increment and Auto decrement modes are useful for implementing “Last-In-First-Out” data structures.

  • Direct Mode: The operand’s offset is given in the instruction as an 8 bit or 16-bit displacement element. In this addressing mode, the 16-bit effective address of the data is part of the instruction.
    Machine Instructions & Addressing Modes | Computer Architecture & Organisation (CAO) - Computer Science Engineering (CSE)Example: ADD AL,[0301]   //add the contents of offset address 0301 to AL
  • Base addressing: The operand’s offset is the sum of an 8 bit or 16-bit displacement and the contents of the base register BX or BP.BX is used as a base register for a data segment, and BP is used as a base register for a stack segment.
    Example: MOV AL,[BX+05]

Note: Suppose the register BX contain 0301. The offset will be 0301+05=0306. Content of the memory location 0306 will move to AL.

  • Indexed addressing mode: The operand’s offset is the sum of the content of an index register SI or DI and an 8 bit or 16-bit displacement.
    Example: MOV AX, [SI +05]
  • Based Indexed Addressing: The operand’s offset is sum of the content of a base register BX or BP and an index register SI or DI.
    Example: ADD AX, [BX+SI]
  • Based Indexed plus displacement addressing mode: In this mode of addressing the operand’s offset is given by offset=[BX or BP]+[SI or DI]+8 bit or 16-bit displacement.
    Example: MOV AX, [BX+SI+05]

Question for Machine Instructions & Addressing Modes
Try yourself:
Which addressing mode is used when the operand is specified in the instruction itself?
View Solution

  • Intersegment Direct: The effective branch address is sum of 8 or 16 bit displacement and the current contents of IP(Instruction Pointer).It can be used with either conditional or unconditional branching.
  • Intrasegment Indirect: The effective branch address is contents of register or memory location that is accessed using any of the data related addressing mode except immediate mode. It can be used only for unconditional branch instruction.
  • Intersegment Direct: Replaces the content of IP with part of the instruction and the contents of CS with another part of the instruction. This mode is provide a way of branching from one code segment to another.
  • Intersegment Indirect: Replaces the contents of IP and CS with the contents of two consecutive words in memory that are referenced using any one of the data related addressing mode except immediate and register modes.

Question for Machine Instructions & Addressing Modes
Try yourself:
Which addressing mode allows branching from one code segment to another by replacing the content of IP and CS with specific memory locations?
View Solution

Example. Match each of the high level language statements given on the left hand side with the most natural addressing mode from those listed on the right hand side.

1. A[1] = B[J];         a. Indirect addressing
2. while [*A++];        b. Indexed  addressing
3. int temp = *x;       c. Autoincrement

(A) (1, c), (2, b), (3, a)
(B) (1, a), (2, c), (3, b)
(C) (1, b), (2, c), (3, a)
(D) (1, a), (2, b), (3, c)

Answer: (C)

Explanation:

Machine Instructions & Addressing Modes | Computer Architecture & Organisation (CAO) - Computer Science Engineering (CSE)

Hence (C) is the correct solution.

The document Machine Instructions & Addressing Modes | Computer Architecture & Organisation (CAO) - Computer Science Engineering (CSE) is a part of the Computer Science Engineering (CSE) Course Computer Architecture & Organisation (CAO).
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
20 videos|86 docs|48 tests

Top Courses for Computer Science Engineering (CSE)

FAQs on Machine Instructions & Addressing Modes - Computer Architecture & Organisation (CAO) - Computer Science Engineering (CSE)

1. What are machine instructions and how are they used in the 8086 microprocessor?
Ans. Machine instructions are the basic operations that a computer's central processing unit (CPU) can perform. In the case of the 8086 microprocessor, these instructions are used to carry out tasks such as arithmetic operations, data movement, and control flow.
2. What are addressing modes in the context of 8086 microprocessor?
Ans. Addressing modes in the 8086 microprocessor refer to the various ways in which the processor can access operands or data during instruction execution. Different addressing modes include immediate, direct, indirect, register, and indexed addressing.
3. What are some important terms related to machine instructions and addressing modes in computer science?
Ans. Some important terms include opcode (operation code), operand (data operated on), memory address, register, instruction set, and program counter (PC).
4. How does the 8086 microprocessor utilize different addressing modes in its instruction set?
Ans. The 8086 microprocessor supports multiple addressing modes, allowing for flexibility in accessing operands and data. This enhances the versatility and efficiency of the processor in executing a wide range of instructions.
5. How do branch-related addressing modes play a role in controlling program flow in the 8086 microprocessor?
Ans. Branch-related addressing modes in the 8086 microprocessor allow for conditional and unconditional branching, enabling the program to make decisions and alter the sequence of instructions based on certain conditions. This helps in implementing loops, branching, and decision-making in programs.
20 videos|86 docs|48 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Important questions

,

Viva Questions

,

pdf

,

Objective type Questions

,

mock tests for examination

,

Free

,

Summary

,

Previous Year Questions with Solutions

,

Machine Instructions & Addressing Modes | Computer Architecture & Organisation (CAO) - Computer Science Engineering (CSE)

,

study material

,

practice quizzes

,

past year papers

,

Machine Instructions & Addressing Modes | Computer Architecture & Organisation (CAO) - Computer Science Engineering (CSE)

,

Exam

,

shortcuts and tricks

,

video lectures

,

Sample Paper

,

Extra Questions

,

ppt

,

Machine Instructions & Addressing Modes | Computer Architecture & Organisation (CAO) - Computer Science Engineering (CSE)

,

Semester Notes

,

MCQs

;