0% found this document useful (0 votes)
109 views12 pages

Topic 9 - 10 - Data Transfer Instructions

The document discusses data transfer instructions in computer organization, specifically the MOV and XCHG instructions. It provides examples of using these instructions, explaining how they transfer data between registers and memory. MOV moves data without affecting flags, while XCHG swaps the contents of source and destination operands. Memory addresses are calculated based on segment registers and index registers when transferring data to/from memory.

Uploaded by

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

Topic 9 - 10 - Data Transfer Instructions

The document discusses data transfer instructions in computer organization, specifically the MOV and XCHG instructions. It provides examples of using these instructions, explaining how they transfer data between registers and memory. MOV moves data without affecting flags, while XCHG swaps the contents of source and destination operands. Memory addresses are calculated based on segment registers and index registers when transferring data to/from memory.

Uploaded by

CHOI Hunter
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

COMPUTER

ORGANIZATION TOPIC FOR THE WEEK: Data Transfer Instructions

NOTES:

Classification of Instructions

The instruction set of a microcomputer defines the basic operations that


a programmer can make the device perform. There are about a 117 basic
instructions for the 8086/88 chip.

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

A memory map (handout) will be used as a reference for all examples


and exercises in this course.

MOV Instruction

Data transfer instructions facilitate the movement of data either between


registers or between a register and main memory. They do not affect the
flags.

The MOV Instruction

Format: MOV D, S

Action: D [S]

Destination Source Example


register register MOV CX, BX
register MM MOV CX, [BP+SI]
MM register MOV [BX], DX
register immediate MOV CX, 80FEH
MM immediate MOV word ptr [BX], 1834H
seg reg register MOV DS, BX
register seg reg MOV AX, CS
seg reg MM MOV SS, [1AFFH]
MM seg reg MOV [BP+SI+1000H], DS

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.

The operand [BX] refers to a memory location whose offset address


is specified by the content of the register BX. FILE is a memory
label whose address is specified by its equivalent offset address.

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:

MOV AX, 1800H


MOV DS, AX

4. The destination operand cannot be immediate data. MOV 1800H,


AX is therefore invalid.

5. More often than not, register CS cannot be the destination operand.

6. If the destination operand is a memory location and the source


operand is immediate data, the prefix byte ptr or word ptr should
appear after the MOV instruction to denote the data size of the
immediate operand.

Example: MOV 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:

AX = 0015H BP = 0002H CS = 3000H


BX = 0019H SP = 0035H DS = 2000H
CX = 0012H DI = 0017H SS = 2000H
DX = 001BH SI = 001EH ES = 4000H

MOV AX, BX
MOV DI, 0005H
MOV [BP + SI], AX

Answer:

MOV AX, BX

AX = 0019H

MOV DI, 0005H

DI = 0005H

MOV [BP + SI], AX

The destination operand is a memory location; we need to compute for


the physical address. Since BP is used, the segment base address is
the stack segment.

Physical Address = SS x 10H + BP + SI;


Physical Address = 20000 + 0002H + 001EH
Physical Address = 20020H

CODE: CSP107
Page 2 of 12
COMPUTER 20020H [AL] – 19H
ORGANIZATION 20021H [AH] – 00H

NOTES: The XCHG Instruction

The XCHG (Exchange) instruction swaps the contents of the source and
destination operands.

Format: XCHG D, S

Action: [D] [S]

Destination Source Example


MM register XCHG [BX],
CX
register register XCHG AH, BL

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

However, four registers are needed in order to implement an


exchange between two registers.

5. Segment registers cannot be used as operands in the XCHG


instruction. XCHG ES, BX is therefore invalid. Instead use:

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:

AX = 0015H BP = 0002H CS = 3000H


BX = 0019H SP = 0035H DS = 2000H
CX = 0012H DI = 0017H SS = 2000H
DX = 001BH SI = 001EH ES = 4000H

XCHG DI, SI
XCHG BX, [CX]
XCHG [BX + 0020H], AX

Answer:

XCHG DI, SI

DI = 001EH
SI = 0017H

XCHG BX, [CX]

The source operand is a memory location; we need to compute for the


physical address. The segment base address is the data segment.

Physical Address = DS x 10H + CX


Physical Address = 20000 + 0012H
Physical Address = 20012H

BL [20012H] – 08H (refer to the memory map)


BH [20013H] – 00H (refer to the memory map)

20012H [BL] – 19H


20013H [BH] – 00H

XCHG [BX + 0020H], AX

The destination operand is a memory location; we need to compute for


the physical address. The segment base address is the data segment.

Physical Address = DS x 10H + BX + 0020H;


Physical Address = 20000 + 0008H + 0020H
Physical Address = 20028H

20028H [AL] – 15H


20029H [AH] – 00H

AL [20028H] – 91H (refer to the memory map)


AH [20029H] – 9FH (refer to the memory map)

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:

AX = 0015H BP = 0002H CS = 3000H


BX = 0019H SP = 0035H DS = 2000H
CX = 0012H DI = 0017H SS = 2000H
DX = 001BH SI = 001EH ES = 4000H

MOV AX, 0034H


XCHG CX, [AX]
MOV [CX + SI], BX

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:

AX = 0015H BP = 0002H CS = 3000H


BX = 0019H SP = 0035H DS = 2000H
CX = 0012H DI = 0017H SS = 2000H
DX = 001BH SI = 001EH ES = 4000H

XCHG AX, BX
MOV [CX], AX
XCHG BX, [CX + SI + 000FH]

The PUSH Instruction

The PUSH instruction decrements SP by 2 and then moves a word data


from the source operand to the top of the stack pointed to by SP.

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:

AX = 0015H BP = 0002H CS = 3000H


BX = 0019H SP = 0035H DS = 2000H
CX = 0012H DI = 0017H SS = 2000H
DX = 001BH SI = 001EH ES = 4000H

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.

Top of the Stack = SS x 10H + SP


= 20000H + 0035H
= 20035H

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.

PUSH AX; 20034H (AH) = 15H


20033H (AL) = 00H

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.

Top of the Stack = SS x 10H + SP


= 20000H + 0033H (new SP from the previous
instr.)
= 20033H

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.

PUSH [BX]; 20031H [20019H] = 12H (refer to memory map)


20032H [2001AH] = FFH (refer to memory map)

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:

AX = 0015H BP = 0002H CS = 3000H


BX = 0019H SP = 0035H DS = 2000H
CX = 0012H DI = 0017H SS = 2000H
DX = 001BH SI = 001EH ES = 4000H

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:

1. The POP instruction pops word-sized data only.


2. POP CS is not allowed. However, the instruction PUSH CS is valid.

Example: POP 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:

AX = 0015H BP = 0002H CS = 3000H


BX = 0019H SP = 0035H DS = 2000H
CX = 0012H DI = 0017H SS = 2000H
DX = 001BH SI = 001EH ES = 4000H

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.

Top of the Stack = SS x 10H + SP


= 20000H + 0035H
= 20035H

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.

POP AX; AL [20035H] – 00H - this is the current top of


stack
AH [20036H] – 70H - top of stack +1

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.

Top of the Stack = SS x 10H + SP


= 20000H + 0037H (new Sp from the previous instr.)
= 20037H

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.

Physical Address = DS x 10H + BX


Physical Address = 20000H + 0019H
Physical Address = 20019H

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.

POP [BX]; 20019H [20037H] – 85H - this is the current top of


stack
2001AH [20038H] – F8H - top of stack +1

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:

AX = 0015H BP = 0002H CS = 3000H


BX = 0019H SP = 0035H DS = 2000H
CX = 0012H DI = 0017H SS = 2000H
DX = 001BH SI = 001EH ES = 4000H

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:

AX = 0015H BP = 0002H CS = 3000H


BX = 0019H SP = 0035H DS = 2000H
CX = 0012H DI = 0017H SS = 2000H
DX = 001BH SI = 001EH ES = 4000H

POP CX
POP [BP+ SI + 0010H]
PUSH SI
PUSH [DI]

The LEA Instruction

The LEA (Load Effective Address) instruction is for transferring the


effective address (not data) of the source operand to the destination
operand.

Format: LEA D, S
Action: D EA of S

Pointers:

1. The source operand should always be one of the memory


addressing modes, while the destination operand should always
be a 16-bit register.
2. In the LEA instruction, the effective address is moved to the
destination operand. Therefore, the destination operand is like a
pointer.
3. Usually, registers BX, BP, DI, or SI are used as the destination
operand since these registers could be used as offset registers.

Examples:

Assume the following:

DS = 5000H
LIST = 1800H

CODE: CSP107
Page 10 of 12
COMPUTER
ORGANIZATION

NOTES: 51802H 44H

51801H 33H

51800H 22H

517FFH 11H

If the MOV DI, LIST instruction is executed, the contents of memory


location 51800H and 51801H are transferred to register DI. DI will
therefore contain the word 3322H.

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.

Example: LEA 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 and labels:

AX = 0015H BP = 0002H CS = 3000H


BX = 0019H SP = 0035H DS = 2000H
CX = 0012H DI = 0017H SS = 2000H
DX = 001BH SI = 001EH ES = 4000H
LIST = 0020H ALPHA = 0030H GAMMA = 0040H

MOV AX, LIST


LEA BX, ALPHA
LEA DI, GAMMA

Answer:

MOV AX, LIST

The content of the memory location specified by the effective address


LIST is:

Physical Address = DS x 10H + LIST


Physical Address = 20000H + 0020H
Physical Address = 20020H

AL [20020H] – E2H (refer to the memory map)


AH [20021H] – 5FH (refer to the memory map)

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

LEA DI, GAMMA

This will transfer the effective address of the source operand, GAMMA,
to register DI.

DILOW [GAMMAALOW] – 40H


DIHIGH [GAMMAHIGH] – 00H

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:

AX = 0015H BP = 0002H CS = 3000H


BX = 0019H SP = 0035H DS = 2000H
CX = 0012H DI = 0017H SS = 2000H
DX = 001BH SI = 001EH ES = 4000H
LIST = 0020H ALPHA = 0030H GAMMA = 0040H

LEA AX, LIST


MOV ALPHA, BX
MOV GAMMA, DI
LEA SI, ALPHA

Data Transfer Instruction Exercise

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:

AX = 0015H BP = 0002H CS = 3000H


BX = 0019H SP = 0035H DS = 2000H
CX = 0012H DI = 0017H SS = 2000H
DX = 001BH SI = 001EH ES = 4000H

POP BX
MOV AX, [CX]
MOV BP, AX
MOV SI, [0074H]
MOV CX, [BP + SI]
PUSH CX

CODE: CSP107
Page 12 of 12

You might also like