Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Mathematics 3670 Lab 13: Implementing Pointer Functions and Array Sorting - Prof. William , Lab Reports of Mathematics

In this document, students are provided with instructions for lab 13 in mathematics 3670, where they will focus on parameter passing at the machine level, specifically handling pointer values and arrays in the presence of subroutines. Students are required to create and test several new functions, including 'swap' and 'sort3', which will be used to interchange values and sort arrays, respectively.

Typology: Lab Reports

2009/2010

Uploaded on 02/24/2010

koofers-user-t78
koofers-user-t78 🇺🇸

5

(2)

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Mathematics 3670: Laboratory 13
Lab Preview
In this lab, we will continue to emphasize issues of parameter passing at the machine level. Of
special interest is how to pass and use pointer values and arrays in the presence of subroutines.
The lab asks you to implement a few new functions and to illustrate their use within a main
program.
Lab Exercises
1. Create a lab13 directory. Place copies of the AshOS files and the function library file
funlib.asm in this directory. In the course of completing the lab, you will add lab13a.asm,
lab13b.asm and lab13c.asm to this directory.
2. Add a new function, swap, to your library of functions. In the C language, this function has
the following prototype:
void swap(int* px, int* py);
Each of the two parameters is a pointer to an int variable. The return type, void, indicates
there is no value computed by this function. In machine terms, each parameter is a memory
address. As shown in the diagram below, we want the swap function to interchange the values
of the corresponding words of memory.
py
px
py
px α
β
β
α
y
x
y
x
Before invoking swap After invoking swap
Follow all the conventions for passing parameters and using stack frames that were established
for Labs 11 and 12.
3. Create a test driver program, lab13a.asm, which illustrates the use of the swap function. In
this program, create four words of memory, initialized as follows:
a: .fill 10
b: .fill 20
c: .fill 30
d: .fill 40
Your program should invoke swap twice: once for the pair aand band a second time for c
and d.
4. Add a new function, sort3, to funlib.asm which will rearrange three words of memory so
they are in order, from smallest to largest. A C language prototype for this function is:
void sort3(int* px, int* py, int* pz);
This function should make pairwise comparisons and perform swaps as necessary. Your code
must make use of the swap function.
pf2

Partial preview of the text

Download Mathematics 3670 Lab 13: Implementing Pointer Functions and Array Sorting - Prof. William and more Lab Reports Mathematics in PDF only on Docsity!

Mathematics 3670: Laboratory 13

Lab Preview

In this lab, we will continue to emphasize issues of parameter passing at the machine level. Of special interest is how to pass and use pointer values and arrays in the presence of subroutines. The lab asks you to implement a few new functions and to illustrate their use within a main program.

Lab Exercises

  1. Create a lab13 directory. Place copies of the AshOS files and the function library file funlib.asm in this directory. In the course of completing the lab, you will add lab13a.asm, lab13b.asm and lab13c.asm to this directory.
  2. Add a new function, swap, to your library of functions. In the C language, this function has the following prototype:

void swap(int* px, int* py);

Each of the two parameters is a pointer to an int variable. The return type, void, indicates there is no value computed by this function. In machine terms, each parameter is a memory address. As shown in the diagram below, we want the swap function to interchange the values of the corresponding words of memory.

py

px

py

px (^) α

β

β

α

y

x

y

x

Before invoking swap After invoking swap

Follow all the conventions for passing parameters and using stack frames that were established for Labs 11 and 12.

  1. Create a test driver program, lab13a.asm, which illustrates the use of the swap function. In this program, create four words of memory, initialized as follows:

a: .fill 10 b: .fill 20 c: .fill 30 d: .fill 40

Your program should invoke swap twice: once for the pair a and b and a second time for c and d.

  1. Add a new function, sort3, to funlib.asm which will rearrange three words of memory so they are in order, from smallest to largest. A C language prototype for this function is:

void sort3(int* px, int* py, int* pz);

This function should make pairwise comparisons and perform swaps as necessary. Your code must make use of the swap function.

Mathematics 3670: Lab 13 2

  1. Create a test driver program, lab13b.asm, which illustrates the use of the sort3 function. Introduce six named words of memory and supply code to sort the first three and the last three. Seeing your function work on two independent sets of variables will provide some confidence that sort3 is using the parameters correctly.
  2. Add a new function, sort, to funlib.asm which will rearrange an array of values. This function should have two parameters: one which gives the address of the base element of the array, and a second which gives the size of the array to be sorted. Use the selection sort algorithm from Lab 9. Your sort function must make use of the swap function to swap pairs of elements within the array.
  3. Create a test driver program, lab13c.asm which illustrates the use of the sort function. Introduce two arrays: one with 8 values and a second with 15 values. Introduce code which will invoke the sort function on each of these two arrays.

Submissions

  • Create a tar archive file consisting of the lab13 directory:

cd ~/ tar -cvf lab13.tar lab

  • Submit your work:

submit lab13.tar mat