Question: Implement a function in assembly that would do the following: - Loop through a sequence of characters in a string and swap them such that

Implement a function in assembly that would do the following:
-Loop through a sequence of characters in a string and swap them such that the end result is the original string in reverse (50 points )
-Before looping, call another assembly function/segment to extract the number of characters in the string (30 points )
-For swapping characters, call another assembly function/segment to do just that (20 points )
C++ Code:
#include
using namespace std;
extern"C"{
void reverse(char[]);
int length(char[]);
}
int main()
{
char myString[]= "abcde";
int x =0;
cout << "Length: "<< length(myString)<< endl;
cout << "Original: "<< myString << endl;
reverse(myString);
cout << "Reversed: "<< myString << endl;
system("pause");
return 0;
}
Reverse Assembly:
.686
.model flat
.code
_reverse PROC
push ebp
mov ebp,esp ;stack pointer to ebp
mov ebx,[ebp+8] ; address of first array element
mov al,[ebx]
mov ah,[ebx+1]
mov cl, al ;
mov al, ah
mov ah, cl
mov [ebx], al
mov [ebx+1], ah
pop ebp
ret
_reverse ENDP
END
Length Assembly:
.686
.model flat
.code
_length PROC
push ebp
mov ebp,esp
mov ebx,[ebp+8]
mov eax, 0
xor dl, dl
loopAgain:
cmp [ebx+eax], dl
je allDone
add eax, 1
jmp loopAgain
allDone:
pop ebp
ret
_length ENDP
END

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!