Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##output the contents of an "array" which you initialize via .byte, .word, .half
- #then, input a string and output the string backwards
- .data
- string_array:
- .space 1000 #define an array 1000 bytes big
- reverse_array:
- .space 1000 #define the array that will hold the reverse
- .globl main
- .text
- main:
- la $a0, user_input #user input
- li $v0, 4
- syscall
- la $a0, string_array #prepare for user input into the string array
- li $a1, 1000 #telling it to feed it into those 1000 bytes of memory + 1(why +1?)
- li $v0, 8 #the actual syscall code
- syscall
- la $t0, string_array #set t1 to store an address of our string array
- la $t2, reverse_array #set t2 to be the address of our reverse array
- repeat:
- lb $t1, ($t0) #store the BYTE indicated by the address in t0
- beqz $t1, finish #if the address becomes 0, terminate
- ##get the maximium of the reverse array and feed byte by byte from the back-to-front
- addi $t0, $t0, 4 #increase the address by 4, which moves us to the next byte
- finish:
- la $a0, terminate
- li $v0, 4
- syscall
- li $v0, 10
- syscall
- .data
- user_input:
- .asciiz "Input your string: "
- terminate:
- .asciiz "Terminating the program."
- #DO: hybrid assignment 7
- #http://courses.cs.vt.edu/~cs2505/summer2011/Notes/pdf/T23.MIPSArrays.pdf
- #https://rosettacode.org/wiki/Reverse_a_string#MIPS_Assembly
Advertisement
Add Comment
Please, Sign In to add comment