0% found this document useful (0 votes)
5 views17 pages

Machine Code Conversion Guide

The document outlines the instruction format and machine code conversion for various assembly language operations. It provides examples of converting specific MOV instructions into machine code, detailing the operation code, mod fields, register assignments, and addressing modes. Each example illustrates the binary representation and hexadecimal equivalent of the instructions.

Uploaded by

mousabhamza2022
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views17 pages

Machine Code Conversion Guide

The document outlines the instruction format and machine code conversion for various assembly language operations. It provides examples of converting specific MOV instructions into machine code, detailing the operation code, mod fields, register assignments, and addressing modes. Each example illustrates the binary representation and hexadecimal equivalent of the instructions.

Uploaded by

mousabhamza2022
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd

Instruction Format

1
Instruction Format

2
Instruction Format

3
Operation Code

4
Mod Field

5
Mod Field

6
Register Assignments

7
R/M Memory Addressing

8
32-Bit Addressing Modes

9
32-Bit Addressing Modes

10
32-bit Addressing

11
32-Bits Addressing

12
Converting to Machine Code
• Ex-1
• MOV AL,[BX]
• From Appendix B ,Looking for the code for MOV reg, mem (P-830)
• 100010dw oorrrmmmdisp
• In this example d=1 (data flow to reg field from R/M field )
• w=0 byte
• oo = 00 ( no displacement ) -Table B-1 P-783
• rrr = 000 al register -Table B-3 P-784
• mmm = 111 (DS:[BX]) –Table B-2
• So the machine code
• 100010 1 0 00 000 111 ---- 8A07h

13
Converting to Machine Code
• EX-2
• MOV 5[SI], bx
• Looking for code MOV mem , reg which is the same as in previous EX
• 100010dw oorrrmmmdisp
• d=0 (data flow from reg field to R/M field )
• w = 1 ( word )
• oo = 01 ( an 8-bits signed displacement follows the op-code )
• reg = 011 (BX register )
• mmm = 100 (DS: [SI])
• So the machine code is
• 10001001 01011100 0000 0101  89 5C 05

14
Converting to Machine Code
• EX- 3
• MOV EAX ,EBX
• Looking for the code MOV reg , reg which is
• 100010dw oorrrmmmdisp but no need for disp
• d = 1 data flow to reg field from R/M field which specify register also
• ( when the two operands are registers reg field specify the
destination )
• w = 1 ( 32 – Bits )
• oo = 11 ( no displacement )
• rrr = 000 ( EAX )
• mmm = 011 (EBX )
• Prefix 66h is used to indicate 32-Bits
• So the code will be
• 0110 0110 10001011 1100 0011  66 8B C3h

15
Converting to Machine Code
• EX- 4
• MOV AX , 10[4*ESI]
• Looking for MOV reg , mem code which is
• 100010dw oorrrmmmdisp
• d = 1 ( data to reg field )
• w = 1 (word )
• rrr = 000 ( AX Register )
• R/M = 100 ( using Scale Index Byte (SIB))  Table 4-5
• In SIB Byte
ss = 10 ( * 4 )  Figure 4-8
index = 110 ( DS: [ESI] )
no Base Register is used ( Base is 101)
o Since 16-Bits mode is used Size prefix have to be used ( 67h )
o So the code is
0110 0111 1000 1011 0000 0100 1011 0101 0000 0000 0000 0000 0000 0000 0000 000A
( 67 8B 04 B5 00 00 00 0A )

16
Converting to Machine Code
• EX-5

• MOV EAX , 10[4*ESI]


• Since the same instruction as in EX-4 but EAX instead of AX ,32 – Bits
prefix
is used also 66h and the code is
67 66 8B 04 B5 00 00 00 0A

17

You might also like