Converting assembly language to machine language (1)
Converting assembly language to machine language (1)
The general instruction for converting assembly language into machine code is given below:
Operation Opcode
MOV 100010
ADD 000000
SUB 010010
XOR 001100
IN 111001
=1 if destination is considered
=0 if source is considered
W: Word or byte
MOD Indication
00 Memory mode, no displacement
01 Memory mode, with 8 bit displacement.
For example: [BX]+12H
10 Memory mode, with 16 bit displacement.
For example: [BX]+1234H
11 Register mode, no displacement
REG: Identifies a register which is one of the instruction operands.
• If MOD = 11, then R/M field acts as a REG field (used for register to-register operations and other
cases).
• If MOD ≠ 11, then R/M indicates how the effective address of the operand is calculated.
Example-1: Convert the following assembly language into machine language.
MOV BL,AL
Solution:
D=1
W=0
REG: 011
MOD: 11
R/M: 000
Byte 1 Byte 2
1 0 0 0 1 0 1 0 1 1 0 1 1 0 0 0
Opcode D W Mod REG R/M
Solution:
D=0
W=0
REG: 000
MOD: 11
R/M: 011
Byte 1 Byte 2
1 0 0 0 1 0 0 0 1 1 0 0 0 0 1 1
Opcode D W Mod REG R/M
Solution:
D=1
W=1
REG: 000
MOD: 00
R/M: 100
Byte 1 Byte 2
0 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0
Opcode D W Mod REG R/M
Solution:
D=1
W=1
REG: 000
MOD: 01
R/M: 100
Destination register is CL
D=1
W=0
REG: 001
MOD: 00
R/M: 110