CS130: Computer Architecture PJ 8 Dr. Lin Version 9/24/21 CS225 Fundamentals of

CS130: Computer Architecture PJ 8 Dr. Lin Version 9/24/21

CS225 Fundamentals of Computer Science Course Syllabus Fall 2013

Dr. Simon Lin Version: 09/02/2013

PJ 8 – Array and Average

Please follow the instructions to complete this project assignment.

(1) Go to Internet: http://www.jblearning.com/catalog/9781284036121/

(2) Click Sample Materials in the middle of the panel.

(3) Click Visual Studio 2015 Files to download VS_2015_Introduction_files.zip into your Downloads folder.

(4) Create a new folder Visual Studio Detmer in your USB drive.

(5) Click to open VS_2015_Introduction_files.zip (in your Downloads folder) to see all the contents. Copy all those folders and files (under the zip folder) into your USB drive folder: Visual Studio Detmer.

(6) Open your Visual Studio 2019. In Visual Studio, click File Open Project/Solution, and open your USB drive folder: Visual Studio Detmer. Double-click its sub-folder Windows32, and click windows32.sln, and click Open button. Now, you are running this windows32 application.

(7) Double-click the file example.asm (in Solution Explorer) to show its contents on the center panel.

(8) Right-click the file example.asm, and rename it to PJ8.asm.

(9) Modify PJ8.asm program as follows:

[a] The top 3 lines must be block comments to show Author, Date, and Purpose.

[b] Remove those blank lines from this program so that the complete program can be displayed on the

center panel. It may have only 32 lines or less now.

[c] This windows32 application will allow only one procedure with the name _MainProc. To run this

program, you need to use the name _MainProc for PROC, and use different PROC names for any

other assembly programs in this windows32 application. Please note that you may create many

assembly programs here (for testing), but only one of them with PROC being _MainProc can run.

Another way to solve this problem is to modify framework.c program so that this driver program

will call your proc (such as PJ8, instead of MainProc) directly.

(10) Write your PJ8.asm program as follows:

[a] create an array of 6 integers with initial values 25, 47, 15, 50, 32, 95 ;

[b] compute the average of those 6 integers;

[c] display the average to the user;

[d] add 10 to each number that is smaller than the average;

[e] display all the numbers in the array to the user one by one.

Note 1: The original example.asm program shows you how to prompt input from the user and how to display the result to the user using message boxes. There is no input from the user for PJ8.asm program.

Note 2: The average of those 6 numbers should be 44. After adding 10 to each number that is less than 44, the array should have 35, 47, 25, 50, 42, and 95.

(11) Fully test this program at least 3 times to make sure it runs successfully with no errors or warnings.

(12) Copy and paste your complete PJ8.asm program into section (A) below.

(13) Build Rebuild Windows32 application. Click Local Windows Debugger to run this program.

(14) Make a screen print (by Ctrl+Alt+PrintScrn) and paste (Ctrl+V) it onto section (B) below.

(15) Show all the 7 message boxes onto section (C) accordingly in sequence.

==========================================================================.

The following is the assembly code to process an array using indexed addressing: (reference page 159-161)

; Given an array of doubleword integers, (1) find the average of those integers, and

; (2) add 10 to each number that is smaller than the average [using indexed addressing].

.586

.MODEL FLAT

.STACK 4096

.DATA

nbrArray DWORD 25, 47, 15, 50, 32, 95, 6 DUP (?) ; // Total 6 integers + 6 more uninitialized integers

nbrElts DWORD 6 ; // 6 elements to be processed even though nbrArray has 12 elements.

.CODE

_MainProc PROC ; begin of procedure

; find sum and average

mov eax,0 ; Accumulator ; eax := 0

mov ecx,0 ; Count index ; ecx := 0

for1: cmp ecx,nbrElts ; count_index < nbrElts

jnl endFor1 ; exit if not ; 4 bytes per number

add eax, nbrArray[4*ecx] ; add number to eax, which is sum_accumulator

inc ecx ; increment index by 1

jmp for1 ; repeat for1 loop

endFor1: ; Now, eax contains the sum of all numbers

cdq ; extend the sum in eax to quadword ; convert Dword to Qword

idiv nbrElts ; calculate average: divide eax by number of elements; eax = eax / nbrElts

; add 10 to each array element that is below average

mov ecx,0 ; count_index := 0

for2: cmp ecx,nbrElts ; count_index < nbrElts

jnl endFor2 ; exit if not

cmp nbrArray[4*ecx], eax ; number < average ? ; eax has the average

jnl endIfSmall ; continue if not less

add DWORD PTR nbrArray[4*ecx], 10 ; add 10 to number at ecx

endIfSmall:

inc ecx ; increment index

jmp for2 ; repeat for2 loop

endFor2:

quit: mov eax, 0 ; exit with return code 0

ret ; return to the caller

_MainProc ENDP ; end of procedure

END ; end of program

==========================================================================.

How to submit your PJ 8?

You must copy/paste (or Ctrl+Alt+PrintScrn/paste) your programs/screens to all the sections below.

Submit this document for this project through the Canvas system (https://ilearn.laccd.edu ).

==========================================================================.

//You must delete everything above & including this line to make this your Word document to be submitted.

CS130 PJ 8 Report My Name:____________________

(A) The following is my source program: PJ8.asm. You must copy/paste your source code from your Visual Studio. As you may see, the font of the program in Visual Studio is Consolas, not Courier New or Times New Roman. You must not show screen prints here.

(B) The following is the screen print of my Visual Studio Console after the program PJ8.asm has been run successfully with return code 0: (You must Ctrl+Alt+PrintScrn your Visual Studio Console, and then paste it to here.)

(C) The following is the screen prints of all the output displays after the program PJ8.asm has been run successfully with return code 0: (You must Ctrl+Alt+PrintScrn your Visual Studio Console, and then paste it to here.)

C.1 Show the average:

C.2 Show the 1st number:

C.3 Show the 2nd number:

C.4 Show the 3rd number:

C.5 Show the 4th number:

C.6 Show the 5th number:

C.7 Show the 6th number:

Page 2 of 3

Page 1 of 3