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
Memory MIPS:存储地址在字边界上未对齐_Memory_Assembly_Store_Mips - Fatal编程技术网

Memory MIPS:存储地址在字边界上未对齐

Memory MIPS:存储地址在字边界上未对齐,memory,assembly,store,mips,Memory,Assembly,Store,Mips,我正试图编写一个程序,用MIPS汇编语言计算出句子中非空格字符、字符和单词的数量。我成功地做到了这一点,但最后我没有什么问题 我得到了这些值,比如随机寄存器中的空格数,并试图将它们保存到彼此相邻的3个寄存器中($s1、$s2、$s3),但当我运行程序(使用Mars)时,我得到以下错误:0x00400070处的运行时异常:存储地址未在字边界0x0000001e上对齐 我将在下面发布我的代码。提前感谢您的回答 .data char_count: .word 0 space_count

我正试图编写一个程序,用MIPS汇编语言计算出句子中非空格字符、字符和单词的数量。我成功地做到了这一点,但最后我没有什么问题

我得到了这些值,比如随机寄存器中的空格数,并试图将它们保存到彼此相邻的3个寄存器中($s1、$s2、$s3),但当我运行程序(使用Mars)时,我得到以下错误:0x00400070处的运行时异常:存储地址未在字边界0x0000001e上对齐

我将在下面发布我的代码。提前感谢您的回答

    .data 

char_count: .word 0 

space_count: .word 0 

word_count: .word 0 

text_input: .asciiz "I'm having an old friend for dinner." 

    .text  
    .globl main

main:
la $s0, char_count        #t1 storing char_count address         

la $t0, text_input # Loading the text
li $t1, 0 # Making the character counter 0
addi $t5, $t5, 0x20 # Loading up the hex value for space
addi $t8, $t8, 0 # Making the register which decides whether or not the characters     (spaces/letters) before the space were a word.
addi $t9, $t9, 1 # Used for comparing the $t8 register to
addi $s4, $s4, 0 # Used for camping the $t8 register to

count:  
lb $t2, 0($t0)  # Load the first byte from address in $t0  
beqz $t2, end   # If the byte is 0 then jump to the end of the program
beq $t2, $t5, space # If the byte is a space then jump to the part of the program which     adds one to the space counter
beq $t8, $t9, continue   # If the word deciding register equals 1 then skip to the         continue part (to stop $t8 getting bigger than 1).
addi $t8, $t8, 1 # Add 1 to the register to indicate that a letter was the last byte.
continue:
add $t1, $t1, 1 # Increment the counter
add $t0, $t0, 1      # Increment the address  
j count      # This then loops this part of the program  

space:
addi $t4, $t4, 1 # Add 1 to the space counter
beq $t8, $s4, continue # If word deciding register equals 0 then jump to continue
sub $t8, $t8, $t9 # Make word deciding register ($t8) go back to 0
addi $t3, $t3, 1 # Add 1 to word counter
jal continue    

end:
beq $t8, $s4, finish
addi $t3, $t3, 1 # If last byte in the string was a character than another word must be         added. This stops spaces at the end being counted as a word.

finish:

sub $t6, $t1,$t4 # This works out the number of non space characters by doing number of     characters minus spaces.

sw $s1, ($t6)           # Trying to store number of non spaces in s1
sw $s2, ($t4)            #  Trying to store number of spaces in s2
sw $s3, ($t3)            # trying to store number of words in s3

li $v0, 10
syscall # Terminates the program.

您使用
sw
的方式与您似乎想要做的不匹配:

sw $s1, ($t6)           # Trying to store number of non spaces in s1
这一行实际上是什么?它将
$s1
中包含的单词存储在
$t6
所指向的内存位置

如果您只是想将
$t6
的内容复制到
$s1
中,您应该使用:

move $s1, $t6
sw $t6, ($s1)
如果您想将
$t6
存储在内存中
$s1
指向的位置,您应该使用:

move $s1, $t6
sw $t6, ($s1)

请记住,在这种情况下,您需要首先在
$s1
中放置一个有效地址;e、 g.
la$s1,char\u count

您使用的
sw
方式与您试图执行的操作不匹配:

sw $s1, ($t6)           # Trying to store number of non spaces in s1
这一行实际上是什么?它将
$s1
中包含的单词存储在
$t6
所指向的内存位置

如果您只是想将
$t6
的内容复制到
$s1
中,您应该使用:

move $s1, $t6
sw $t6, ($s1)
如果您想将
$t6
存储在内存中
$s1
指向的位置,您应该使用:

move $s1, $t6
sw $t6, ($s1)

请记住,在这种情况下,您需要首先在
$s1
中放置一个有效地址;e、 g.
la$s1,char\u count

谢谢您的回答!我要做的是将$t6存储在$t1位置的内存中。我把la$s1,char_计数放在主菜单中,但它仍然不起作用。我这样做对吗?另外,对于三个不同的商店,我需要放置3个有效地址吗?好的,我再次尝试了你的建议,现在它运行没有任何错误。但是,我看不到$s1中$t6的值。我应该看到$s1中的值,还是对sw函数的含义感到困惑?您所说的“in
$s1
”是什么意思?您是在谈论
$s1
的值还是
$s1
指向的内存中的值
sw
用于将寄存器的值存储到内存中,而不是将值从一个寄存器移动到另一个寄存器。我想将值存储在s1中。假设t6显示5,我想s1也说5。我是否需要使用移动功能进行此操作,或者sw是否工作?谢谢你应该使用
move
。谢谢你的回答!我要做的是将$t6存储在$t1位置的内存中。我把la$s1,char_计数放在主菜单中,但它仍然不起作用。我这样做对吗?另外,对于三个不同的商店,我需要放置3个有效地址吗?好的,我再次尝试了你的建议,现在它运行没有任何错误。但是,我看不到$s1中$t6的值。我应该看到$s1中的值,还是对sw函数的含义感到困惑?您所说的“in
$s1
”是什么意思?您是在谈论
$s1
的值还是
$s1
指向的内存中的值
sw
用于将寄存器的值存储到内存中,而不是将值从一个寄存器移动到另一个寄存器。我想将值存储在s1中。假设t6显示5,我想s1也说5。我是否需要使用移动功能进行此操作,或者sw是否工作?谢谢你应该使用
move