In: Computer Science
Hi
Can you solve this question for me in MIPS language works on mars4.5:
Write a program that asks the user to enter a letter (between A and Z) and display the letter corresponding index in the alphapet (e.g, if user enters A, display 1).
MIPS PROGRAM :-
.data
message: .asciiz "Please, enter a letter (between A and Z):
\n"
result: .asciiz "Index of the alphabet is
:"
.text
main:
# show the
message
li $v0, 4
la $a0, message
syscall
# reads a character and the
user input is stored in $t1
li $v0, 12
syscall
add $t1, $zero, $v0
#ascii code of 'A'
li $t0, 0x41
#subtracting the ASCII of the character with ASCII
code of 'A'
#it gives the offset index value with referring 'A' as
0
sub $t3, $t1, $t0
#as we need to start from indexing 'A' as 1; we add
value 1 to it
addi $t3 $t3, 1
show:
# prints out the message
li $v0, 4
la $a0, result
syscall
# prints out the result
li $v0, 1
add $a0, $zero, $t3
syscall
# end of the main
function
li $v0, 10
syscall