# string.s -- Program that reads a string, and then # prints it out. We will finish a modification that makes # all the letters capital. # # A string is simply an array of characters (bytes). # # Purpose of registers: # $s0 = base address of string # $s1 = offset into string # $s2 = total address # $s3 = holds single character from string # $s4 = ASCII value of newline character (10) .data string: .space 80 # make room for 80 character string prompt: .asciiz "Please enter some text: " out_str: .asciiz "Your string is: " newline: .asciiz "\n" .text main: la $s0, string # initialize base address of string li $s4, 10 # ascii value of '\n' is 10 li $v0, 4 # print the prompt la $a0, prompt syscall li $v0, 8 # specify input-string function move $a0, $s0 # set $a0 to base address of string li $a1, 80 # tell machine to accept up to 80 chars syscall li $s1, 0 loop: add $s2, $s0, $s1 # compute address of character in array lb $s3, 0($s2) # load single character into $s3 beq $s3, $s4, end_loop li $v0, 1 # print integer value of $s3 move $a0, $s3 syscall li $v0, 4 # print newline la $a0, newline syscall addi $s1, $s1, 1 # point to next character in string j loop end_loop: li $v0, 4 # introduce the output la $a0, out_str syscall li $v0, 4 # print the string move $a0, $s0 syscall li $v0, 4 # print a newline la $a0, newline syscall li $v0, 10 # end of program syscall