Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

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 »

the
Lab 7 - Functions
CS311 - Computer Architecture 1
Fe
uary 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 a
ay 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 a
ay 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_format    db    "%ld",0
printf_found db    "Value %ld found in location %ld",0x0a,0 printf_notfound db    "Value %ld not found in a
ay",0x0a,0
segment .text global main global sort global search extern scanf extern printf
; sort function sort:
et
; search function search:
et
; main function main:
et
Question 2 - main.
    The main function should do    following:
· 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 a
ay 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 a
ay 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
p mov
p, 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 ...
    call    scanf
; call search function call    search
; print output
cmp    rax, 0    ; check if the return value was -1 jl    valnf    ; 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 ...
call    printf endm:
; end main label leave ret
Question 3 - sort.
    The sort function should do    following:
· sort the a
ay 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:
    push    
p
    mov    
p, rsp
    frame    ; set up the frame macro to your needs
    sub    rsp, 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 a
ay
· return the location of the value in the RAX register if the value is found in the a
ay.
· 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:
num    equ local1    ; num is local variable to store the value push    
p mov    
p, rsp frame 1,1,0    ; set up the frame macro to your needs sub    rsp, frame_size mov    [
p+num], rcx ; save value on the stack when passed in rcx
; the linear search code ... found: ...
mov    rax, loc    ; return location in rax if value found jmp    end not_found:
mov    rax, -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 ru
ic is given in Table 1.
T
a
l
e
1
:
G
a
d
i
n
g
u
i
c
F
i
l
e
A
s
p
e
c
t
s
P
o
i
n
t
s
S
o
t
S
e
a
c
h
F
u
n
.
a
s
m
C
o
e
c
t
M
a
i
n
2
0
C
o
e
c
t
I
n
s
e
t
i
o
n
S
o
t
F
u
n
c
t
i
o
n
2
5
C
o
e
c
t
L
i
n
e
a
S
e
a
c
h
F
u
n
c
t
i
o
n
2
5
C
o
e
c
t
S
t
a
c
k
u
s
e
1
0
C
o
e
c
t
s
c
a
n
f
a
n
d
p
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 After Mar 08, 2022

Solution

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