Topic 9 - 10 - Data Transfer Instructions
Topic 9 - 10 - Data Transfer Instructions
NOTES:
Classification of Instructions
Classification of Instructions:
1. Data Transfer Instructions
2. String Instructions
3. Arithmetic Instructions
4. Logic Instructions
5. Shift Instructions
6. Rotate Instructions
7. Flag Control Instructions
8. Jump Instructions
MOV Instruction
Format: MOV D, S
Action: D [S]
Pointers:
1. The MOV instruction does not allow both source and destination
operands to be memory locations (no memory to memory transfers).
The instruction MOV [BX], FILE is invalid.
CODE: CSP107
Page 1 of 12
COMPUTER 2. Both source and destination operands should be of the same data
size. Therefore, the instruction MOV AH, BX is invalid.
ORGANIZATION
The destination operand AH can only hold 8-bit of data compared to
the source which is a 16-bit.
NOTES:
3. Immediate data cannot be moved to a segment register. MOV DS,
1800H is therefore invalid. Instead, use:
Unless otherwise stated, determine the contents of all the affected general
purpose registers and memory addresses after executing the following
program. Each instruction is dependent of one another. Whenever
necessary, use the memory map (handout) for additional data. Assume the
following register contents:
MOV AX, BX
MOV DI, 0005H
MOV [BP + SI], AX
Answer:
MOV AX, BX
AX = 0019H
DI = 0005H
CODE: CSP107
Page 2 of 12
COMPUTER 20020H [AL] – 19H
ORGANIZATION 20021H [AH] – 00H
The XCHG (Exchange) instruction swaps the contents of the source and
destination operands.
Format: XCHG D, S
Pointers:
1. The XCHG instruction does not allow both source and destination
operands to be memory locations (no memory to memory
transfers). The instruction XCHG [BX], FILE is therefore invalid.
2. Both source and destination operands should be of the same data
size.
Therefore, the instruction XCHG AH, BX is invalid.
3. Immediate addressing cannot be used with this instruction. The
instruction XCHG AX, 1800H is invalid.
4. A data exchange can also be done using several MOV instructions:
MOV CX, AX
MOV DX, BX
MOV AX, DX
MOV BX, CX
MOV CX, ES
XCHG BX, CX
MOV ES, CX
CODE: CSP107
Page 3 of 12
COMPUTER Example: XCHG Instruction
ORGANIZATION
Unless otherwise stated, determine the contents of all the affected general
purpose registers and memory addresses after executing the following
program. Each instruction is dependent of one another. Whenever
NOTES: necessary, use the memory map (handout) for additional data. Assume the
following register contents:
XCHG DI, SI
XCHG BX, [CX]
XCHG [BX + 0020H], AX
Answer:
XCHG DI, SI
DI = 001EH
SI = 0017H
CODE: CSP107
Page 4 of 12
COMPUTER Exercise 1
ORGANIZATION
Unless otherwise stated, determine the contents of all the affected general
purpose registers and memory addresses after executing the following
program. Each instruction is dependent of one another. Whenever
NOTES: necessary, use the memory map (handout) for additional data. Assume the
following register contents:
Exercise 2
Unless otherwise stated, determine the contents of all the affected general
purpose registers and memory addresses after executing the following
program. Each instruction is dependent of one another. Whenever
necessary, use the memory map (handout) for additional data. Assume the
following register contents:
XCHG AX, BX
MOV [CX], AX
XCHG BX, [CX + SI + 000FH]
Format: PUSH S
Action: SP SP - 2
[SP+ 1] [SH]
[SP] [SL]
Source Example
register PUSH AX
seg reg PUSH DS
MM PUSH BETA
CODE: CSP107
Page 5 of 12
Pointers:
COMPUTER
ORGANIZATION 1. The PUSH instruction pushes word-sized data only.
NOTES:
Example: PUSH Instruction
Unless otherwise stated, determine the contents of all the affected general
purpose registers and memory addresses after executing the following
program. Each instruction is dependent of one another. Whenever
necessary, use the memory map (handout) for additional data. Assume the
following register contents:
PUSH AX
PUSH [BX]
Answer:
PUSH AX
To compute for the top of the stack (physical address), add the physical
segment base address and the offset address which is the value of the
stack pointer.
After executing the command PUSH AX, the value of the high-order 8
bits of AX is stored at the address 20034H (Top of the Stack – 1) and the
low-order 8 bit of AX is stored at the address 20033H (Top of the Stack -
2). SP is then decremented by 2 so that the next word of data is stored
in the next available memory location.
New SP = SP - 2
= 0035H – 2H
= 0033H
PUSH [BX]
To compute for the top of the stack (physical address), add the physical
segment base address and the offset address which is the value of the
stack pointer.
Then compute for the physical address of the memory location specified by
the content of BX. Since BX is used, the data segment will be
addressed.
CODE: CSP107
Page 6 of 12
COMPUTER
Physical Address = DS x 10H + BX
ORGANIZATION
Physical Address = 20000H + 0019H
Physical Address = 20019H
NOTES: After executing the command PUSH [BX], the value of the address
20019H is stored at the address 20031H, low-order 8 bits (Top of the
Stack – 2) and the value of the address 2001AH, high-order 8 bits is
stored at the address 20032H (Top of the Stack -1). SP is then
decremented by 2 so that the next word of data is stored in the next
available memory location.
New SP = SP - 2
= 0033H – 2H
= 0031H
Exercise 3
Unless otherwise stated, determine the contents of all the affected general
purpose registers and memory addresses after executing the following
program. Each instruction is dependent of one another. Whenever
necessary, use the memory map (handout) for additional data. Assume the
following register contents:
PUSH DX
PUSH [BX + DI]
CODE: CSP107
Page 7 of 12
COMPUTER The POP Instruction
ORGANIZATION
POP transfers a word data pointed to by SP to the destination operand.
Afterwards, the value of SP is incremented by 2.
NOTES: Format: POP D
Action: DL [SP]
DH [SP + 1]
SP SP + 2
Destination Example
register POP AX
seg reg POP DS
MM POP BETA
Pointers:
Unless otherwise stated, determine the contents of all the affected general
purpose registers and memory addresses after executing the following
program. Each instruction is dependent of one another. Whenever
necessary, use the memory map (handout) for additional data. Assume the
following register contents:
POP AX
POP [BX]
Answer:
POP AX
To compute for the top of the stack (physical address), add the physical
segment base address and the offset address which is the value of the
stack pointer.
After executing the command POP AX, the content of the location
addressed by SP (current top of the stack), 20035H is removed and
store it to AL and the high-order 8 bits are removed from the location
addressed by SP + 1 (current top of the stack + 1), 20036H and store it
at AH. SP is then incremented by 2.
CODE: CSP107
Page 8 of 12
COMPUTER
ORGANIZATION New SP = SP + 2
= 0035H + 2
= 0037H
NOTES: POP [BX]
To compute for the top of the stack (physical address), add the physical
segment base address and the offset address which is the value of the
stack pointer.
Then compute for the physical address of the memory location specified
by the content of BX. Since BX is used, the data segment will be
addressed.
After executing the command POP [BX], the content of the location
addressed by SP (current top of the stack), 20037H is removed and
store it to address 200019H and the high-order 8 bits are removed from
the location addressed by SP + 1 (current top of the stack + 1), 20038H
and store it at address 2001AH. SP is then incremented by 2.
New SP = SP + 2
= 0037H + 2
= 0039H
Exercise 4
Unless otherwise stated, determine the contents of all the affected general
purpose registers and memory addresses after executing the following
program. Each instruction is dependent of one another. Whenever
necessary, use the memory map (handout) for additional data. Assume the
following register contents:
POP CX
POP [BX + DI + 000AH]
CODE: CSP107
Page 9 of 12
COMPUTER Exercise 5
ORGANIZATION
Unless otherwise stated, determine the contents of all the affected general
purpose registers and memory addresses after executing the following
program. Each instruction is dependent of one another. Whenever
NOTES: necessary, use the memory map (handout) for additional data. Assume the
following register contents:
POP CX
POP [BP+ SI + 0010H]
PUSH SI
PUSH [DI]
Format: LEA D, S
Action: D EA of S
Pointers:
Examples:
DS = 5000H
LIST = 1800H
CODE: CSP107
Page 10 of 12
COMPUTER
ORGANIZATION
51801H 33H
51800H 22H
517FFH 11H
However, if the LEA DI, LIST instruction is executed, this will transfer the
effective address of the source operand to register DI. Therefore, DI will
now contain 1800H.
Unless otherwise stated, determine the contents of all the affected general
purpose registers and memory addresses after executing the following
program. Each instruction is dependent of one another. Whenever
necessary, use the memory map (handout) for additional data. Assume the
following register contents and labels:
Answer:
CODE: CSP107
Page 11 of 12
COMPUTER LEA BX, ALPHA
ORGANIZATION
This will transfer the effective address of the source operand, ALPHA, to
register BX.
NOTES: AL [ALPHALOW] – 30H
AH [ALPHAHIGH] – 00H
This will transfer the effective address of the source operand, GAMMA,
to register DI.
Exercise 6
Unless otherwise stated, determine the contents of all the affected general
purpose registers and memory addresses after executing the following
program. Each instruction is dependent of one another. Whenever
necessary, use the memory map (handout) for additional data. Assume the
following register contents and labels:
Unless otherwise stated, determine the contents of all the affected general
purpose registers and memory addresses after executing the following
program. Each instruction is dependent of one another. Whenever
necessary, use the memory map (handout) for additional data. Assume the
following register contents and labels:
POP BX
MOV AX, [CX]
MOV BP, AX
MOV SI, [0074H]
MOV CX, [BP + SI]
PUSH CX
CODE: CSP107
Page 12 of 12