Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly 在MIPS中存储字符串_Assembly_Mips_Mips32_Mips64 - Fatal编程技术网

Assembly 在MIPS中存储字符串

Assembly 在MIPS中存储字符串,assembly,mips,mips32,mips64,Assembly,Mips,Mips32,Mips64,我会很简短 我正在用MIPS制作一个程序,从用户那里接收15个字符的字符串。 我无法在堆栈上保存字符串。 请注意,我使用的是2D矩阵[20][15],其中20是字符串,每个字符串有15个字符 请引导我。我已经试了10个小时了 Loop: bgt $t2,20,XYZ li $v0,8 #take in input la $a0, buffer #load byte space into address li $a1, 15 # allot the byte space

我会很简短

我正在用MIPS制作一个程序,从用户那里接收15个字符的字符串。 我无法在堆栈上保存字符串。 请注意,我使用的是2D矩阵[20][15],其中20是字符串,每个字符串有15个字符

请引导我。我已经试了10个小时了

Loop:
bgt $t2,20,XYZ

li $v0,8        #take in input
la $a0, buffer  #load byte space into address
li $a1, 15      # allot the byte space for string
syscall

move $t3,$a0    #save string to t0


#transfering the 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 is the base address!

#storing the data onto the stack!
sw $t3,0($s0)

add $t2,$t2,1
add $s0,$s0,-15 
j Loop

您正在堆栈上存储字符串的地址,而不是字符串本身

t3由以下人员设置:

la $a0, buffer  #load byte space into address
move $t3,$a0    #save string to t0
存储指令:

sw $t3,0($s0)
下一条指令假设写入了15个字节:

add $s0,$s0,-15 
您只使用SW$t2,0$s0写入了4个字节。在下一个循环中,当您基于T2重新计算和覆盖S0时,这也会被破坏。使add$s0、$s0、-15冗余

您需要一个字符串复制例程,如

#A0=Dest, A1=Source
copy_string:
   lbu v0,(a1)    
   addiu a1,a1,#1   
   sb v0,(a0)
   addiu a0,a0,#1
   bnez v0, copy_string

字符串有4位!哈哈,这是一个错误的评论。我知道。