Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.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 代码正在读取具有指定字符串的继续字符串_Assembly_Mips - Fatal编程技术网

Assembly 代码正在读取具有指定字符串的继续字符串

Assembly 代码正在读取具有指定字符串的继续字符串,assembly,mips,Assembly,Mips,所以我正在调试一些代码,并不断得到一个奇怪的结果。我在一个数组中循环并将每个元素打印到控制台。打印每个元素后,我希望打印一个仅由“\n”换行符组成的字符串。我在QtSpim中运行代码。当我这样做时,打印新行和下一个字符串str3。我只想让它打印str2,这样下一个元素就可以在新行上打印了。任何人遇到这样的问题或看到我的代码有任何问题 问题在于print_sorted_data函数中的第二个系统调用 .data x: .word 1,2,3,4,5,6,7,8 #

所以我正在调试一些代码,并不断得到一个奇怪的结果。我在一个数组中循环并将每个元素打印到控制台。打印每个元素后,我希望打印一个仅由“\n”换行符组成的字符串。我在QtSpim中运行代码。当我这样做时,打印新行和下一个字符串str3。我只想让它打印str2,这样下一个元素就可以在新行上打印了。任何人遇到这样的问题或看到我的代码有任何问题

问题在于print_sorted_data函数中的第二个系统调用

.data        
    x:    .word  1,2,3,4,5,6,7,8  #OR  x: .space 32   #since x contains 8 words,we have to reserve 32 bytes.    
    min:  .word  0
    max:  .word  0
    mean: .word  0  
    str1: .ascii "\n The Min, Max and Mean of the array are : \n "  

    str2: .ascii " \n"

    str3: .ascii "Enter Number: \n"

.text  
#======================================================================= 
main: 
#======================================================================= 

    #Push $ra into stack 
addi $sp, $sp, -4
sw $ra, 0($sp)

#-------------------------------------------------------------------
#***jal read_data 
#***nop  
#-------------------------------------------------------------------

la $a0, x
ori $a1, $0, 8

#-------------------------------------------------------------------
jal print_sorted_data   
nop
#-------------------------------------------------------------------




jr $ra
nop

#======================================================================= 
read_data:  
#======================================================================= 
    #reading data from console , storing it in memory
    #initialization for the counter of the loop

addi $t1, $0, 0     ## $t1<-stores counter for loop.

## don't need addi $t2, $0, 8        ## max value of loop

#lodad The base adderss of array 
la $t0, x

check_cond1: ##############################
        #check condition of the loop, if not met branch to read_done

slti $t3, $t1, 8
beq  $t3, $0, read_done1
nop

        #read an int from console and store it in &x[i]

ori $v0, $0, 4  ## print " enter number" to screen
la $a0, str3   ## changed lw to la
syscall

ori $v0, $0, 5
syscall
sw $v0, 0($t0)

    #update both counter of the loop and pointer to the next element in the array

addi $t1, $t1, 1
addi $t0, $t0, 4

j check_cond1
nop

read_done1: 
jr $ra  
nop

#=======================================================================
#printing the sorted data
print_sorted_data:
#=======================================================================
    #initialization for the counter of the loop
    #lodad The base adderss of array 

ori $t9, $a0, 0 ##  We get base address in $a0
ori $t0, $0, 0 ##counter for loop


check_cond2: ##############################
        #check condition of the loop, if not met branch to print_done1

slt $t1, $t0, $a1
beq $t1,$0, print_done1

    #print x[i]
sll $t2,$t0 ,2 ## Multiply counter by 4 for offset
add $t2, $t2, $t9 ## Add to base address

ori $v0, $0, 1 ## set syscall up to print integer
lw $a0, 0($t2)
syscall  ## not sure if this is right func name## it is

    #go to next line by printing "\n"

ori $v0, $0, 4 ## set syscall up to print string
la $a0, str2
syscall



    #update both counter of the loop and pointer to the next element in the array
##Dont think i have to update array. It does that in the loop.

add $t0, $t0, 1

j check_cond2
nop 

print_done1: #######################
jr $ra  
nop 
.data
x:.单词1,2,3,4,5,6,7,8或x:.空格32#由于x包含8个单词,我们必须保留32个字节。
最小:。字0
最大值:。字0
平均值:。单词0
str1:.ascii“\n数组的最小值、最大值和平均值为:\n”
str2:.ascii“\n”
str3:.ascii“输入编号:\n”
.文本
#======================================================================= 
主要内容:
#======================================================================= 
#将$ra推入堆栈
附加$sp,$sp,-4
西南$ra,0($sp)
#-------------------------------------------------------------------
#***日本航空公司读取数据
#***不
#-------------------------------------------------------------------
洛杉矶$a0,x
ori$a1、$0、8
#-------------------------------------------------------------------
日航打印数据
不
#-------------------------------------------------------------------
jr$ra
不
#======================================================================= 
读取数据:
#======================================================================= 
#从控制台读取数据,并将其存储在内存中
#循环计数器的初始化

addi$t1,$0,0##$t1差值为
.asciiz
给定字符串后的尾随零。基本上它与
.ascii
几乎相同,它只附加一个0字符,作为字符串的终止字符

因此,如果使用
.ascii
并且没有手动指定终止0,则字符串将与内存中的以下数据合并-
\n
不是字符串终止(仅是行终止)