Question: Assignment - Reverse String Problem Statement: Create a Legv 8 program that reverses the characters in a string. The program should handle strings stored in

Assignment
-
Reverse String
Problem Statement: Create a Legv
8
program that reverses the characters in a string. The program should handle strings stored in memory and reverse the order of characters in place.
Requirements
Input:
The program should begin with a predefined string stored in memory. Choose a string that is a mix of characters, including spaces and punctuation, with a length of at least
1
5
characters.
Clearly define the starting address of the string in the program.
Process:
Develop the assembly code to reverse the string in place, without using additional memory to store the reversed string.
Ensure the program correctly handles the null
-
terminator character at the end of the string to maintain proper string formatting in memory.
Output:
After reversing, the program should ensure the modified string is correctly null
-
terminated and stored back at its original memory location.
(
Hint:
1
0
4
1
0
1
1
0
8
1
0
8
1
1
1
-
this is the ascii code of hello
Convert it to hex
Then store in memory
)
This solution does not work in LEGv
8
Simulator. Please correct the code and try it in LEGv
8
Simulator. I need correct solution.
.
data
string:
.
byte
0
x
4
8
,
0
x
6
5
,
0
x
6
C
,
0
x
6
C
,
0
x
6
F
,
0
x
2
C
,
0
x
2
0
,
0
x
5
7
,
0
x
6
F
,
0
x
7
2
,
0
x
6
C
,
0
x
6
4
,
0
x
2
1
,
0
x
2
1
,
0
x
2
1
,
0
x
0
0
.
text
.
global
_
start
_
start:
/
/
Load the base address of the string
LDR X
0
,
=
string
/
/
Find the length of the string
MOV X
1
,
X
0
/
/
Copy base address to X
1
find
_
end:
LDRB W
2
,
[
X
1
]
/
/
Load byte at X
1
into W
2
CBZ W
2
,
reverse
/
/
If byte is null, jump to reverse
ADD X
1
,
X
1
,
#
1
/
/
Increment X
1
B find
_
end
reverse:
SUB X
1
,
X
1
,
#
1
/
/
Decrement X
1
to point to the last character
/
/
Set up pointers for swapping
MOV X
2
,
X
0
/
/
X
2
is the start pointer
MOV X
3
,
X
1
/
/
X
3
is the end pointer
swap:
CMP X
2
,
X
3
/
/
Compare start and end pointers
B
.
GT done
/
/
If start
>
end, we're done
is it safe to solve

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 Databases Questions!