0% found this document useful (0 votes)
8 views2 pages

Concatination String

This assembly program copies two strings ("Hello" and " World") into a buffer and then prints the concatenated string. It defines data sections for the strings and buffer. The main routine copies each string into the buffer, then calls a subroutine to print the concatenated string. Subroutines are defined to copy strings and print strings.

Uploaded by

Deep Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Concatination String

This assembly program copies two strings ("Hello" and " World") into a buffer and then prints the concatenated string. It defines data sections for the strings and buffer. The main routine copies each string into the buffer, then calls a subroutine to print the concatenated string. Subroutines are defined to copy strings and print strings.

Uploaded by

Deep Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

section .

data
string1 db 'Hello', 0
string2 db ' World', 0
result_buffer db 50

section .text
global _start

_start:
mov esi, string1 ; Source address (string1)
mov edi, result_buffer ; Destination address
call copy_string ; Call subroutine to copy string

mov esi, string2 ; Source address (string2)


call copy_string ; Call subroutine to copy string

; Print the concatenated string


mov eax, 4 ; syscall number for sys_write
mov ebx, 1 ; file descriptor 1 (stdout)
mov ecx, result_buffer ; address of the string to print
call print_string ; Call subroutine to print string

; Exit the program


mov eax, 1 ; syscall number for sys_exit
xor ebx, ebx ; return 0 status
int 0x80 ; call kernel

copy_string: ; Copy string from esi to edi


copy_loop:
lodsb ; Load byte from source (esi) into al and increment esi
stosb ; Store byte from al into destination (edi) and increment edi
test al, al ; Test if it's the null terminator
jnz copy_loop ; If not null terminator, continue copying
ret

print_string:
; Print the null-terminated string at the address in ecx
mov edx, ecx ; length of the string
call print_string_length
ret

print_string_length:
; Print the null-terminated string at the address in edx
mov eax, 4 ; syscall number for sys_write
mov ebx, 1 ; file descriptor 1 (stdout)
int 0x80 ; call kernel
ret

You might also like