8086 program to transfer a block of bytes by using string instruction

09 Jun, 2022
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.
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.
The value of counter which tells the number of bytes to be transferred is stored at offset 500.
The 8-bit data which have to be transfer is stored in continuous memory location starting from 501.
The data is transferred to a continuous memory location starting from 600.
The value of DS and ES is taken equal to 0000.
the program starts from offset 400.
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 the value of CX is not equal to zero and the 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  
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 the 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.
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 the 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.
MOV SI, 500: load the value 500 into offset 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 the AX register into ES (extra segment).MOV CL, [SI]: load the data of offset SI into the 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 the source memory location to the destination memory location.HLT: end.
MOV SI, 500: load the value 500 into offset 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 the AX register into ES (extra segment).
MOV CL, [SI]: load the data of offset SI into the 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 the source memory location to the destination memory location.
HLT: end.
Akanksha_Rai
surinderdawra388
guptamridul75
microprocessor
system-programming
Computer Organization & Architecture
microprocessor
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Logical and Physical Address in Operating System
Direct Access Media (DMA) Controller in Computer Architecture
Computer Organization | RISC and CISC
Memory Hierarchy Design and its Characteristics
Computer Organization and Architecture | Pipelining | Set 1 (Execution, Stages and Throughput)
Interrupts
Architecture of 8085 microprocessor
Control Characters
Computer Organization | Instruction Formats (Zero, One, Two and Three Address Instruction)
Programmable peripheral interface 8255