Knowee
Questions
Features
Study Tools

Develop an assembly language program that swaps the values of two strings, which can be of any length.

Question

Develop an assembly language program that swaps the values of two strings, which can be of any length.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a simple assembly language program that swaps the values of two strings. This program is written in x86 assembly language and uses the Irvine32 library.

INCLUDE Irvine32.inc

.data
string1 BYTE "Hello", 0
string2 BYTE "World", 0
temp BYTE SIZEOF string1 DUP(0)

.code
main PROC
    ; Copy string1 to temp
    mov esi, OFFSET string1
    mov edi, OFFSET temp
    mov ecx, SIZEOF string1
    rep movsb

    ; Copy string2 to string1
    mov esi, OFFSET string2
    mov edi, OFFSET string1
    mov ecx, SIZEOF string2
    rep movsb

    ; Copy temp to string2
    mov esi, OFFSET temp
    mov edi, OFFSET string2
    mov ecx, SIZEOF temp
    rep movsb

    ; Print the swapped strings
    mov edx, OFFSET string1
    call WriteString
    call Crlf
    mov edx, OFFSET string2
    call WriteString
    call Crlf

    exit
main ENDP
END main

This program works by first copying the contents of string1 to a temporary string temp. Then it copies the contents of string2 to string1. Finally, it copies the contents of temp (which is the original string1) to string2. The rep movsb instruction is used to copy the strings. It repeats the movsb instruction ecx times, where ecx is the size of the string being copied. The esi register points to the source string and the edi register points to the destination string.

Please note that this program assumes that string1 and string2 are the same length. If they are not, you will need to adjust the size of temp and the value of ecx accordingly.

This problem has been solved

Similar Questions

Arun is working on a program to swap the values of two variables, a and b, without using a temporary variable. Write a program to help Arun accomplish this task.Input format :The first line of input is an integer value a.The second line of input is an integer value b.Output format :The output prints the values of a and b after swapping. Refer to the sample output for the formatting specifications.

A set of simple string manipulation functions are employed in _______a.<stdio.h>b.<conio.h>c.<string.h>d.<math.h>

Arun is working on a program to swap the values of two variables, a and b, without using a temporary variable. Write a program to help Arun accomplish this task.

Write a program for reading a position and deleting a character at that specified location in a given string in assembly language

What is the function to concatenate two strings in C programming?

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.