English 中文(简体)
如何在MIPS的一个阵列中储存顺序?
原标题:How can I store sequence in an array in MIPS?

我有这种家务问题。

根据用户选择的术语数量,撰写出一个节目,制作顺序如下:1,2,2,4,8,32,256,......并储存在一个阵列中。 每一要素的计算方法可以是乘以此前的两个要素。 换言之,Sn的序列号是按Sn=Sn-1×XSn-2等值计算的。

我曾尝试过,但却没有了。

我的法典

^ ^

# UNTITLED PROGRAM

    .data   # Data declaration section
str1: .ascii "Please enter the number of terms to produce: "
arr: .space 40

    .text

main:       # Start of code section


li $v0, 4   # system call code for printing string = 4
la $a0, str1    # load address of string to be printed into $a0
syscall         # call operating system to perform print operation


li $v0, 5   # get ready to read in integers
syscall     # system waits for input
move $s0,$v0    # store the result of the read (returned in $v0) in num1


la $s1,arr
addi $t2,$zero,2    # i=2
addi $t0,$zero,1
add $t1,$t0,$t0
sw $t0,0($s1)
sw $t1,0($s1)

L1:
addi $t2,$t2,1       #i++
addi $s1,$s1,4
lw $t4,0($s1)        #A[i-1]
lw $t5,4($s1)
mul $t3,$t4,$t5
sw $t3,8($s1)
beq $t2,$s0,print 
j L1

print:
lw $t3,0($s1)
li $v0, 1   # system call code for print_int
move $a0, $t3   # integer to print
syscall     # print it
addi $s1,$s1,4
beq $t2,$s0,Exit 
j print


Exit:
li $v0, 10      # exits program
syscall




# END OF PROGRAM
问题回答

计算机辅助设备错误信息:

Error in line 26: Runtime exception at 0x00400030: store address not aligned on word boundary 0x1001002d

错误信息告诉你,你在这项指示中再次试图以非法(不按字)地址获取记忆:

sw $t0,0($s1)

当你遇到类似问题时,你需要使用gger。 首先,在提出例外情形时,在指示中设定一个突破点。

“brkpt”/

操作节目,在休息点停下来时,检查地址(1美元),然后试图进入。 页: 1

“regfile”/

<代码>1有正确的阵容地址,但我认为你再次假定,当你在数据部分制造阵列时,它将在文字上开始。 情况并非如此。 为此,您需要align 。 数据。

    .data   # Data declaration section
str1: .ascii "Please enter the number of terms to produce: "
    .align 2
arr: .space 40




相关问题
WordPress Data Storage Efficiency

I ve been asked to review a WordPress plugin of sorts and try to find ways of making it faster. The premise of this plugin is basically to store a bunch of users and shifts and appointments and ...

Convert a 2D array index into a 1D index

I have two arrays for a chess variant I am coding in java...I have a console version so far which represents the board as a 1D array (size is 32) but I am working on making a GUI for it and I want it ...

Convert an array of integers for use in a SQL "IN" clause

Surely there is a framework method that given an array of integers, strings etc converts them into a list that can be used in a SQL "IN" clause? e.g. int[] values = {1,2,3}; would go to "(1,2,3)"

Sorting twodimensional Array in AS3

So, i have a two-dimensional Array of ID s and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array -...

C++ Array Sort Me

Stuck on an array sorter. Have to sort numbers from largest to smallest. I m trying two loops (one nested in the other). Here s the code: int counter=0; // inner counter int counter2=0; // outer ...

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

Best practice of big javascript objects

sry for this imprecise topic name. I am querying a dataset a lot of times so using ajax request would end up in tons of http requests. For this reason I decided to use the json encode method to ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

热门标签