Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help to complete this code in x86_64 assembly Procedure For this assignment you must write all code in x86_64 assembly (but you may use/call

Need help to complete this code in x86_64 assembly

Procedure

For this assignment you must write all code in x86_64 assembly (but you may use/call C functions in your assembly code).

All code should be in one source file only (asm_program.asm)

You may reuse code from any of my assembly examples for this assignment.

Create a function named "Compute" which takes four 64-bit integer arguments (eg. W, X, Y, Z).

Your function should compute ((W * X) - (Y / Z)) / 8, and leave the result in RAX when it returns.

Your function should accept the four arguments using appropriate conventions (see registers listed in the lecture slides).

Your function should NOT print anything - it should ONLY perform the math, and return the result via RAX.

Use a loop to compute the above function over an array of size 16 (A[0], A[1], ..., A[15])

Declare an array (in memory) containing the following 16 64-bit integer values: 2,15,14,7,5,2,18,3,3,45,12,4,55,17,108,9

Use a loop to iterate over the elements of the array, and use your function (above) to calculate the value of every four consecutive array values.

For example, rax = ((A[0] * A[1]) - (A[2] / A[3])) / 8, then rax = ((A[1] * A[2]) - (A[3] / A[4])) / 8, then rax = ((A[2] * A[3]) - (A[4] / A[5])) / 8, then ... ... ... rax = ((A[12] * A[13]) - (A[14] / A[15])) / 8 done

Based on the sample array, rax = ((2 * 15) - (14 / 7)) / 8, then rax = ((15 * 14) - (7 / 5)) / 8, then rax = ((14 * 7) - (5 / 2)) / 8, then ... ... ... rax = ((55 * 17) - (108 / 9)) / 8 done

For each iteration, print out the calculation, the result, and start a newline (Output based on the sample array): ((2 * 15) - (14 / 7))/8 = 3 ((15 * 14) - (7 / 5))/8 = 26 ((14 * 7) - (5 / 2)) = 12 ((7 * 5) - (2 / 18))/8 = 4 ... ... ... ((55 * 17) - (108 / 9))/8 = 115

The last iteration should compute rax = (A[12] * A[13]) - (A[14] / A[15]) ... (i.e. don't calculate past the end of the array!)

Your output should exactly match the above form.

Compile and link your code to make an executable (asm_program)

Use insightful comments in the code to illustrate what is happening at each step

The assembly source code file should be named "asm_program.asm"

The executable file should be named "asm_program"

There should not be any folder within the zip file. The zip file should only contain two files: "asm_program.asm" and "asm_program"

Your function should take exactly four arugments

.global main .text main: mov $0, %r15 #initialize a counter %r15 to 0, and use this counter to get the element of the array loop: cmp $13, %r15 je done inc %r15, 4 call compute jmp loop compute: #Calculates ((W * X) - (Y / Z)) / 8) # W in %rdi, X in %rsi, Y in %rdx, Z in %rcx mov %rax, %rdi mul %rsi mov %rbx, %rdx mov $0, %rdx #make rdx 0 because any non_zero number will make the dividend (rdx,rcx) a very large number. div %rcx sub %rax, %rbx mov %rbx, 8 div %rbx ret done: # calling sys_exit mov $60, %rax mov $0, %rdi syscall .data array: .quad 2,15,14,7,5,2,18,3,3,45,12,4,55,17,108,9

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2005 For Windows Mobile Web Office And Database Applications Comprehensive

Authors: Gary B. Shelly, Thomas J. Cashman, Corinne Hoisington

1st Edition

0619254823, 978-0619254827

More Books

Students also viewed these Databases questions

Question

here) and other areas you consider relevant.

Answered: 1 week ago