the Lab 7 - Functions CS311 - Computer Architecture 1 February 27, 2022 The last laboratory exercise requires you to code the Search and Sort algorithm from Lab 6 as functions in assembly. Please...

1 answer below »
Assembly Code 64 bits Windows



the Lab 7 - Functions CS311 - Computer Architecture 1 February 27, 2022 The last laboratory exercise requires you to code the Search and Sort algorithm from Lab 6 as functions in assembly. Please create a file named SortSearchFun.asm in ebe. Question 1 - Outline. The sixth laboratory exercise required you to code the Insertion Sort algorithm and sort a given array of integers and then find the index of a given value using the Linear Search algorithm. In this lab, you are required to split this code into three distinct functions: · main - the main function, which will call the sort and search function, and handles the user input and output functions. · sort - function to sort the data using Insertion Sort Algorithm. · search - function to search for a value in the sorted array using Linear Search Algorithm. The general outline of the code is given as: segment .data a db 7,5,2,3,6 size db 5 val dq 0 scanf_formatdb"%ld",0 printf_found db"Value %ld found in location %ld",0x0a,0 printf_notfound db"Value %ld not found in array",0x0a,0 segment .text global main global sort global search extern scanf extern printf ; sort function sort: ret ; search function search: ret ; main function main: ret Question 2 - main. The main function should dofollowing: · call the sort function · ask the user to input an unsigned integer number between [0, 100] (inclusive) in the terminal, using scanf and save this number in the location val. · call the search function and pass the val to the function using the RCX register. · if the return value of the RAX register is -1, then print to the terminal the string array printf notfound. This require the val as one of the parameters. · if the return value of the RAX register is the location of the found val, then print to the terminal the string array printf found. This requires the val and the location as returned by the RAX register. A sample main outline can be given as: main: push rbp mov rbp, rsp frame; set up the frame macro to your needs sub rsp, frame_size ; call sort function call sort ; ask for user input value to search for ; set up the parameters as required for scanf ... callscanf ; call search function callsearch ; print output cmprax, 0; check if the return value was -1 jlvalnf; value not found ; set up the parameters as required for printf_found ... call printf jmp endm valnf: ; if the value is not found ; set up the parameters as required for printf_notfound ... callprintf endm: ; end main label leave ret Question 3 - sort. The sort function should dofollowing: · sort the array in place using Insertion Sort Algorithm. · no restrictions on number of used register. · no restrictions is placed on stack use and local variables. A sample sort outline can be given as: ; sort function sort: pushrbp movrbp, rsp frame; set up the frame macro to your needs subrsp, frame_size ; the Insertion sort code ... leave ret Question 4 - search. The search function should do the following: · accept the number from main in the RCX register (i.e. incoming frame macro should be at least 1) · create a local variable and save this number on the stack (i.e. the second parameter of frame macro should be at least 1). · return -1 in RAX register if the value is not found in the array · return the location of the value in the RAX register if the value is found in the array. · no other restrictions on number of used register. · no other restrictions is placed on stack use and local variables. Linear Search algorithm: A sample search outline can be given as: search: numequ local1; num is local variable to store the value pushrbp movrbp, rsp frame 1,1,0; set up the frame macro to your needs subrsp, frame_size mov[rbp+num], rcx ; save value on the stack when passed in rcx ; the linear search code ... found: ... movrax, loc; return location in rax if value found jmpend not_found: movrax, -1; return -1 if value not found end: leave ret Constraints Please note that values can only be passed into function using specific registers in strict order. Also certain registers must be preserved inside functions. Therefore, care must be taken in selection of which registers to use. Submission All submitted files MUST have student name, student CWU ID and the honor code in them (and not written on Canvas). If any of these mandatory requirements are missing from the submission, it will not be graded and the student will be given 0 points for the lab. The file must be submitted through Canvas before 11:59am March 11, 2022. The grading rubric is given in Table 1. T a b l e 1 : G r a d i n g r u b r i c F i l e A s p e c t s P o i n t s S o r t S e a r c h F u n . a s m C o r r e c t M a i n 2 0 C o r r e c t I n s e r t i o n S o r t F u n c t i o n 2 5 C o r r e c t L i n e a r S e a r c h F u n c t i o n 2 5 C o r r e c t S t a c k u s e 1 0 C o r r e c t s c a n f a n d p r i n t f 1 0 D o c u m e n t a t i o n 1 0 1 1 1
Answered 2 days AfterMar 08, 2022

Answer To: the Lab 7 - Functions CS311 - Computer Architecture 1 February 27, 2022 The last laboratory exercise...

Jahir Abbas answered on Mar 11 2022
105 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here