Question: Exercise [Arrays ] Step 1: Create a new ASSEMBLY project using Keil Software Make sure you use the M3 option Make sure you name the

Exercise [Arrays ]

Step 1: Create a new ASSEMBLY project using Keil Software

Make sure you use the M3 option

Make sure you name the folder COSC2440_Lab06_YourFirstName_YourLastName

Step 2: Copy the following template to your assembly file:

AREA Lab_06_YourFirstName_YourLastName, CODE, READONLY

EXPORT __main

__main

MOV R0, SP ; Replace ___ with base register.

MOV R1, #1 ; R1 will be used to increment the loop.

MOV R2, #20; R2 will represent the number of iterations.

MOV R3, #0 ; R3 will be used to hold the sum of the array.

storeValuesLoop

STR R1, [R0], #4;Store the value of R1 to address of R0, then auto increment the address by 4. Hint use STR instruction.

ADD R1, #1; Increment the Loop by adding 1 to R1

CMP R1, R2; Compare R1 & R2 to determine if we need to exit the loop or not

BLE storeValuesLoop; Stay in the loop if R1 is less than or equal to R2

MOV R1, #1 ; Reset R1 to start from the beginning again for the 2nd loop.

MOV R0, SP;

readValuesLoop

LDR R4, [R0], #4;Read the value of current iteration to R4. Hint use LDR instruction.

ADD R3, R4 ; Add the value your read [R4] to the sum [R3]

ADD R1, #1; Increment the Loop by adding 1 to R1

CMP R1, R2; Compare R1 & R2 to determine if we need to exit the loop or not

BLE readValuesLoop; Stay in the loop if R1 is less than or equal to R2

stop B stop

END

Step 3:

Change YourFirstName to your first name.

Change YourLastName to your last name.

This is the same program that we used for Lab 05.

Step 4: Modify storeValuesLoop from using the STR-Post-indexed-autoindexing-post-incrementing to STR-Pre-indexed-autoindexing-pre-incrementing.

You are ONLY allowed to modify the highlighted line inside the storeValuesLoop loop.

Step 5: Modify readValuesLoop from using the LDR-Post-indexed-autoindexing-post-incrementing to LDR- indexed-Double Register with Scaling.

You are ONLY allowed to modify the highlighted line inside the readValuesLoop loop.

Step 6: You should have the same sum result as we had in (the pic below)

Exercise [Arrays ] Step 1: Create a new ASSEMBLY project using Keil

Value Register Core 0x20001058 0x00000015 0x00000014 0x000000D2 Ox00000014 RO 0 R4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!