Joining two strings
A program that joins two strings into one.
Program source code
title .model small .stack 100h data segment public string1 db "Microsoft $", 20 dup(?) string2 db "Macro Assembler$" strlen2 equ ($-string2) data ends code segment public assume ds:data, cs:code main proc mov ax, seg data ; Get the data segment address and store it in ax mov ds, ax ; Pass the data segment address from ax to ds mov es, ax ; Pass the data segment address from ax to es mov cx, 0FFFFh ; Set the counter to -1 mov al, 24h ; Copy the string terminator value ($) into the al register lea di, es:[string1] ; Load the address of the string1 variable into the destination register es:di lea si, ds:[string2] ; Load the address of the string2 variable into the source register ds:si repnz scasb ; Scan for the byte in the al register among the bytes in es:di dec di ; Decrement the di register value by 1. We position ourselves where the ($) was mov cx, strlen2 ; Set the counter to the length of the string2 string rep movsb ; Copy from ds:si to es:di while CX≠0 mov ah, 09h ; Copy the string output function number into ah lea dx, ds:[string1] ; Load the address of the string1 variable into the ds:dx register int 21h ; Call the interrupt mov ax, 4C00h ; Copy the termination function number into ah and the value into al int 21h ; Call the interrupt main endp code ends end main
Microsoft Macro Assembler
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".