SlideShare a Scribd company logo
Data Movement
Instructions
Ref: The Intel Microprocessors |
Architecture, Programming, and Interfacing | Eighth
Edition | Barry B. Brey
OBJECTIVE
● Machine language introduction
● Instructions modes
● Assembly instructions breakdown
● Assembly instruction to machine code conversion
MOV Revisited
● used earlier to explain addressing modes
● will be now used to demonstrate machine language
instructions
Machine Language
● native (binary) code that microprocessor understands
● instructions for the 8086 through the Core2 may vary in
length from 1 to as many as 13 bytes
● no complete list of these variations
● as many as 100,000 variations of instructions
INSTRUCTION MODES
● 16-bit mode(DOS mode):
○ 8086 through the 80286 uses this form
○ compatible in upper versions(80386 and upper) as well if they are
programmed to do so
● 32-bit mode:
○ but needs to be prefixed as below:
INSTRUCTION MODES(cntnd)
● 80386 and above assume that all instructions are 16-bit
mode when operated in real mode
● in protected mode D-bit selects in between (16 or 32)
D = 0, instructions are 16-bit instructions
16-bit offset addresses and register
D = 1, 32 bit instructions, 32 bit offset, registers
INSTRUCTION MODES(cntnd)
● first two bytes are called Override Prefixes
● Address size(67H): modifies the size of the operand
address
● Register/Operand size(66H): modifies register size
INSTRUCTION MODES(cntnd)
● By default:
○ l6-bit instruction mode uses 8- and l6-bit registers and addressing
modes
○ 32-bit instruction mode uses 8- and 32-bit registers and addressing
modes
● prefixes basically overrides these defaults so that a
32-bit register can be used in the l6-bit mode and vice
versa
● selecting mode-of-operation depends on application
○ 32-bit mode: if 8 or 32 bit data dominates the app
○ 16-bit mode: if 8 or 16 bit data dominates the app
● mode selection is done by OS
INSTRUCTION MODES(cntnd)
● Example (32-bit mode):
○ mov <mem>, <reg>
○ possible combinations:
■ default:
● moves 32 bits from a 32 bit register to memory using 32 bit
address
■ if preceded by operand-size prefix
● moves 16 bits from a 16 bit register to memory using 32 bit
address
■ if preceded by address-size prefix
● moves 32 bits from a 32 bit register to memory using 16 bit
address
■ if preceded by both operand-size and address-size prefix
● moves 16 bits from a 16 bit register to memory using 16 bit
address
INSTRUCTION MODES(cntnd)
● Example (16-bit mode):
○ mov <mem>, <reg>
○ possible combinations:
■ default:
● moves 16 bits from a 16 bit register to memory using 16 bit
address
■ if preceded by operand-size prefix
● moves 32 bits from a 32 bit register to memory using 16 bit
address
■ if preceded by address-size prefix
● moves 16 bits from a 16 bit register to memory using 32 bit
address
■ if preceded by both operand-size and address-size prefix
● moves 32 bits from a 32 bit register to memory using 32 bit
address
OPCODE
● selects the operation to be executed(add, sub, etc)
● 1 or 2 bytes long
● first 6 bits of the first byte is binary opcode
● D represents direction (appears mainly in mov and
mov-alike operations)
● W represents Word (appears in all instructions)
OPCODE(cntnd)
● List of some opcodes*
Instruction opcode
ADD 000000dw
AND 001000dw
DAA 00100111
DAS 00101111
DIV 1111011w
JMP(short) 11101011
JMP(near) 11101001
JMP(far) 11101010
MOV 100010dw
*
see Appendix-B for full list
OPCODE(contnd)
● If D == 0, data flows to the R/M field from the REG field
● If D == 1, data flows to the REG field from the R/M field
REG R/M
R/M REG
OPCODE(contnd)
● If W == 0, data size is always a byte
● If W == 1, data size is WORD/DOUBLE-WORD
○ recall that how register-size prefix determines it
MOD
● specifies the addressing mode
● MOD → mode, REG → register, R/M → register/memory
● MOD selects the type of addressing and whether a
displacement is present with that type
MOD(CNTND)
16-bit
instruction
mode
32-bit
instruction
mode
MOD(16-bit instructions)
● 11 → register-addressing mode, R/M is literally a
register then
● {00, 01, 10} → memory-addressing mode,
○ 00 → MOV AL, [DI]
○ 01 → MOV AL, [DI + 2]
○ 10 → MOV AL, [DI + 1000H]
MOD(16-bit instructions)
● 8-bit displacements are sign-extended into 16-bit
displacements
● i.e.:
○ 00H–7FH (positive) → 0000H–007FH
○ 80H–FFH (negative) → FF80-FFFFH
MOD(32-bit instructions)
● gets selected by address-size override prefix or
operating mode of OS
● 8-bit displacements are sign-extended into 32-bit
displacements
● i.e.:
○ 00–7FH (positive) → 00000000–0000007FH
○ 80–FFH (negative) → FFFFFF80-FFFFFFFFH
Register Assignments
● recall that double-word are only available to the
80386-Core2
● this table is accountable for REG (in any case) and for
R/M (only when it stands for register i.e: MOD = 11)
R/M Memory Assignments
● this table is accountable for REG (in any case) and for
R/M (only when it stands for memory i.e: MOD = 00 | 01 |
10),
* see exercise-4 for special addressing
16-bit addressing mode 32-bit addressing mode
Example_1:2-Byte Instruction
● 8BECH:
○ let’s take it as a 16-bit instruction mode
○ not prefixed by 66H or 67H
○ so, first byte 8B is opcode
● Opcode := 100010 ⇒ MOV
● D := 1 ⇒ R/M → REG
● W := 1 ⇒ WORD
OPCODE D W
1 0 0 0 1 0 1 1
Example_1:2-Byte Instruction(cntnd)
● 8BECH:
○ second byte, EC
● MOD := 11 ⇒ R/M is register
○ i.e.: register to register addressing
● REG := 101 ⇒ BP(destination)
● R/M := 100 ⇒ SP(source)
MOD REG R/M
1 1 1 0 1 1 0 0
Example_1:2-Byte Instruction(cntnd)
● Let’s put it all together:
○ the instruction(8BECH):= MOVes a word from SP to BP
○ i.e.: MOV BP, SP
● self:
○ figure out the instruction if it was operated in 32-bit instruction
mode and match your answer with the given one after going through
each step:
○ Answer: MOV EBP, ESP
Example_2:3-Byte Instruction
● 668BE8H:
○ let’s take it as a 16-bit instruction mode
○ prefixed by 66H(register-size override prefix)
■ so, 32 bit register operand
○ so, second byte 8B is opcode
● Opcode := 100010 ⇒ MOV
● D := 1 ⇒ R/M → REG
● W := 1 ⇒ DOUBLE-WORD
OPCODE D W
1 0 0 0 1 0 1 1
Example_2:3-Byte Instruction(cntnd)
● 668BE8H:
○ third byte, E8
● MOD := 11 ⇒ R/M is register
○ i.e.: register to register addressing
● REG := 101 ⇒ EBP(destination)
● R/M := 000 ⇒ EAX(source)
MOD REG R/M
1 1 1 0 1 0 0 0
Example_2:3-Byte Instruction(cntnd)
● Let’s put it all together:
○ the instruction(668BE8H):= MOVes a double-word from EAX to EBP
○ i.e.: MOV EBP, EAX
● self:
○ figure out the instruction if it was operated in 32-bit instruction
mode and match your answer with the given one after going through
each step:
○ Answer: MOV BP, AX
Example_3:2-Byte Instruction
● 8A15H:
○ let’s take it as a 16-bit instruction mode
○ not prefixed by 66H or 67H
○ so, first byte 8A is opcode
● Opcode := 100010 ⇒ MOV
● D := 1 ⇒ R/M → REG
● W := 0 ⇒ BYTE
OPCODE D W
1 0 0 0 1 0 1 0
Example_3:2-Byte Instruction(cntnd)
● 8A15H:
○ second byte, 15
● MOD := 00 ⇒ R/M is memory with no displacement
○ i.e.: memory to register addressing
● REG := 010 ⇒ DL(destination)
● R/M := 101 ⇒ DS:[DI](source)
MOD REG R/M
0 0 0 1 0 1 0 1
Example_3:2-Byte Instruction(cntnd)
● Let’s put it all together:
○ the instruction(8A15H):= MOVes a byte from memory addressed by
DS:[DI] to DL
○ i.e.: MOV DL, DS:[DI]
Example_4:Special Addressing
● if an instruction has only a displacement
○ MOD field contains 00 and R/M contains 110(DS:[BP])
Example_4:Special Addressing(cntnd)
● 88160010H:
○ let’s take it as a 16-bit instruction mode
○ not prefixed by 66H or 67H
○ so, first byte 88 is opcode
● Opcode := 100010 ⇒ MOV
● D := 0 ⇒ R/M ← REG
● W := 0 ⇒ BYTE
OPCODE D W
1 0 0 0 1 0 0 0
Example_4:Special Addressing(cntnd)
● 88160010H:
○ second byte, 16
● MOD := 00 ⇒ R/M is memory
○ invalid: with no displacement
○ Valid: with displacement to data
segment
MOD REG R/M
0 0 0 1 0 1 1 0
Example_4:Special Addressing(cntnd)
● 88160010H:
○ second byte, 16
● REG := 010 ⇒ DL(destination)
● R/M := 110 ⇒ DS:[BP](source)
MOD REG R/M
0 0 0 1 0 1 1 0
Example_4:Special Addressing(cntnd)
● 88160010H:
○ third and fourth byte, 0010(little endian)
● Displacement := 1000H
0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0
Example_4:Special Addressing(cntnd)
● Let’s put it all together:
○ the instruction(88160010H):= MOVes a byte from register DL into data
segment memory location 1000H
○ i.e.: MOV [1000H], DL
Example_5:Special Addressing
● if an instruction has BP addressing mode(i.e: contains
R/M code 110)
○ there will always be a displacement
○ adds 0 if no displacement is specified
○ example: MOV [BP], DL turns into MOV [BP + 0], DL
Example_5:Special Addressing(cntnd)
● 885600H:
○ let’s take it as a 16-bit instruction mode
○ not prefixed by 66H or 67H
○ so, first byte 88 is opcode
● Opcode := 100010 ⇒ MOV
● D := 0 ⇒ R/M ← REG
● W := 0 ⇒ BYTE
OPCODE D W
1 0 0 0 1 0 0 0
Example_5:Special Addressing(cntnd)
● 885600H:
○ second byte, 56
● MOD := 01 ⇒ R/M is memory
○ 8 bit displacement
● REG := 010 ⇒ DL(destination)
● R/M := 110 ⇒ DS:[BP](source)
MOD REG R/M
0 1 0 1 0 1 1 0
Example_5:Special Addressing(cntnd)
● 885600H:
○ third byte, 00(little endian)
● Displacement := 00H
0 0 0 0 0 0 0 0
Example_5:Special Addressing(cntnd)
● Let’s put it all together:
○ the instruction(885600H):= MOVes a byte from register DL into data
segment memory location pointed by BP plus displacement 00H
○ i.e.: MOV [BP], DL
○ i.e: MOV [BP + 0], DL
Exercise
● Convert the following machine codes into assembly
instruction(consider both 16 and 32-bit instruction
mode):
○ 8B07H
○ 8B9E004CH
○ 8A5501H
○ 8A750010H
○ 88160010H
○ 885600H
Exercise
● Write down the corresponding machine code for the
instructions given below(both in 16 and 32-bit
instruction mode):
○ mov ah, dh
○ MOV SI,[BX+2]
○ MOV ESI,[EAX]
○ MOV DL, [DI+1000H]
○ MOV DL, [DI+1H]
○ MOV [1000H],DL
○ MOV [BP],DL

More Related Content

What's hot

Data communication and networks by B. Forouzan
Data communication and networks by B. ForouzanData communication and networks by B. Forouzan
Data communication and networks by B. Forouzan
Preethi T G
 
Register transfer and micro-operation
Register transfer and micro-operationRegister transfer and micro-operation
Register transfer and micro-operation
Nikhil Pandit
 
8259 Operating Modes.pptx
8259 Operating Modes.pptx8259 Operating Modes.pptx
8259 Operating Modes.pptx
MeenaAnusha1
 
Modified booth's algorithm Part 2
Modified booth's algorithm Part 2Modified booth's algorithm Part 2
Modified booth's algorithm Part 2
babuece
 
Arm cortex-m4 programmer model
Arm cortex-m4 programmer modelArm cortex-m4 programmer model
Arm cortex-m4 programmer model
Mohammed Gomaa
 
Microprocessors & Microcomputers Lecture Notes
Microprocessors & Microcomputers Lecture NotesMicroprocessors & Microcomputers Lecture Notes
Microprocessors & Microcomputers Lecture Notes
FellowBuddy.com
 
Digital electronics
Digital electronicsDigital electronics
LPC 2148 ARM MICROCONTROLLER
LPC 2148 ARM MICROCONTROLLERLPC 2148 ARM MICROCONTROLLER
LPC 2148 ARM MICROCONTROLLER
sravannunna24
 
Communication Protocols (UART, SPI,I2C)
Communication Protocols (UART, SPI,I2C)Communication Protocols (UART, SPI,I2C)
Communication Protocols (UART, SPI,I2C)
Emertxe Information Technologies Pvt Ltd
 
8051 MICROCONTROLLER ARCHITECTURE.pptx
 8051 MICROCONTROLLER ARCHITECTURE.pptx 8051 MICROCONTROLLER ARCHITECTURE.pptx
8051 MICROCONTROLLER ARCHITECTURE.pptx
MemonaMemon1
 
Logic gates
Logic gatesLogic gates
Logic gates
prasanna chitra
 
microprocessor
 microprocessor microprocessor
microprocessor
ATTO RATHORE
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-pptjemimajerome
 
IP addressing and subnetting.pptx
IP addressing and subnetting.pptxIP addressing and subnetting.pptx
IP addressing and subnetting.pptx
naseerahmad707715
 
Programmable Timer 8253/8254
Programmable Timer 8253/8254Programmable Timer 8253/8254
Programmable Timer 8253/8254
Muhammed Afsal Villan
 

What's hot (20)

Data communication and networks by B. Forouzan
Data communication and networks by B. ForouzanData communication and networks by B. Forouzan
Data communication and networks by B. Forouzan
 
8086
8086 8086
8086
 
Register transfer and micro-operation
Register transfer and micro-operationRegister transfer and micro-operation
Register transfer and micro-operation
 
8259 Operating Modes.pptx
8259 Operating Modes.pptx8259 Operating Modes.pptx
8259 Operating Modes.pptx
 
Basics of digital electronics
Basics of digital electronicsBasics of digital electronics
Basics of digital electronics
 
Modified booth's algorithm Part 2
Modified booth's algorithm Part 2Modified booth's algorithm Part 2
Modified booth's algorithm Part 2
 
Arm cortex-m4 programmer model
Arm cortex-m4 programmer modelArm cortex-m4 programmer model
Arm cortex-m4 programmer model
 
Microprocessors & Microcomputers Lecture Notes
Microprocessors & Microcomputers Lecture NotesMicroprocessors & Microcomputers Lecture Notes
Microprocessors & Microcomputers Lecture Notes
 
Digital electronics
Digital electronicsDigital electronics
Digital electronics
 
LPC 2148 ARM MICROCONTROLLER
LPC 2148 ARM MICROCONTROLLERLPC 2148 ARM MICROCONTROLLER
LPC 2148 ARM MICROCONTROLLER
 
Communication Protocols (UART, SPI,I2C)
Communication Protocols (UART, SPI,I2C)Communication Protocols (UART, SPI,I2C)
Communication Protocols (UART, SPI,I2C)
 
TCP IP Addressing
TCP IP AddressingTCP IP Addressing
TCP IP Addressing
 
Conditional jump
Conditional jumpConditional jump
Conditional jump
 
8051 MICROCONTROLLER ARCHITECTURE.pptx
 8051 MICROCONTROLLER ARCHITECTURE.pptx 8051 MICROCONTROLLER ARCHITECTURE.pptx
8051 MICROCONTROLLER ARCHITECTURE.pptx
 
Logic gates
Logic gatesLogic gates
Logic gates
 
8085 lab
8085 lab8085 lab
8085 lab
 
microprocessor
 microprocessor microprocessor
microprocessor
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-ppt
 
IP addressing and subnetting.pptx
IP addressing and subnetting.pptxIP addressing and subnetting.pptx
IP addressing and subnetting.pptx
 
Programmable Timer 8253/8254
Programmable Timer 8253/8254Programmable Timer 8253/8254
Programmable Timer 8253/8254
 

Similar to Barry B. Brey: Chapter#4

Intel µp instruction encoding and decoding
Intel µp instruction encoding and decodingIntel µp instruction encoding and decoding
Intel µp instruction encoding and decoding
yocirem
 
Assembly code
Assembly codeAssembly code
Assembly code
SharmilaChidaravalli
 
Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051
logesh waran
 
microcomputer architecture-Instruction formats
microcomputer architecture-Instruction formatsmicrocomputer architecture-Instruction formats
microcomputer architecture-Instruction formats
lavanya marichamy
 
Lecture 02 Data Group of Instructions
Lecture 02 Data Group of InstructionsLecture 02 Data Group of Instructions
Lecture 02 Data Group of Instructions
Zeeshan Ahmed
 
Lecture 4 (8051 instruction set) rv01
Lecture 4 (8051 instruction set) rv01Lecture 4 (8051 instruction set) rv01
Lecture 4 (8051 instruction set) rv01
cairo university
 
8086 Micro-processor and MDA 8086 Trainer Kit
8086 Micro-processor and MDA 8086 Trainer Kit8086 Micro-processor and MDA 8086 Trainer Kit
8086 Micro-processor and MDA 8086 Trainer Kit
Amit Kumer Podder
 
Arm instruction set
Arm instruction setArm instruction set
Arm instruction set
Mathivanan Natarajan
 
[論文読み会資料] Asynchronous Bidirectional Decoding for Neural Machine Translation
[論文読み会資料] Asynchronous Bidirectional Decoding for Neural Machine Translation[論文読み会資料] Asynchronous Bidirectional Decoding for Neural Machine Translation
[論文読み会資料] Asynchronous Bidirectional Decoding for Neural Machine Translation
Hayahide Yamagishi
 
LECTURE2 td 2 sue les theories de graphes
LECTURE2 td 2 sue les theories de graphesLECTURE2 td 2 sue les theories de graphes
LECTURE2 td 2 sue les theories de graphes
AhmedMahjoub15
 
Https _doc-0o-c4-apps-viewer.googleusercontent
Https  _doc-0o-c4-apps-viewer.googleusercontent Https  _doc-0o-c4-apps-viewer.googleusercontent
Https _doc-0o-c4-apps-viewer.googleusercontent vijaydeepakg
 
Arm Cortex material Arm Cortex material3222886.ppt
Arm Cortex material Arm Cortex material3222886.pptArm Cortex material Arm Cortex material3222886.ppt
Arm Cortex material Arm Cortex material3222886.ppt
Manju Badiger
 
armcortexinsructionsetupdated (2).pptx
armcortexinsructionsetupdated (2).pptxarmcortexinsructionsetupdated (2).pptx
armcortexinsructionsetupdated (2).pptx
ssuserda88a7
 
ARM AAE - Intrustion Sets
ARM AAE - Intrustion SetsARM AAE - Intrustion Sets
ARM AAE - Intrustion Sets
Anh Dung NGUYEN
 
Microprocessor Part 3
Microprocessor    Part  3Microprocessor    Part  3
Microprocessor Part 3
Sajan Agrawal
 
Intel8086_Flags_Addr_Modes_sample_pgms.pdf
Intel8086_Flags_Addr_Modes_sample_pgms.pdfIntel8086_Flags_Addr_Modes_sample_pgms.pdf
Intel8086_Flags_Addr_Modes_sample_pgms.pdf
Anonymous611358
 
ARM Fundamentals
ARM FundamentalsARM Fundamentals
ARM Fundamentals
guest56d1b781
 
15CS44 MP & MC module 5
15CS44 MP & MC  module 515CS44 MP & MC  module 5
15CS44 MP & MC module 5
RLJIT
 

Similar to Barry B. Brey: Chapter#4 (20)

Intel µp instruction encoding and decoding
Intel µp instruction encoding and decodingIntel µp instruction encoding and decoding
Intel µp instruction encoding and decoding
 
Assembly code
Assembly codeAssembly code
Assembly code
 
Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051
 
Lecture9
Lecture9Lecture9
Lecture9
 
8253,8254
8253,8254 8253,8254
8253,8254
 
microcomputer architecture-Instruction formats
microcomputer architecture-Instruction formatsmicrocomputer architecture-Instruction formats
microcomputer architecture-Instruction formats
 
Lecture 02 Data Group of Instructions
Lecture 02 Data Group of InstructionsLecture 02 Data Group of Instructions
Lecture 02 Data Group of Instructions
 
Lecture 4 (8051 instruction set) rv01
Lecture 4 (8051 instruction set) rv01Lecture 4 (8051 instruction set) rv01
Lecture 4 (8051 instruction set) rv01
 
8086 Micro-processor and MDA 8086 Trainer Kit
8086 Micro-processor and MDA 8086 Trainer Kit8086 Micro-processor and MDA 8086 Trainer Kit
8086 Micro-processor and MDA 8086 Trainer Kit
 
Arm instruction set
Arm instruction setArm instruction set
Arm instruction set
 
[論文読み会資料] Asynchronous Bidirectional Decoding for Neural Machine Translation
[論文読み会資料] Asynchronous Bidirectional Decoding for Neural Machine Translation[論文読み会資料] Asynchronous Bidirectional Decoding for Neural Machine Translation
[論文読み会資料] Asynchronous Bidirectional Decoding for Neural Machine Translation
 
LECTURE2 td 2 sue les theories de graphes
LECTURE2 td 2 sue les theories de graphesLECTURE2 td 2 sue les theories de graphes
LECTURE2 td 2 sue les theories de graphes
 
Https _doc-0o-c4-apps-viewer.googleusercontent
Https  _doc-0o-c4-apps-viewer.googleusercontent Https  _doc-0o-c4-apps-viewer.googleusercontent
Https _doc-0o-c4-apps-viewer.googleusercontent
 
Arm Cortex material Arm Cortex material3222886.ppt
Arm Cortex material Arm Cortex material3222886.pptArm Cortex material Arm Cortex material3222886.ppt
Arm Cortex material Arm Cortex material3222886.ppt
 
armcortexinsructionsetupdated (2).pptx
armcortexinsructionsetupdated (2).pptxarmcortexinsructionsetupdated (2).pptx
armcortexinsructionsetupdated (2).pptx
 
ARM AAE - Intrustion Sets
ARM AAE - Intrustion SetsARM AAE - Intrustion Sets
ARM AAE - Intrustion Sets
 
Microprocessor Part 3
Microprocessor    Part  3Microprocessor    Part  3
Microprocessor Part 3
 
Intel8086_Flags_Addr_Modes_sample_pgms.pdf
Intel8086_Flags_Addr_Modes_sample_pgms.pdfIntel8086_Flags_Addr_Modes_sample_pgms.pdf
Intel8086_Flags_Addr_Modes_sample_pgms.pdf
 
ARM Fundamentals
ARM FundamentalsARM Fundamentals
ARM Fundamentals
 
15CS44 MP & MC module 5
15CS44 MP & MC  module 515CS44 MP & MC  module 5
15CS44 MP & MC module 5
 

Recently uploaded

Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 

Recently uploaded (20)

Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 

Barry B. Brey: Chapter#4

  • 1. Data Movement Instructions Ref: The Intel Microprocessors | Architecture, Programming, and Interfacing | Eighth Edition | Barry B. Brey
  • 2. OBJECTIVE ● Machine language introduction ● Instructions modes ● Assembly instructions breakdown ● Assembly instruction to machine code conversion
  • 3. MOV Revisited ● used earlier to explain addressing modes ● will be now used to demonstrate machine language instructions
  • 4. Machine Language ● native (binary) code that microprocessor understands ● instructions for the 8086 through the Core2 may vary in length from 1 to as many as 13 bytes ● no complete list of these variations ● as many as 100,000 variations of instructions
  • 5. INSTRUCTION MODES ● 16-bit mode(DOS mode): ○ 8086 through the 80286 uses this form ○ compatible in upper versions(80386 and upper) as well if they are programmed to do so ● 32-bit mode: ○ but needs to be prefixed as below:
  • 6. INSTRUCTION MODES(cntnd) ● 80386 and above assume that all instructions are 16-bit mode when operated in real mode ● in protected mode D-bit selects in between (16 or 32) D = 0, instructions are 16-bit instructions 16-bit offset addresses and register D = 1, 32 bit instructions, 32 bit offset, registers
  • 7. INSTRUCTION MODES(cntnd) ● first two bytes are called Override Prefixes ● Address size(67H): modifies the size of the operand address ● Register/Operand size(66H): modifies register size
  • 8. INSTRUCTION MODES(cntnd) ● By default: ○ l6-bit instruction mode uses 8- and l6-bit registers and addressing modes ○ 32-bit instruction mode uses 8- and 32-bit registers and addressing modes ● prefixes basically overrides these defaults so that a 32-bit register can be used in the l6-bit mode and vice versa ● selecting mode-of-operation depends on application ○ 32-bit mode: if 8 or 32 bit data dominates the app ○ 16-bit mode: if 8 or 16 bit data dominates the app ● mode selection is done by OS
  • 9. INSTRUCTION MODES(cntnd) ● Example (32-bit mode): ○ mov <mem>, <reg> ○ possible combinations: ■ default: ● moves 32 bits from a 32 bit register to memory using 32 bit address ■ if preceded by operand-size prefix ● moves 16 bits from a 16 bit register to memory using 32 bit address ■ if preceded by address-size prefix ● moves 32 bits from a 32 bit register to memory using 16 bit address ■ if preceded by both operand-size and address-size prefix ● moves 16 bits from a 16 bit register to memory using 16 bit address
  • 10. INSTRUCTION MODES(cntnd) ● Example (16-bit mode): ○ mov <mem>, <reg> ○ possible combinations: ■ default: ● moves 16 bits from a 16 bit register to memory using 16 bit address ■ if preceded by operand-size prefix ● moves 32 bits from a 32 bit register to memory using 16 bit address ■ if preceded by address-size prefix ● moves 16 bits from a 16 bit register to memory using 32 bit address ■ if preceded by both operand-size and address-size prefix ● moves 32 bits from a 32 bit register to memory using 32 bit address
  • 11. OPCODE ● selects the operation to be executed(add, sub, etc) ● 1 or 2 bytes long ● first 6 bits of the first byte is binary opcode ● D represents direction (appears mainly in mov and mov-alike operations) ● W represents Word (appears in all instructions)
  • 12. OPCODE(cntnd) ● List of some opcodes* Instruction opcode ADD 000000dw AND 001000dw DAA 00100111 DAS 00101111 DIV 1111011w JMP(short) 11101011 JMP(near) 11101001 JMP(far) 11101010 MOV 100010dw * see Appendix-B for full list
  • 13. OPCODE(contnd) ● If D == 0, data flows to the R/M field from the REG field ● If D == 1, data flows to the REG field from the R/M field REG R/M R/M REG
  • 14. OPCODE(contnd) ● If W == 0, data size is always a byte ● If W == 1, data size is WORD/DOUBLE-WORD ○ recall that how register-size prefix determines it
  • 15. MOD ● specifies the addressing mode ● MOD → mode, REG → register, R/M → register/memory ● MOD selects the type of addressing and whether a displacement is present with that type
  • 17. MOD(16-bit instructions) ● 11 → register-addressing mode, R/M is literally a register then ● {00, 01, 10} → memory-addressing mode, ○ 00 → MOV AL, [DI] ○ 01 → MOV AL, [DI + 2] ○ 10 → MOV AL, [DI + 1000H]
  • 18. MOD(16-bit instructions) ● 8-bit displacements are sign-extended into 16-bit displacements ● i.e.: ○ 00H–7FH (positive) → 0000H–007FH ○ 80H–FFH (negative) → FF80-FFFFH
  • 19. MOD(32-bit instructions) ● gets selected by address-size override prefix or operating mode of OS ● 8-bit displacements are sign-extended into 32-bit displacements ● i.e.: ○ 00–7FH (positive) → 00000000–0000007FH ○ 80–FFH (negative) → FFFFFF80-FFFFFFFFH
  • 20. Register Assignments ● recall that double-word are only available to the 80386-Core2 ● this table is accountable for REG (in any case) and for R/M (only when it stands for register i.e: MOD = 11)
  • 21. R/M Memory Assignments ● this table is accountable for REG (in any case) and for R/M (only when it stands for memory i.e: MOD = 00 | 01 | 10), * see exercise-4 for special addressing 16-bit addressing mode 32-bit addressing mode
  • 22. Example_1:2-Byte Instruction ● 8BECH: ○ let’s take it as a 16-bit instruction mode ○ not prefixed by 66H or 67H ○ so, first byte 8B is opcode ● Opcode := 100010 ⇒ MOV ● D := 1 ⇒ R/M → REG ● W := 1 ⇒ WORD OPCODE D W 1 0 0 0 1 0 1 1
  • 23. Example_1:2-Byte Instruction(cntnd) ● 8BECH: ○ second byte, EC ● MOD := 11 ⇒ R/M is register ○ i.e.: register to register addressing ● REG := 101 ⇒ BP(destination) ● R/M := 100 ⇒ SP(source) MOD REG R/M 1 1 1 0 1 1 0 0
  • 24. Example_1:2-Byte Instruction(cntnd) ● Let’s put it all together: ○ the instruction(8BECH):= MOVes a word from SP to BP ○ i.e.: MOV BP, SP ● self: ○ figure out the instruction if it was operated in 32-bit instruction mode and match your answer with the given one after going through each step: ○ Answer: MOV EBP, ESP
  • 25. Example_2:3-Byte Instruction ● 668BE8H: ○ let’s take it as a 16-bit instruction mode ○ prefixed by 66H(register-size override prefix) ■ so, 32 bit register operand ○ so, second byte 8B is opcode ● Opcode := 100010 ⇒ MOV ● D := 1 ⇒ R/M → REG ● W := 1 ⇒ DOUBLE-WORD OPCODE D W 1 0 0 0 1 0 1 1
  • 26. Example_2:3-Byte Instruction(cntnd) ● 668BE8H: ○ third byte, E8 ● MOD := 11 ⇒ R/M is register ○ i.e.: register to register addressing ● REG := 101 ⇒ EBP(destination) ● R/M := 000 ⇒ EAX(source) MOD REG R/M 1 1 1 0 1 0 0 0
  • 27. Example_2:3-Byte Instruction(cntnd) ● Let’s put it all together: ○ the instruction(668BE8H):= MOVes a double-word from EAX to EBP ○ i.e.: MOV EBP, EAX ● self: ○ figure out the instruction if it was operated in 32-bit instruction mode and match your answer with the given one after going through each step: ○ Answer: MOV BP, AX
  • 28. Example_3:2-Byte Instruction ● 8A15H: ○ let’s take it as a 16-bit instruction mode ○ not prefixed by 66H or 67H ○ so, first byte 8A is opcode ● Opcode := 100010 ⇒ MOV ● D := 1 ⇒ R/M → REG ● W := 0 ⇒ BYTE OPCODE D W 1 0 0 0 1 0 1 0
  • 29. Example_3:2-Byte Instruction(cntnd) ● 8A15H: ○ second byte, 15 ● MOD := 00 ⇒ R/M is memory with no displacement ○ i.e.: memory to register addressing ● REG := 010 ⇒ DL(destination) ● R/M := 101 ⇒ DS:[DI](source) MOD REG R/M 0 0 0 1 0 1 0 1
  • 30. Example_3:2-Byte Instruction(cntnd) ● Let’s put it all together: ○ the instruction(8A15H):= MOVes a byte from memory addressed by DS:[DI] to DL ○ i.e.: MOV DL, DS:[DI]
  • 31. Example_4:Special Addressing ● if an instruction has only a displacement ○ MOD field contains 00 and R/M contains 110(DS:[BP])
  • 32. Example_4:Special Addressing(cntnd) ● 88160010H: ○ let’s take it as a 16-bit instruction mode ○ not prefixed by 66H or 67H ○ so, first byte 88 is opcode ● Opcode := 100010 ⇒ MOV ● D := 0 ⇒ R/M ← REG ● W := 0 ⇒ BYTE OPCODE D W 1 0 0 0 1 0 0 0
  • 33. Example_4:Special Addressing(cntnd) ● 88160010H: ○ second byte, 16 ● MOD := 00 ⇒ R/M is memory ○ invalid: with no displacement ○ Valid: with displacement to data segment MOD REG R/M 0 0 0 1 0 1 1 0
  • 34. Example_4:Special Addressing(cntnd) ● 88160010H: ○ second byte, 16 ● REG := 010 ⇒ DL(destination) ● R/M := 110 ⇒ DS:[BP](source) MOD REG R/M 0 0 0 1 0 1 1 0
  • 35. Example_4:Special Addressing(cntnd) ● 88160010H: ○ third and fourth byte, 0010(little endian) ● Displacement := 1000H 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
  • 36. Example_4:Special Addressing(cntnd) ● Let’s put it all together: ○ the instruction(88160010H):= MOVes a byte from register DL into data segment memory location 1000H ○ i.e.: MOV [1000H], DL
  • 37. Example_5:Special Addressing ● if an instruction has BP addressing mode(i.e: contains R/M code 110) ○ there will always be a displacement ○ adds 0 if no displacement is specified ○ example: MOV [BP], DL turns into MOV [BP + 0], DL
  • 38. Example_5:Special Addressing(cntnd) ● 885600H: ○ let’s take it as a 16-bit instruction mode ○ not prefixed by 66H or 67H ○ so, first byte 88 is opcode ● Opcode := 100010 ⇒ MOV ● D := 0 ⇒ R/M ← REG ● W := 0 ⇒ BYTE OPCODE D W 1 0 0 0 1 0 0 0
  • 39. Example_5:Special Addressing(cntnd) ● 885600H: ○ second byte, 56 ● MOD := 01 ⇒ R/M is memory ○ 8 bit displacement ● REG := 010 ⇒ DL(destination) ● R/M := 110 ⇒ DS:[BP](source) MOD REG R/M 0 1 0 1 0 1 1 0
  • 40. Example_5:Special Addressing(cntnd) ● 885600H: ○ third byte, 00(little endian) ● Displacement := 00H 0 0 0 0 0 0 0 0
  • 41. Example_5:Special Addressing(cntnd) ● Let’s put it all together: ○ the instruction(885600H):= MOVes a byte from register DL into data segment memory location pointed by BP plus displacement 00H ○ i.e.: MOV [BP], DL ○ i.e: MOV [BP + 0], DL
  • 42. Exercise ● Convert the following machine codes into assembly instruction(consider both 16 and 32-bit instruction mode): ○ 8B07H ○ 8B9E004CH ○ 8A5501H ○ 8A750010H ○ 88160010H ○ 885600H
  • 43. Exercise ● Write down the corresponding machine code for the instructions given below(both in 16 and 32-bit instruction mode): ○ mov ah, dh ○ MOV SI,[BX+2] ○ MOV ESI,[EAX] ○ MOV DL, [DI+1000H] ○ MOV DL, [DI+1H] ○ MOV [1000H],DL ○ MOV [BP],DL