GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • COA Tutorial
  • Notes
  • Memory Organisation
  • ISA & Microarchitecture
  • Instruction Formats
  • Digital Electronics
  • Computer Network
  • TOC
  • Compiler Design
  • DBMS
  • Quizzes
  • Introduction2 min read
  • Issues in Computer Design1 min read
  • Von Neumann Architecture5 min read

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — Machine Instructions - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • COA Tutorial
  • Notes
  • Memory Organisation
  • ISA & Microarchitecture
  • Instruction Formats
  • Digital Electronics
  • Computer Network
  • TOC
  • Compiler Design
  • DBMS
  • Quizzes

Machine Instructions

Last Updated : 20 Sep, 2023

Machine Instructions are commands or programs written in the machine code of a machine (computer) that it can recognize and execute. A machine instruction consists of several bytes in memory that tell 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. A machine language program is the collection of machine instructions in the main memory.

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 a machine instruction is

A machine language program is the collection of machine instructions in the main memory.
  • Brackets indicate that a field is optional
  • The 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 “:”
  • The inclusion of spaces is arbitrary, except that at least one space must be inserted; no room would lead to ambiguity.
  • Comment field begins with a semicolon “ ; ”

Example:

Here: MOV R5,#25H;load 25H into R5

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 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).
  • SHL, SHR: Logical Shift rotate instruction 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.

4. 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.

5. Control transfer instructions

- conditional, unconditional, call subroutine and return from subroutine.

  • JMP: Unconditional jump .it includes loop transfer and subroutine and interrupt instructions.
  • JNZ: jump till the counter value decreases to zero. It runs the loop till the value stored in CX becomes zero

 6. 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.

7. 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.

Sample GATE Question

Q.1: Consider the sequence of machine instructions given below: [GATE CSE 2015]

  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

Solution: Correct Answer is (C).

Explanation:

 1   2   3   4   5   6   7   8   9   10   11   12   13
  IF  OF  PO  PO  PO  WB
      IF  OF          PO  PO  PO  PO  PO   WB
          IF          OF                   PO   WB
              IF          OF                    PO   WB
Comment

Explore

    Basics
    • Introduction2 min read
    • Issues in Computer Design1 min read
    • Von Neumann Architecture5 min read
    • Harvard Architecture3 min read
    • Addressing Modes7 min read
    • RISC vs CISC3 min read
    • Flynn's Taxonomy3 min read
    Instruction Execution & Formats
    • Instruction Cycles4 min read
    • Machine Instructions5 min read
    • Instruction Formats5 min read
    • 2 and 1 Address Instructions2 min read
    • 3 and 0 Address Instruction4 min read
    • Register content and Flag status3 min read
    Instruction Design and Format
    • ALU Functions and Bus Organization5 min read
    • Computer Arithmetic5 min read
    • 1's vs 2's Complement3 min read
    • Restoring Division Algorithm3 min read
    • Non-Restoring Division Algorithm3 min read
    • Booth's Algorithm4 min read
    Microprogrammed Control
    • Control Unit4 min read
    • Hardwired and Micro-programmed Control Unit3 min read
    • Micro-Operation2 min read
    • Micro Instructions Sequencer4 min read
    • Microarchitecture and ISA3 min read
    • Program Control Instructions4 min read
    • CALL and JUMP instructions5 min read
    Input and Output Organization
    • I/O Interface4 min read
    • Memory Mapped I/O and Isolated I/O5 min read
    • Priority Interrupts5 min read
    • DMA Controller2 min read
    • Asynchronous I/O synchronization5 min read
    • Input-Output Processor5 min read
    • Bus System3 min read
    • MPU Communication2 min read
    Memory Organization
    • Memory and Memory Units2 min read
    • Memory Hierarchy Design6 min read
    • Cache Memory3 min read
    • Cache Organization3 min read
    • Virtual Memory7 min read
    • CPU Cache vs TLB4 min read
    • NUMA vs UMA Architectures3 min read
    Pipelining
    • Execution and Throughput4 min read
    • Instruction Level Parallelism5 min read
    • Types and Stalling3 min read
    • Dependencies and Data Hazard5 min read
    Courses
    • GATE CS/IT/DA Courses2 min read
    • DSA and System Design Course2 min read
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.