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

Crat a function which taks four 64-bit intgr argumnts (g. W, X, Y, Z). Your func

ID: 3883784 • Letter: C

Question

Crat a function which taks four 64-bit intgr argumnts (g. W, X, Y, Z).

Your function should comput (W + X) * (Y - Z), and lav th rsult in RAX whn it rturns.

Your function should accpt th four argumnts using appropriat convntions (s rgistrs listd in th lctur slids).

rdi, rsi, rdx, rcx, r8, r9 should be th main reigsters you use

Your function should NOT print anything - it should ONLY prform th math, and rturn th rsult.

Us a loop to comput th abov function ovr an array of siz 16 (A[0], A[1], ..., A[15])

Dclar an array (in mmory) containing 16 rasonabl 64-bit intgr valus (of your choosing).

Us a loop to itrat ovr th lmnts of th array, and us your function (abov) to calculat th valu of vry four conscutiv array valus.

For xampl, rax = (A[0] + A[1]) * (A[2] - A[3]), thn rax = (A[1] + A[2]) * (A[3] - A[4]), tc.

For ach itration, print out th calculation, th rsult, and start a nwlin (xactly lik this): (5 + 2) * (3 - 4) = -7

Th last itration should comput rax = (A[12] + A[13]) * (A[14] - A[15]) ... (i.. don't calculat past th nd of th array!)

Explanation / Answer

package test;

import java.util.Random;

public class Testing {

   private Integer[] arr;

   public Testing(int count) {

       arr = new Integer[count];

       int i;

       for (i = 0; i < arr.length; i++)

       {

           arr[i] = new Random().nextInt();

       }

   }

  

   public Integer computeRax(Integer w,Integer x,Integer y,Integer z) {

       return (w + x) * (y - z);

      

   }

   public static void main(String[] args) {

       Testing test = new Testing(16);

       int i;

       for (i = 0; i < test.arr.length - 3; i++)

       {

           System.out.println("(" + test.arr[i] + " + " + test.arr[i+1] + ") * (" + test.arr[i+2] + " + " + test.arr[i+3] + ") = " + test.computeRax(test.arr[i], test.arr[i+1], test.arr[i+2], test.arr[i+3]));

          

       }

   }

}