
Board Used

Exercise 1: Greatest Common Divisor (GCD) : 

- Code: Select all
.text
.global _start
_start: MOV R0, #54 /* Register R0 is the first number. */
MOV R1, #24 /* Register R1 is the second number. */
GCD: CMP R0, R1 /* Set the condition codes by comparing the two numbers. */
SUBGT R0, R0, R1 /* If (R0 > R1) then R0 = R0 - R1. */
SUBLT R1, R1, R0 /* If (R0 < R1) then R1 = R1 - R0. */
BNE GCD /* If (R0 != R1) then loop again. */
STOP: B STOP /* If (R0 == R1) then stop. */
.end
Exercise 2: Dot product : 

- Code: Select all
.text
.global _start
_start: LDR R0, =AVECTOR /* Register R0 is a pointer to vector $A$. */
LDR R1, =BVECTOR /* Register R1 is a pointer to vector $B$. */
LDR R2, N /* Register R2 is used as the counter for loop iterations. */
MOV R3, #0 /* Register R3 is used to accumulate the product. */
LOOP: LDR R4, [R0], #4 /* Load the next element of vector $A$. */
LDR R5, [R1], #4 /* Load the next element of vector $B$. */
MLA R3, R4, R5, R3 /* Compute the product of next pair of elements, */
/* ~~and add to the sum. */
SUBS R2, R2, #1 /* Decrement the counter. */
BGT LOOP /* Loop again if not finished. */
STR R3, DOTP /* Store the result in memory. */
STOP: B STOP
N:
.word 6 /* Specify the number of elements. */
AVECTOR:
.word 5, 3, -6, 19, 8, 12 /* Specify the elements of vector A. */
BVECTOR:
.word 2, 14, -3, 2, -5, 36 /* Specify the elements of vector B. */
DOTP:
.space 4 /* Space for the final dot product. */
.end
Exercise 3: HPS Peripherals : The program will use the HPS pushbutton and LED


- Code: Select all
#define bit_25_pattern 0x02000000
/* This program provides a simple example of code for the ARM A9. The program
* loops indefinitely, reading the HPS pushbutton and setting the green light
* to match.
*/
int main(void)
{
/* Declare volatile pointers to I/O registers (volatile means that the
* locations will not be cached, even in registers) */
volatile int * HPS_GPIO1_Data = (int *) 0xFF709000;
volatile int * HPS_GPIO1_Direction = (int *) 0xFF709004;
volatile int * HPS_GPIO1_External = (int *) 0xFF709050;
*HPS_GPIO1_Direction = (1 << 24); // Set bit 24 (LEDG) of GPIO1
// to be an output
while(1)
{
int value = *HPS_GPIO1_External; // Read the value of the GPIO port
value &= bit_25_pattern; // Mask out the pushbutton value
*HPS_GPIO1_Data = (value >> 1); // Set the LEDG to the read value
}
}
Exercise 4: FPGA Peripherals : Circuit must be configured in the FPGA




- Code: Select all
/* This program provides a simple example of code for the ARM A9. The program
* loops indefinitely, reading the FPGA switches, setting the red LEDs
* to match and sets the seven segement display accordingly .
*/
int main(void)
{
/* Declare volatile pointers to I/O registers (volatile means that the
* locations will not be cached, even in registers) */
volatile int * LEDs = (int *) 0xFF200000; // Red LED address
volatile int * HEX3_HEX0 = (int *) 0xFF200020; // HEX3_HEX0 address
volatile int * SW_switch = (int *) 0xFF200040; // Slider switch address
int hex_conversions[16] = { 0x3F, 0x06, 0x5B, 0x4F,
0x66, 0x6D, 0x7D, 0x07,
0x7F, 0x67, 0x77, 0x7C,
0x39, 0x5E, 0x79, 0x71};
while(1)
{
int value = *SW_switch; // Read the value of the switches
*LEDs = value; // Set the LEDR to the read value
int first_digit = value & 0xF; // Get the first digit
int second_digit = (value >> 4) & 0xF; // Get the second digit
int third_digit = (value >> 8) & 0xF; // Get the third digit
int hex_value = hex_conversions[first_digit];
hex_value |= hex_conversions[second_digit] << 8;
hex_value |= hex_conversions[third_digit] << 16;
*HEX3_HEX0 = hex_value; // Set the LEDR to the read value
}
}
Exercise 5: Semihosting : 


