Performing Block Transfer using Assembly Language

In this blog post, we’ll explore how to perform a block transfer using an 8086 assembly language program. The following code snippet demonstrates this process:

DATA SEGMENT
STRING1 DB 01H,02H,03H,04H,05H
STRING2 DB 4 DUP(0)
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV ES,AX
LEA SI,STRING1
LEA DI,STRING2
MOV CX,05H
CLD
REP MOVSB
INT 3
CODE ENDS
END START

Overall Process:

  • The program initializes registers and sets up pointers to the source array (STRING1) and the destination array (STRING2).
  • It sets up the CX register as a counter for the number of bytes to transfer.
  • The CLD (Clear Direction Flag) instruction ensures that data is copied in a forward direction.
  • The REP MOVSB instruction is used to transfer bytes from STRING1 to STRING2 efficiently.
  • The process continues until all bytes in STRING1 are copied to STRING2.
  • The program terminates after successfully transferring the data.

Step-by-Step Explanation of Block Transfer Process:

Data Segment:

  • STRING1: Defines a source array of hexadecimal numbers (01H, 02H, 03H, 04H, 05H).
  • STRING2: Defines a destination array initialized with zeroes using 4 DUP(0), reserving space.

Code Segment: Initialization

  1. MOV AX, DATA: Loads the address of the data segment into the AX register.
  2. MOV DS, AX: Sets the DS register to point to the data segment, allowing access to source data.
  3. MOV ES, AX: Sets the ES register to the same data segment for destination storage.
  4. LEA SI, STRING1: Loads the address of the source array STRING1 into the SI register.
  5. LEA DI, STRING2: Loads the address of the destination array STRING2 into the DI register.
  6. MOV CX, 05H: Sets the loop counter CX to 5, corresponding to the number of elements to transfer.

Performing the Block Transfer:

  1. CLD: Clears the direction flag to ensure auto-increment mode.
  2. REP MOVSB: Executes MOVSB instruction CX times, copying bytes from STRING1 to STRING2.

Program Termination:

  • INT 3: Generates an interrupt 3, which typically halts the program execution.

Output

C:\TASM>masm bt.asm
Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987.  All rights reserved.
 
Object filename [bt.OBJ]:
Source listing  [NUL.LST]:
Cross-reference [NUL.CRF]:
bt.asm(1): warning A4001: Extra characters on line
 
  50422 + 450234 Bytes symbol space free
 
      1 Warning Errors
      0 Severe  Errors
 
C:\TASM>link bt.obj
Microsoft (R) Overlay Linker  Version 3.60
Copyright (C) Microsoft Corp 1983-1987.  All rights reserved.
 
Run File [BT.EXE]:
List File [NUL.MAP]:
Libraries [.LIB]:
LINK : warning L4021: no stack segment
 
C:\TASM>debug bt.exe
-g
 
AX=0B97  BX=0000  CX=0000  DX=0000  SP=0000  BP=0000  SI=0005  DI=000A
DS=0B97  ES=0B97  SS=0B97  CS=0B98  IP=0015   NV UP EI PL NZ NA PO NC
0B98:0015 CC            INT     3
-d 0B97:0000
0B97:0000  01 02 03 04 05 01 02 03-04 05 00 00 00 00 00 00   ................
0B97:0010  B8 97 0B 8E D8 8E C0 8D-36 00 00 8D 3E 05 00 B9   ........6...>...
0B97:0020  05 00 FC F3 A4 CC 15 8A-86 70 FF 2A E4 50 B8 FD   .........p.*.P..
0B97:0030  05 50 FF 36 24 21 E8 77-63 83 C4 06 FF 36 24 21   .P.6$!.wc....6$!
0B97:0040  B8 0A 00 50 E8 47 5E 83-C4 04 5E 8B E5 5D C3 90   ...P.G^...^..]..
0B97:0050  55 8B EC 81 EC 84 00 C4-5E 04 26 80 7F 0A 00 74   U.......^.&....t
0B97:0060  3E 8B 46 08 8B 56 0A 89-46 FC 89 56 FE C4 5E FC   >.F..V..F..V..^.
0B97:0070  26 8A 47 0C 2A E4 40 50-8B C3 05 0C 00 52 50 E8   &.G.*[email protected].
-q
 
C:\TASM>

Understanding the Memory Dump

The memory dump displayed in the DEBUG session shows the contents of memory after running the program. Let’s analyze the key parts.

AddressData (Hex)ASCII RepresentationDescription
0B97:000001 02 03 04 05.....First five bytes from STRING1
0B97:000501 02 03 04 05.....Copied data in STRING2
0B97:000A00 00 00 00 00 00......Unused/initialized memory

Final Thoughts:

This simple assembly program demonstrates how to perform a block transfer efficiently using REP MOVSB. It’s a powerful way to copy data in assembly language, often used in low-level programming and system operations.

“Block transfer in assembly—because moving bytes is just another form of digital teleportation!” 😆

4 thoughts on “Performing Block Transfer using Assembly Language”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.