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 points
Before looping, call another assembly functionsegment to extract the number of characters in the string points
For swapping characters, call another assembly functionsegment to do just that points
C Code:
#include
using namespace std;
extern"C
void reversechar;
int lengthchar;
int main
char myString "abcde";
int x ;
cout "Length: lengthmyString endl;
cout "Original: myString endl;
reversemyString;
cout "Reversed: myString endl;
systempause;
return ;
Reverse Assembly:
model flat
code
reverse PROC
push ebp
mov ebp,esp ;stack pointer to ebp
mov ebx,ebp ; address of first array element
mov alebx
mov ahebx
mov cl al ;
mov al ah
mov ah cl
mov ebx al
mov ebx ah
pop ebp
ret
reverse ENDP
END
Length Assembly:
model flat
code
length PROC
push ebp
mov ebp,esp
mov ebx,ebp
mov eax,
xor dl dl
loopAgain:
cmp ebxeax dl
je allDone
add eax,
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
