Question: Explain the following 8086 instructions ( ANY THREE )
0

a) CMPSB

b) DIV AX

c) LOOPE again

d) REP SCASB

e) XLATB

Mumbai University > Electronics and Telecommunication > Sem 4 > Microprocessor and peripherals

mumbai university mpa • 28 views
ADD COMMENTlink
modified 2 hours ago by gravatar for Ankit Pandey Ankit Pandey ♦♦ 0 written 10 weeks ago by gravatar for kazi.tahoor kazi.tahoor0
0
  • CMPSB-

    Mnemonic: CMPSB (compare string byte)

    Algorithm:

    DS: [SI] – ES: [DI]

    Set flags according to result → OF, SF, ZF, AF, PF, CF

    If DF = 0 then

    SI = SI + 1

    DI = DI + 1 else

    SI = SI – 1

    DI = DI – 1

    Operation:

    • This instruction is used to compare a byte in one string with a byte in another string.
    • SI is used to hold the offset of a byte in the source string and DI is used to hold the offset of byte in another string.
    • Comparison is done by subtracting the byte pointed by DI from byte pointed by SI.
    • After comparison SI and DI will be automatically incremented or decremented according to direction flag to point to next element in the string.
  • DIV AX:-

    Mnemonic: DIV AX

    Algorithm: AX = (DX: AX)/operand (Quotient)

    DX = remainder (Modulus)

    Operation:

    DIV AX

    • If the divisor is 16 bit then the dividend is in DX-AX registers.
    • After division, the quotient is in AX and the remainder in DX.
  • LOOPE again:-

    Mnemonic: Loop while CX ≠ 0 and ZF = 1

    LOOPE again

    Algorithm: CX = CX – 1

    If CX ≠ 0 and ZF = 1 then jump else no jump

    Operation:

    • This instruction is used to repeat a group of instructions some number of times or until zero flag becomes zero.
    • Number of times of repetition is loaded in CX.
  • REP:-

    Mnemonic: REP

    Operation:

    • This is an instruction prefix which can be used in string instructions.
    • It can be used with string instructions only.
    • It causes the instruction to be repeated CX number of times.
    • After each execution, the SI and DI registers are incremented/decremented based on the DF (Direction Flag) in the flag register and CX is decremented i.e. DF = 1; SI, DI decrements.
    • Thus, it is important that before we use the REP instruction prefix the following steps must be carried out.
    • CX must be initialized to the count value. If auto decrementing is required, DF must be set using STD instruction else cleared using CLD instruction. E.g. MOV CX, 0023H CLD REP MOVSB

    The above section of a program will cause the following string operation

    ES: [DI] ← DS: [SI]

    SI ← SI + I

    DI ← DI + I

    CX ← CX – 1

    to be executed 23H times (as CX = 23H) in auto incrementing mode (as DF is cleared).

  • SCASB:-

    Mnemonic: SCASB (for byte operation)

    Algorithm: For SCASB

    AL – ES: [DI]

    Set flags according to result

    If DF = 0 then DI = DI + 1

    Operation:

    • It is used to compare the contents of AL with a byte in the extra segment.
    • The offset of the byte in extra segment is in DI.
    • DI is incremented/decremented depending upon the direction flag (DF).
    • Comparison is done by subtracting a byte from extra segment from AL. The flag bits are affected but the result is not stored anywhere.
  • XLATB:-

    Mnemonic: XLATB (B indicates byte operation)

    Algorithm: AL = DS: [BX + unsigned AL]

    Operation:

    AL ← DS: [BX + AL]

    • This instruction replaces a byte in AL register with a byte from a look up table in the memory i.e. it copies the value of memory byte at location DS: [BX + unsigned AL] to the AL register.
    • Here the contents of AL before execution act as index to the desired location in lookup table.
    • This instruction is used to translate a byte from one code to another code.
ADD COMMENTlink
modified 2 hours ago  • written 2 hours ago by gravatar for Ankit Pandey Ankit Pandey ♦♦ 0
Please log in to add an answer.