# 这是一篇来自美国的关于计在链表上实现一个快速排序算法的编程代写

1 Project Description

The goal of the project is to write a program that implements a quick sorting algorithm on a linked list in the LEGv8 assembly language. Overall, the program will import an array of data and create a singly linked list based on its values. Then the array will be printed in its unsorted state, after which the array will be sorted and reprinted in ascending order. You must use project starter code.s provided in the course canvas as the template file. Notice the implementation of our code is a bit different from normal quick sort. Hence, the runtime of our implementation isn’t nlogn. The reason is to let you practice writing the assembly of double recursive functions. Your goal is to translate C code in the following pages to LEGv8 assembly.

Figure 1: Singly-linked list. Numbers entered by the user are: 12, 99, 37

Figure 2: Singly-linked list with a single node. The value at that node is 37 and the node pointer is null, i.e., it does not point to another node. In programming, a null pointer typically is one that is set to 0.

2 Quick Sort Algorithm Description

The overview of a quick sort algorithm is conceptually simple:

1. Get the end node of the input list. We will consider the value of this node the “pivot” value.
1. Partition the input list based on the pivot value so that nodes on the left side have values less than the pivot value and nodes to the right side have value greater or equal to the pivot value. The boundary between left and right is not in the middle. It is computed and retained for next steps.
1. Recursively call quick sort on the left and right sub-lists, respectively. Use the boundary computed in the previous step to distinguish left and right.
1. Return the now-sorted list to the calling function.

The recursive quick sort will keep dividing the sub-list until the sub-list holds a single element. A single element sub-list (the base case) is inherently sorted. It is highly recommended that you read over the description of a quick sort on quick sort on Wikipedia (it’s a very good overview), and graphical view of the sort at: www.sorting-algorithms.com/quick-sort.

Your project must use the provided template file. While you are free to add any further helper functions, your code must implement the following functions according to specification given below.

Interoperability. The grader should be able to remove any of these functions (and any nonessential helper functions it may use) from your code and use it in another person’s programming assignment without issue (i.e. do not change the register names passed to functions).

3 Implementation

In this project, you have to write six functions, namely SwapNodeValue, GetLastNode,GetNodeWithVal, Parition, QuickSort, and QuickSortWrapper to implement the quick sort algorithm in the LEGv8 assembly language. Some details to note:

• Use the procedures prototype as mentioned below and given to you in the template. Don’t change the registers or the arguments passed to the procedures or the values returned.
• Follow the “Procedure Call Convention” for calling procedures, passing registers and managing the stack. The procedures should not make any assumptions about the implementation of other procedures, except for the name of input/output registers (as indicated below) and the conventions mentioned in the course. A code that works correctly but does not follow conventions will be penalized.
• We expect your code to be well-commented. Each instruction should be commented with a meaningful description of the operation. For example, this comment is bad as it tells you nothing:

// x1 gets x2 – 1

sub x1, x2, #1

A good comment should explain the meaning behind the instruction. A better example would be:

// Initialize loop counter x1 to n-1

sub x1, x2, #1

In this project we use the following c-like structure to implement linked-list nodes:

struct Node {

__int64 data; // the numeric value held in this node

Node* next; // address of the next node (0 for NULL)

};

In the following pesudo-codes, we will also use some c-like notations.

For a node with memory address p:

• pdata: The integer value stored in memory address p
• pnext: The memory address of the next element stored in memory address p+8

In other words, if p is stored in x0, then you can get pvalue in x11 and pnext in x12 using the following instructions:

LDUR x11, [x0, #0]

LDUR x12, [x0, #8]

E-mail: itcsdx@outlook.com  微信:itcsdx