我有这种家务问题。
根据用户选择的术语数量,撰写出一个节目,制作顺序如下: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