Problem – Write a program to transfer a block of 4 bytes, starting address is 0500 and transfer the block at address 0600 by using string instructions.
Example –
Assumptions – Assume that there are 4 blocks in memory addresses 0500, 0501, 0502, 0503.
Algorithm –
- Assign value 500 in SI and 600 in DI
- Assign the value 0000 H to AX
- Move the content of AX in DS
- Move the content of AX in ES
- Assign the value 0004 H to CX
- Clear the directional flag
- Repeat until CX=0, Move string block
- Halt of the program
Program –
MEMORY ADDRESS | MNEMONICS | COMMENTS |
---|---|---|
0400 | MOV SI, 500 | SI <- 500 |
0403 | MOV DI, 600 | DI <- 600 |
0406 | MOV AX, 0000 | AX <- 0000 |
0409 | MOV DS, AX | DS <- AX |
040B | MOV ES, AX | ES <- AX |
040D | MOV CX, 0004 | CX <- 0004 |
0410 | CLD | CLEAR DIRECTIONAL FLAG |
0411 | REP | REPEAT UNTIL CX=0 |
0412 | MOVSB | MOVE THE BLOCK |
0413 | HLT | END OF THE PROGRAM |
Explanation –
- MOV SI, 500 assigns 500 to SI
- MOV DI, 600 assigns 600 to DI
- MOV AX, 00 assign 0000 to AX register
- MOV DS, AX moves the content of AX to DS segment
- MOV ES, AX moves the content of AX to ES segment
- MOV CX, 0004 assign 0000 to CX register
- CLD clear the directional flag
- REP repeat until CX=0
- MOVSB move string block
- HLT stops the execution of the program.