assembly - Store Strings in MIPS -
i short.
i making program in mips intake strings of 15 chars user. unable save string on stack. note using 2d matrix [20][15] 20 string , each string have 15 character.
please guide me. have been trying on past 10 hours.
loop: bgt $t2,20,xyz li $v0,8 #take in input la $a0, buffer #load byte space address li $a1, 15 # allot byte space string syscall move $t3,$a0 #save string t0 #transfering data onto stack! #num = $t2 #$base address of matrix = $t1 #colums of matrix = 15 mul $s0,$t2,15 #num * colums li $s1,4 #string have 4 bit! mul $s0,$s0,$s1 add $s0,$s0,$t1 #$t1 base address! #storing data onto stack! sw $t3,0($s0) add $t2,$t2,1 add $s0,$s0,-15 j loop
you're storing address of string on stack, not string itself
t3 set by:
la $a0, buffer #load byte space address move $t3,$a0 #save string t0
storing instruction:
sw $t3,0($s0)
this next instruction assumes 15 bytes written:
add $s0,$s0,-15
you wrote 4 bytes sw $t2,0($s0). gets destroyed in next loop anyway recalculate , overwrite s0 based on t2. making add $s0,$s0,-15 redundant.
you need string copy routine like
#a0=dest, a1=source copy_string: lbu v0,(a1) addiu a1,a1,#1 sb v0,(a0) addiu a0,a0,#1 bnez v0, copy_string
Comments
Post a Comment