Docsity

Machine codes, Study notes of Microprocessor and Assembly Language Programming

Partial preview of the text

Download Machine codes and more Study notes Microprocessor and Assembly Language Programming in PDF only on Docsity!

8088 - 86 CPU

Machine Codes

Addressing Modes, machine coding and

decoding

Addressing Modes

  • Register Addressing MOV AX, BX MOV SI, DX MOV BH, AL
  • Immediate Addressing MOV AX, 2356H MOV SI, 0ABCDH MOV BH, 76

Addressing Modes (Cntd.) Base-plus-Index MOV [BX+DI], CL MOV DL, [BX+SI] MOV BL, [BP+SI] Register Relative MOV AX, [BX+2] MOV [BX+4], DH

8086 - 88 Machine Language Encoding

  • Instructions consist on 1, 2, 3, 4, 5 or up to 6 bytes maximum.
  • Each instruction consists of several fields depending upon nature of instruction and addressing mode.
  • Instructions can be encoded in machine codes.
  • Conversely, machine codes can be decoded in instruction.

Endianness

  • Little Endian Machines (8086-88)

Those who store Least Significant Byte in lower

address of memory and subsequent higher bytes

in higher addresses of memory

  • 90AB12CDH Address Value 1000 CD 1001 12 1002 AB 1003 90

A simple 2-byte instruction

Byte 0 (LS-Byte)

Byte 1 (MS-Byte)

Mode Field REG Field R/M Field Op-code Field (^) D W

Mode bits table

REG Field Bits

Example 1

  • Consider an instruction with machine code 02CBH.

Op-code 000000B is for ADD.

Converting in binary to mark fields:

02CBH = 00000010 11001011 B

Here: Op-code = 000000 (ADD Instruction)

D = 1 (REG as destination)

W = 0 (8-bit operation)

MOD = 11 (Reg-Reg operation)

REG = 001 (CL register)

R/M = 011 (BL register)

Instruction is: ADD CL, BL

Example 2

  • Consider an instruction with machine code 88CBH.

100010B is the op-code for MOV.

Converting in binary to mark fields:

88CBH = 10001000 11001011 B

Here: Op-code = 100010 (MOV Instruction)

D = 0 (R/M as destination)

W = 0 (8-bit operation)

MOD = 11 (Reg-Reg operation)

REG = 001 (CL register)

R/M = 011 (BL register)

Instruction is: MOV BL, CL

Instructions with MOD = 10

Recall

MOD = 10 is 16-bit (2 bytes) displacement

Instruction format for offset address will be

[BX+SI/DI+16-bit Constant]

Instruction will be 6-bytes long now

Byte No. 7 6 5 4 3 2 1 0 MS-Byte OP-CODE D W MOD REG R/M LOWER BYTE OF DISPLACEMENT ADDRESS HIGHER BYTE OF DISPLACEMENT ADDRESS LOWER DATA BYTE LS-Byte HIGHER DATA BYTE

Example 5

  • Consider instruction C58796BF78CDH
  • Point to remember: REG Field is ignored when MOD = 10 in 6-byte instruction.
  • C58796BF78CDH =
    • 1100010110000111110010110101111110111100011001101
    • Here: Op-code = 110001 (MOV Immediate)
    • D = 0 (Destination is R/M), W = 1 (16-bit Transfer),
    • MOD = 10 ( 16 - bit displacement)
    • R/M (111) = BX+16-bit Displacement
    • So the displacement bytes are 02ABH and data bytes are CD78H
    • So the instruction will be MOV [BX+0BF96H], 0CD78H

QUIZ Write an IBM-PC Assembly language Program that reads a two characters from keyboard and prints them to the monitor in reverse order. Example:

  • A 7 are input characters and 7 A is the output on monitor.