Write a short RISC-V assembly program that operates on a NULL terminated string of arbitrary size (use your favourite phrase when you define it with DC for testing). The program (no need to define a function) scans the string and replaces every lower case character with the corresponding upper case. Your program prints the string before and after converting it to upper case.
Please give positive ratings for my effort. Thanks.
PROGRAM
convertOpposite(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&):
addi sp,sp,-32
sd s0,24(sp)
addi s0,sp,32
sd a0,-24(s0)
nop
ld s0,24(sp)
addi sp,sp,32
jr ra
.LC0:
.string "Enter the string : "
.LC1:
.string "\nResultant String : "
main:
addi sp,sp,-80
sd ra,72(sp)
sd s0,64(sp)
sd s1,56(sp)
addi s0,sp,80
addi a5,s0,-72
mv a0,a5
call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string() [complete object constructor]
lui a5,%hi(.LC0)
addi a1,a5,%lo(.LC0)
lui a5,%hi(_ZSt4cout)
addi a0,a5,%lo(_ZSt4cout)
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
addi a5,s0,-72
mv a1,a5
lui a5,%hi(_ZSt3cin)
addi a0,a5,%lo(_ZSt3cin)
call std::basic_istream<char, std::char_traits<char> >& std::operator>><char, std::char_traits<char>, std::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)
addi a5,s0,-72
mv a0,a5
call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::length() const
mv a5,a0
sw a5,-40(s0)
sw zero,-36(s0)
.L10:
lw a4,-36(s0)
lw a5,-40(s0)
sext.w a4,a4
sext.w a5,a5
bge a4,a5,.L3
lw a4,-36(s0)
addi a5,s0,-72
mv a1,a4
mv a0,a5
call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned long)
mv a5,a0
lbu a5,0(a5)
mv a4,a5
li a5,96
bleu a4,a5,.L4
lw a4,-36(s0)
addi a5,s0,-72
mv a1,a4
mv a0,a5
call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned long)
mv a5,a0
lbu a5,0(a5)
mv a4,a5
li a5,122
bgtu a4,a5,.L4
li a5,1
j .L5
.L4:
li a5,0
.L5:
beqz a5,.L6
lw a4,-36(s0)
addi a5,s0,-72
mv a1,a4
mv a0,a5
call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned long)
mv a5,a0
lbu s1,0(a5)
lw a4,-36(s0)
addi a5,s0,-72
mv a1,a4
mv a0,a5
call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned long)
mv a4,a0
addiw a5,s1,-32
andi a5,a5,0xff
sb a5,0(a4)
j .L7
.L6:
lw a4,-36(s0)
addi a5,s0,-72
mv a1,a4
mv a0,a5
call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned long)
mv a5,a0
lbu a5,0(a5)
mv a4,a5
li a5,64
bleu a4,a5,.L8
lw a4,-36(s0)
addi a5,s0,-72
mv a1,a4
mv a0,a5
call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned long)
mv a5,a0
lbu a5,0(a5)
mv a4,a5
li a5,90
bgtu a4,a5,.L8
li a5,1
j .L9
.L8:
li a5,0
.L9:
beqz a5,.L7
lw a4,-36(s0)
addi a5,s0,-72
mv a1,a4
mv a0,a5
call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned long)
mv a5,a0
lbu s1,0(a5)
lw a4,-36(s0)
addi a5,s0,-72
mv a1,a4
mv a0,a5
call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned long)
mv a4,a0
addiw a5,s1,32
andi a5,a5,0xff
sb a5,0(a4)
.L7:
lw a5,-36(s0)
addiw a5,a5,1
sw a5,-36(s0)
j .L10
.L3:
lui a5,%hi(.LC1)
addi a1,a5,%lo(.LC1)
lui a5,%hi(_ZSt4cout)
addi a0,a5,%lo(_ZSt4cout)
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
mv a4,a0
addi a5,s0,-72
mv a1,a5
mv a0,a4
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
li s1,0
addi a5,s0,-72
mv a0,a5
call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
mv a5,s1
j .L14
mv s1,a0
addi a5,s0,-72
mv a0,a5
call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
mv a5,s1
mv a0,a5
call _Unwind_Resume
.L14:
mv a0,a5
ld ra,72(sp)
ld s0,64(sp)
ld s1,56(sp)
addi sp,sp,80
jr ra
__static_initialization_and_destruction_0(int, int):
addi sp,sp,-32
sd ra,24(sp)
sd s0,16(sp)
addi s0,sp,32
mv a5,a0
mv a4,a1
sw a5,-20(s0)
mv a5,a4
sw a5,-24(s0)
lw a5,-20(s0)
sext.w a4,a5
li a5,1
bne a4,a5,.L17
lw a5,-24(s0)
sext.w a4,a5
li a5,65536
addi a5,a5,-1
bne a4,a5,.L17
lui a5,%hi(_ZStL8__ioinit)
addi a0,a5,%lo(_ZStL8__ioinit)
call std::ios_base::Init::Init() [complete object constructor]
lui a5,%hi(__dso_handle)
addi a2,a5,%lo(__dso_handle)
lui a5,%hi(_ZStL8__ioinit)
addi a1,a5,%lo(_ZStL8__ioinit)
lui a5,%hi(_ZNSt8ios_base4InitD1Ev)
addi a0,a5,%lo(_ZNSt8ios_base4InitD1Ev)
call __cxa_atexit
.L17:
nop
ld ra,24(sp)
ld s0,16(sp)
addi sp,sp,32
jr ra
_GLOBAL__sub_I_convertOpposite(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&):
addi sp,sp,-16
sd ra,8(sp)
sd s0,0(sp)
addi s0,sp,16
li a5,65536
addi a1,a5,-1
li a0,1
call __static_initialization_and_destruction_0(int, int)
ld ra,8(sp)
ld s0,0(sp)
addi sp,sp,16
jr ra
DW.ref.__gxx_personality_v0:
IMAGE OF OUTPUT
Get Answers For Free
Most questions answered within 1 hours.