Вы находитесь на странице: 1из 2

Exercise: 5

5.1 Assignments with operands in memory


Assume an array of 5 words. A compiler associates variables x and y with registers r0 and r1, respectively. Assume
that the base address for the array is located in r2. Compute the value for X.
x = array [5] + y

5.2 Loads and stores


Assume an array of 5 words. A compiler associates y with r1. Assume that the base address for the array is located
in r2. Compute the value for array[6]th element.
array [6] = array[3] + y

5.3 Array assignment


Write ARM assembly to perform the following array assignment in C:
for ( i = 0; i <= 10; i++)
{
a[i] = b[i] + c;
}

Assume that r3 contains i, r4 contains c, the starting address of array a is in r1, and the starting address of array b is
in r2.

Exercise: 6

6.1 Arrays and pointers


Consider the following two C procedures that initialize an array to zero using a) indices, and b) pointers:
a) init_Indices (int a[], int s) {
int i;
for ( i = 0; i < s; i ++) Convert these two procedures to ARM assembly.
a[i] = 0; }
b) init_Pointers (int *a, int s) {
Put the starting address of the array in r1, s in r2,
int *p; and i and p in r3. Assume that s > 0
for (p = &array[0]; p < &array[s]; p++)
*p = 0; }

6.2 The Fibonacci sequence


The Fibonacci sequence is an infinite sequence of numbers that begins with 0 and 1, and each of the remaining
numbers is the sum of the previous two numbers. Write an ARM assembly program that computes the first 12
numbers of the sequence and stores the sequence in memory locations 0x4000 to 0x400B.

6.3 The nth Fibonacci number


Use The Fibonacci sequence exercise program and write ARM assembly to compute f(n). Start with r1 = n. At the
end of the program, r0 = f(n)

Exercise: 7
7.1 Factorial calculation
To take advantage of the idea of conditional execution, examine the algorithm for computing n!, where n is an
integer. For a given value of n, the algorithm iteratively multiplies a current product by a number that is one less
than the number it used in the previous multiplication. The code continues to loop until it is no longer necessary to
perform a multiplication, first by subtracting one from the next multiplier value and stopping when it is equal to
zero.
7.2 Find maximum value
In this exercise, find the largest integer in a series of 32-bit unsigned integers. The length of the series is determined
by the value in register r5. The maximum value is stored in the memory location 0x5000 at the end of the routine.
The data values begin at memory location 0x5006. Choose 11 or more integers to use. Use as much conditional
execution as possible when writing the code

7.3 Sequential parity checker


Write ARM assembly to inspect the parity of a value initially held in r0. If r0 has an odd number of ones, the
program ends with 0x0001 in r1. If r0 has an even number of ones, the program ends with 0x0000 in r1.

Вам также может понравиться