Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions

Question

What is the effect of word war second?

Answered: 1 week ago

Question

Would you recommend this program to your employer? Why?

Answered: 1 week ago