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

Selection Sort Algorithm - Intro to Computer Architecture - Homework, Exercises of Computer Architecture and Organization

In the course of intro to computer architecture, the main points are:Selection Sort Algorithm, Array Numbers, Unconditional Branches, Language Statements, Ascending Order, Six-Stage Pipeline, Target Addresses, Data Hazards, Total Branch Penalty, Branch-History Table, Machinelanguage

Typology: Exercises

2012/2013

Uploaded on 05/06/2013

anurati
anurati 🇮🇳

4.1

(23)

128 documents

1 / 1

Toggle sidebar

Related documents


Partial preview of the text

Download Selection Sort Algorithm - Intro to Computer Architecture - Homework and more Exercises Computer Architecture and Organization in PDF only on Docsity! Computer Architecture HW #3 1. Consider the following selection sort algorithm that sorts an array numbers: SelectionSort(int length; int numbers[ ]) int firstUnsortedIndex, testIndex, smallestIndex, temp for firstUnsortedIndex = 0 to (length-2) do smallestIndex = firstUnsortedIndex for testIndex = firstUnsortedIndex + 1 to length - 1 do if numbers[ testIndex ] < numbers[ smallestIndex ] then smallestIndex = testIndex end if end for temp = numbers[ firstUnsortedIndex ] numbers [ firstUnsortedIndex ] = numbers [ smallestIndex ] numbers [ smallestIndex ] = temp end for end SelectionSort a) Where in the code would unconditional branches be used and where would conditional branches be used? b) If the compiler could predict by opcode for the conditional branches (i.e., select whether to use machine language statements like: “BRANCH_LE_PREDICT_NOT_TAKEN” or “BRANCH_LE_PREDICT_TAKEN"), then which conditional branches would be "PREDICT_NOT_TAKEN" and which would be "PREDICT_TAKEN"? c) Assumptions:  length = 100 and the numbers are initially in ascending order before the selection sort algorithm is called  the six-stage pipeline of the text  the outcome of conditional branches is known at the end of the EI stage  target addresses of all branches is known at the end of the CO stage  ignore any data hazards Under the above assumptions, answer the following questions: i) If static predict-never-taken is used by the hardware, then what will be the total branch penalty (# cycles wasted) for the algorithm? (Here assume NO branch-history table) For partial credit, explain your answer. ii) If a branch-history table with one history bit per entry is used, then what will be the total branch penalty (# cycles wasted) for the algorithm? (Assume predict-not taken is used if there is no match in the branch-history table) For partial credit, explain your answer. iii) If a branch-history table with two history bits per entry is used as in Figure 11.16, then what will be the total branch penalty (# cycles wasted) for the algorithm? (Assume predict-not taken is used if there is no match in the branch-history table) For partial credit, explain your answer. Docsity.com
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved