Sei sulla pagina 1di 3

Introduction to Computing

Programming Assignment 2
Fall 2012 Due: Tuesday, 30th October 2012, 11:59 pm You must do the programming assignment by yourself. You are permitted to get help from ONLY the TAs and the instructor. The file you submit should be an assembly language file called stats.asm. This is the only file you need to submit. Objective: Sort and report statistics on a list of numbers. The tasks your program has to perform are: Sort the list of numbers in place Report the range, defined as the difference between the largest and smallest number by writing it to a predefined location Report the median, defined as that element in the list that has equal number of elements above and below it. Your LC3 program should sort an array of 15 numbers (stored in memory). You may assume that the first number of the array is stored in memory location x3100 and the last number of the array is stored in memory location x310E. Each memory location contains a single number (a score). Your program should sort the array of numbers in increasing order and store the sorted result back in memory locations x3100 through x310E. Your program should start at memory location x3000. You may assume that the numbers are in the range 0 and +100. That is, the smallest number you can encounter is -0 and the largest is 100. It is possible that there are multiple instances of the same number (duplicates). The range has to written to memory location x310F and the median has to be written to location x3110. Example: Memory locations x3100 through x3110 before sorting: Location x3100 x3101 x3102 x3103 x3104 x3105 x3106 x3107 x3108 x3109 x310A x310B Contents (decimal) 76 72 52 84 95 65 76 75 90 83 50 89

x310C x310D x310E x310F x3110

91 75 82 0 0

Memory locations x3100 through x3110 after sorting: Location x3100 x3101 x3102 x3103 x3104 x3105 x3106 x3107 x3108 x3109 x310A x310B x310C x310D x310E x310F x3110 Contents (decimal) 50 52 65 72 75 75 76 76 82 83 84 89 90 91 95 45 76

Hint 1: How would you find the smallest number in the unsorted array? Hint 2: If you swap the smallest number in the array with the first number in the array (i.e., the number in memory location x3100), you now have a 14-number array to sort (starting from memory location x3101). Hint 2: What positions will you find the smallest, largest and median elements at in the sorted array? Initial Values: Your program should assume that there are already values stored in memory locations x3100 through x310E. When testing your program with the LC-3 simulator, you should manually load test values into these memory locations before running your program. You can click on "Simulate" in menubar and select "Set Value". Alternatively, you can just press F4 and the "Set Value" dialog box will pop up. Labels: You are welcome to use labels in this programming assignment. Make sure your labels are named sensibly.

Notes: The first line of your program must specify the memory address of the first instruction of your program. The LC-3 simulator will place your program starting at that address. For this assignment, you should place your program starting at x3000 (i.e. the first line of your program should be .ORIG x3000). The file that you will submit for this assignment must be named stat.asm. The TAs will show you how to store your 15-element array in another file called data.asm and use it rather than typing all 15 numbers every time you want to test your code. You will however not turn in this file.

Potrebbero piacerti anche