8086 program to transfer a block of bytes by using string instruction
Problem – Write an assembly language program to transfer a block of bytes from one memory location to another memory location by using string instruction.
Example –

Example –
- In this example, the counter value stored in CX register is 4.
- The block of data which is stored from memory location starting from 501 to 504 offset is transferred to another memory location which is starting from 600 to 603 offset.
Assumptions –
CLD instruction is used to clear the directional flag, i.e., DF=0. Now, value of SI and DI will be increased.
SI=SI+1 DI=DI+1
REP instruction is used to repeat the step until value of CX is not equal to zero and value of CX is decremented by one at every step, i.e.,
CX=CX-1
MOVSB instruction is used to transfer bytes only from source memory location (MADS) to destination memory location (MAES).
MADS-->MAES
where MADS=DS*10+SI
MAES=ES*10+DI
Here, value of SI and DI is updated automatically.
if DF=0, SI=SI+1 and DI=DI+1
Algorithm –
- set the value of offset SI equal to 500.
- set the value of offset DI equal to 600.
- load the value 0000 into register AX.
- load the data of AX register into DS(data segment).
- load the data of AX register into ES(extra segment).
- load the data of offset SI into CL register and load value 00 into CH register.
- increment the value of SI by one.
- clear the directional flag so that data is read from lower memory to higher memory location.
- check the value of CX, if not equal to zero then repeat step 10 otherwise go to step 11.
- transfer the data from source memory location to destination memory location and decrease the value of CX by one.
- Stop.
Program –
| Address | Mnemonics | Comments |
|---|---|---|
| 0400 | MOV SI, 500 | SI<-500 |
| 0403 | MOV DI, 00 | DI<-600 |
| 0406 | MOV AX, 0000 | AX<-0000 |
| 0409 | MOV DS, AX | DS<-AX |
| 040B | MOV ES, AX | ES<-AX |
| 040D | MOV CL, [SI] | CL<-[SI] | 0410 | MOV CH, 00 | CH<-00 |
| 0412 | INC SI | SI<-SI+1 |
| 0413 | CLD | clears the directional flag |
| 0414 | REP | repeat until CX is not equal to zero and CX=CX-1 at every step |
| 0415 | MOVSB | transfer the data from source to destination memory location |
| 0416 | HLT | end |
Explaination –
- MOV SI, 500: load the value 500 into offet SI.
- MOV DI, 600: load the value 600 into offset DI.
- MOV AX, 0000: load the value 0000 into AX register.
- MOV DS, AX: load the value of AX register into DS (data segment).
- MOV ES, AX: load the value of AX register into ES (extra segment).
- MOV CL, [SI]: load the data of offset SI into CL register.
- MOV CH, 00: load value 00 into CH register.
- INC SI: increment the value of SI by one.
- CLD: clears the directional flag i.e. DF=0.
- REP: repeat until value of CX is not equal to zero and decrement the value of CX by one at each step.
- MOVSB: transfer the data from source memory location to destination memory location.
- HLT: end.
Recommended Posts:
- 8086 program to transfer a block of 4 bytes by using string instructions
- 8085 program to exchange a block of bytes in memory
- Program execution transfer instructions in 8086 microprocessor
- Data transfer instructions in 8086 microprocessor
- 8086 program to reverse a string
- 8086 program to print a String
- 8086 program to check whether a string is palindrome or not
- 8086 program to search a number in a string
- Computer Organization | Instruction Formats (Zero, One, Two and Three Address Instruction)
- Assembly program to transfer the status of switches
- Assembly language program to find the range of bytes
- 8086 program to add two 8 bit BCD numbers
- String manipulation instructions in 8086 microprocessor
- 8086 program to subtract two 8 bit BCD numbers
- 8086 program for selection sort
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



