In the Settings menu of SPIM set Bare Machine OFF , Allow Pseudo Instructions ON
ID: 3618126 • Letter: I
Question
In the Settings menu of SPIM set Bare MachineOFF, Allow Pseudo InstructionsON, Load Trap File ON, DelayedBranches OFF, Delayed Loads OFF,Mapped IO ON, Quiet OFF.
Run the programs by loading the trap handler (as explained inthe chapter) and clicking SimulatorGo and then OK inthe pop-up panel.
Explanation / Answer
x.Xlor="red">please rate - thanks ## $s0 --- char of string ## $s1 --- p, index for input strings ## $s2 --- q, index for combined string .text .globl main main: # while ( true ) li $v0,4 # print "Enter First String:" la $a0,prompt1 # syscall li $v0,8 # read string into "string1" la $a0,string1 # $a0 == buffer address li $a1,132 # $a1 == buffer length syscall lb $s0,string1 # if ( string==empty ) nop li $t1,10 # new line in ascii is 10 beq $s0,$t1,done # done nop li $v0,4 # print "Enter Secnd String:" la $a0,prompt2 # syscall li $v0,8 # read string into "string2" la $a0,string2 # $a0 == buffer address li $a1,132 # $a1 == buffer length syscall # copy string1 to string3 li $s1,0 # p = 0 li $s2,0 # q = 0 scan1: lb $s0,string1($s1) # while ( string1[p] != ' ' ) nop beq $s0,$t1,end1 # nop sb $s0,string3($s2) # string3[q] = string1[p] addiu $s1,$s1,1 # p = p+1 addiu $s2,$s2,1 # q = q+1 b scan1 # endwhile nop end1: # copy string2 to string3 li $s1,0 # p = 0 scan2: lb $s0,string2($s1) # while ( string2[p] != ' ' ) nop beq $s0,$t1,end2 # nop sb $s0,string3($s2) # string3[q] = string1[p] addiu $s1,$s1,1 # p = p+1 addiu $s2,$s2,1 # q = q+1 b scan2 # endwhile nop end2: sb