mips - QtSpim Character Insertion -
the program accepts single-letter keyboard input @ time. letter inputs must lower case through z (no upper-case or non-letter characters allowed; lower-case letters). 1 letter must input @ time; make sure character lower-case letter.
• in data declaration, declare alphabetized string of letters (named “str”), a-z.
• program must input character keyboard, determine place in string, , make space in string character, inserting in proper alphabetical order.
• after alphabetized string of 26 letters, declare sequence of 30 nulls (using “.space” directive), expansion space string insert characters alphabetized list.
• @ point, can ask print current string (i.e., many letter inserts have been made far) inputting capital p keyboard.
• finally, program must use recursive routine insert letter in correct point in program.
my code far
.data str: .asciiz"abcdefghijklmnopqrstuvwxyz\n" espace: .space 30 prompt: .asciiz "please enter lowercase letter \n" error1: .asciiz "error! please input lowercase letter. \n" answer: .asciiz "the alphebetized letters far \n" .text main: la $s0,0 li $v0,4 la $a0,prompt syscall loop: li $v0,12 syscall move $t0,$v0 blt $t0,61,error #if less bgt $t0,80,error #if more z bge $t0,0x50,print #when user enters p, print loop2: lb $t2,str($s0) #load first byte of string bge $t0,$t2,store #if input char=string char, store addi $s0,$s0,1 #next char in string j loop store: la $t0,str+26 li $t1,'a' sb $t1,($t0) # append 'a' string sb $zero,1($t0) # add null terminator after 'a' sw $t0,str($s0) #store char in string addi $s0,$s0,1 j loop error: li $v0,4 la $a0,error1 #print error message syscall j loop #jump loop print: li $v0,4 la $a0,answer #print dialogue syscall li $v0,4 la $a0,str #print string syscall
i need know how write code inputs character in string
Comments
Post a Comment