Average of 4 Exercise
To get experience writing ARM assembly code for the GBA using arithmetic and shift operations.
For this lab, you will write an ARM assembly function to calculate the average of four parameter
values. Your function will take 4 integers as parameters (the most that can be passed solely using
registers), and compute the average value of them.
When the program works, it should return the correct value for the average of those
four numbers which is 130.
- Start by downloading a GBA skeleton program with an empty average4 function:
tar xvf average4.tar.gz
- Compile the program so that you can see you have everything set up correctly:
gbacc average4.s main.c
- Run the program.gba program this creates. It should print that the average is
160. This is because the first value, 160, is passed in as r0 which is also used
as the return value. Since the function does nothing, the first parameter is used
as a return value.
- Edit the average4 function in average4.s so that it computes the average of the
four parameter values. Remember that there is no division instruction on the GBA!
How else could we divide by 4?
When you are done, please submit the assembly code under the assignment in
Ian Finlayson | Licensed under a Attribution-NonCommercial 4.0 International License.