Write a program in assembly language to calculate a[6] and print it to the outpu
ID: 641040 • Letter: W
Question
Write a program in assembly language to calculate a[6] and print it to the output.
Let :
a[0]=1
a[1]=2
a[n]=(a[n-1] + a[n-2]) * (a[n-1]
Explanation / Answer
#data segment .data numbers:.word 2,1,5,3,10 count: .word 5 ans1: .asciiz "sum = " endl: .asciiz " " #text segment .text main: la $a0, numbers # load array address lw $a1, count # load number of elements jal sum # call sum function move $a0, $v0 # call print jal print j finish # finish sum: bge $t2, $a1, done #if t2>=$a1, goto done lw $t0, 0($a0) #load value at addr a0 to t0 add $t1, $t1, $t0 # sum = sum + array[i] addi $a0, $a0, 4 # add addr by 4 to get the address of next value in the array addi $t2, $t2, 1 # i = i + 1 j sum done: move $v0, $t1 # move result to v0 jr $ra #go to return addr print: # code to print ansl, sum and end # deleted for brevity jr $ra # return finish: li $v0, 10 # exit syscall
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.