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

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

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

Describe how a character string is displayed on the monitor usingassembly language. Give an example (Note: complete program is notrequired).

__________ converts the programs written in assembly language into machine instructions

Write a python program to: Read two strings, then put the second string in the middle ofthe first string. And finally Write the new string in a new file.

1/1

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.