Question
Finding the maximum value in an array only takes a few minutes to code in C and maybe 20 minutes to code in assembly (if
Finding the maximum value in an array only takes a few minutes to code in C and maybe 20 minutes to code in assembly (if you've done the practice problems, attended the lecture, and follow best programming practices). Debugging can take hours - unless you use gdb - then it only takes a few minutes. Corrections and Additions None yet. Specifications 1. Complete the template file find_maximum.s. This file contains exactly one function that returns the index of the maximum value in an array of integers. 2. Write the code in x86-64 assembly. 3. Make your code as human-readable as possible by adding comments for each short block of code as well as each line of assembly. 4. When combined with the provided drivers, your code must write the phrase \"The maximum value in the array is found at index ???\" where ??? is replaced with the correct index. This text is provided in the driver files. 5. You may print any other debugging code so long as the answer phrase is also printed. 6. Your code may not produce a segmentation fault, infinite loop, or command terminated errors. These errors will result in a grade of 0 on the assignment Files
find max.s - Do your work here.
driver4.s - Assembly code for a function that calls prepares a 4-element array and calls Find_Max(). This file also contains the code for the debugging function Print_One_Number(). Your function must work with this code. driver5.s - Assembly code for a function that calls prepares a 5-element array and calls Find_Max(). This file also contains the code for the debugging function Print One_Number(). Your function must work with this code.
driver4.c - C code for main with the 4-element array driver5.c - C code for main with the 5-element array find max template.c - C code provided to show the equivalent functionality of the provided find_max.s
find max.c - C code that finds the maximum value in an array. (You really shouldn't need this)
Compiling, Running, and Debugging Compile the code and produce the default executable gcc -g find_max.s driver4.s -Wall Run the default executable ./a.out Write a new driver - edit driverX.c and compile to assembly with gcc So driverX.s driverx.c Debug with gdb gdb./a.out Use the qdb commands: start layout as stepi nexti info registers help x (to examine memory)
.file \"find_max_template.c\" .text .section .rodata .align 8 .LC0: .string \"The length of the array is %d \" .text .globl Find_Max .type Find_Max, @function Find_Max: // prologue - write code for the prologue here // printf(\"The length of the array is %d \", n); // update this code if necessary to print the length of the array // this block prints the value of register %edi // initially the parameter n movl %edi, %eax movl %eax, %esi leaq .LC0(%rip), %rdi movl $0, %eax call printf@PLT // reserve space for local variables /* make a table here the variables from * your c code and the addresses used in assembly * n - address of n * a - address of a * i - address of i * .... */ // this code calls Print_One_Number to // print the number found in register %eax - use this code to debug // replace $999 with a register or memory address you wish to print movl $999, %eax movl %eax, %edi call Print_One_Number@PLT // write your code to find the index of the maximum value here // prepare the return value // the template returns -1, you will need to update this movl $-1, %eax // epilogue - complete the epilogue below ret .LFE0: .size Find_Max, .-Find_Max .ident \"GCC: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0\" .section .note.GNU-stack,\"\",@progbits .section .note.gnu.property,\"a\" .align 8 .long 1f - 0f .long 4f - 1f .long 5 0: .string \"GNU\" 1: .align 8 .long 0xc0000002 .long 3f - 2f 2: .long 0x3 3: .align 8 4:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started