Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a subroutine which satisfies the following: Name: NElements When the subro

ID: 657030 • Letter: W

Question

Write a subroutine which satisfies the following: Name: NElements When the subroutine is entered it expects the stack to look as follows (as looked in word increments):

Top of the stack ?> PC counter value

Space for output

Input

Subroutine expects the Input on the stack as shown above: The input is the starting address of an array consisting of word length elements. The last element of the array is expected to be -999. Subroutine will place one word of output on the stack in the space as shown above: Output is the number of words in the array (not counting the last word which equals -999) whose starting address is in the input. The subroutine only works with arrays whose last element is -999. It calculates the number of elements in an array not counting the last element -999. For example the array: 2, 45, 67,-34,1, -999 has 5 number of elements. The subroutine should save all local variables on the stack. You will need to use Indirect Register Mode for iterating through the array for which you will need to use a core register. Use RIO for this purpose. As soon as you enter the subroutine, save the existing value of RIO by pushing it on the stack. Just before exiting the subroutine pop the saved value back into RIO. Test this subroutine in main code by using an array Named MyArray with word elements [2, 3, 67, -34,1, -999] placed in the .text region and storing the output in a variable named "Result". Use loops for repeated tasks. Include pseudo code (subroutine only), flow chart (subroutine only) and the text of the assembly file (main program + subroutine). Also include a screen shot of the memory browser which shows the variable "Result" clearly. Use the Carmen drop box setup for this Project.

Explanation / Answer

subroutine od an array

integer :: i, j
integer, parameter :: n=10
real(8), dimension(n) :: x, y
real(8), dimension(n,n) :: val
real(8) :: integ

integ = 0.0D0

do j=1,10
y(j) = dble(j)*1.0D0
x(j) = dble(j) * 2.5D-1
enddo
call subr(x,y,val,n)
do j=1,n
do i=1,n
     integ = integ + val(i,j)
   enddo
enddo

write (*,'(a,e20.10e3)')' Integration value = ',integ

end program integrationarray

subroutine subr(a,b,c,n)
implicit none

screen short for the memory browser :


integer :: n, i, j
real(8) :: a(n),b(n),c(n,n)
do j=1,n
     do i=1,n
     c(i,j) = sin(a(i)+b(j))
     enddo
enddo
return
end subroutine subr

example

*****the arraay[]={2,45,67,-37,1,-999} ******

x=2,y=-999;

store in R10;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote