Lab 5
Lab 5 : Programming based on block data transfer
OBJECTIVE
To familiar with the use of data transfer instruction set of 8086
PRELAB
Read data transfer instructions and segment registers from textbook in detail.
DATA TRANSFER INSTRUCTIONS
Instructions | Operands | Description |
MOV | REG, memory
memory, REG
REG, REG
memory, immediate
REG, immediate
SREG, memory
memory, SREG
REG, SREG
SREG, REG
| Copy operand2 to operand1.
The MOV instruction cannot:
• Set the value of the CS and IP registers.
• Copy value of one segment register to another segment register (should copy to general register first).
• Copy immediate value to segment register (should copy to general register first).
Algorithm: operand1 = operand2
Ex:
Mov AX,BX ;Copy contents of BX to AX
Mov si,00h ;load Si with 00h |
PUSH | REG
SREG
memory | Store 16 bit value in the stack.
Algorithm:
• SP = SP - 2
• SS:[SP] (top of the stack) = operand |
POP | REG
SREG
memory | Get 16 bit value from the stack.
Algorithm: Operand = SS : [SP](top of stack)
SP = Sp + 2. |
XCHG | REG, memory
memory, REG
REG, REG | Exchange values of two operands.
Algorithm: operand1 < - > operand2 |
IN | AL, im.byte
AL, DX
AX, im.byte
AX, DX | Input from port into AL or AX.
Second operand is a port number. If required to access port number over 255 - DX register should be used. |
OUT | AL, ibyte
AL, DX
AX, DX | Output from AL or AX to port.
First operand is a port number. If required to access port number over 255 - DX register should be used. |
LEA | REG, memory | Load Effective Address.
Algorithm:
REG = address of memory (offset) |
XLAT | No Operands | Translate byte from table.
Copy value of memory byte at DS:[BX + unsigned AL] to AL register.
Algorithm: AL = DS:[BX + unsigned AL] |
EXERCISES
1) An ALP to transfer a given block of data from source memory block to the destination memory block without overlap.
ASSUME CS:CODE, DS:DATA
DATA SEGMENT
SOURCE DB 10 DUP(?) ; Source block
DEST DB 10 DUP(?) ; Destination block
COUNT DW 10 ; Number of bytes to transfer
DATA ENDS
CODE SEGMENT
START:
MOV AX, DATA
MOV DS, AX
MOV ES, AX ; Set ES to point to the same segment as DS
LEA SI, SOURCE ; Load effective address of source into SI
LEA DI, DEST ; Load effective address of destination into DI
MOV CX, COUNT ; Load count into CX for loop
TRANSFER:
MOV AL, [SI] ; Move byte from source to AL
MOV [DI], AL ; Move byte from AL to destination
INC SI ; Increment source index
INC DI ; Increment destination index
LOOP TRANSFER ; Repeat until CX = 0
MOV AH, 4CH ; DOS function: Exit program
INT 21H ; DOS interrupt
CODE ENDS
END START
2) An ALP to exchange a block of data located from source to the destination memory locations.
ASSUME CS:CODE, DS:DATA
DATA SEGMENT
SOURCE DB 10 DUP(?) ; Source block
DEST DB 10 DUP(?) ; Destination block
COUNT DW 10 ; Number of bytes to exchange
DATA ENDS
CODE SEGMENT
START:
MOV AX, DATA
MOV DS, AX
MOV ES, AX ; Set ES to point to the same segment as DS
LEA SI, SOURCE ; Load effective address of source into SI
LEA DI, DEST ; Load effective address of destination into DI
MOV CX, COUNT ; Load count into CX for loop
EXCHANGE:
MOV AL, [SI] ; Move byte from source to AL
MOV BL, [DI] ; Move byte from destination to BL
MOV [SI], BL ; Move byte from BL to source
MOV [DI], AL ; Move byte from AL to destination
INC SI ; Increment source index
INC DI ; Increment destination index
LOOP EXCHANGE ; Repeat until CX = 0
MOV AH, 4CH ; DOS function: Exit program
INT 21H ; DOS interrupt
CODE ENDS
END START