1. Engineering
  2. Computer Science
  3. assmbly language the objectives of this program is to understand...

Question: assmbly language the objectives of this program is to understand...

Question details

Assmbly Language

The objectives of this program is to understand dynamic arrays, stacks and subprogram calling another subprogram (function calls that are more than one level deep).

create_array will have no arguments IN and two arguments OUT:

$sp+0 - array base address (OUT)
$sp+4 - array length (OUT)

create_array will call subprogram allocate_array to dynamically allocate array. Then it will call read_array to fill the array. Lastly, create_array will return base address and array size back to the main.

allocate_array will have no arguments IN and two arguments OUT:

$sp+0 - array base address (OUT)

$sp+4 - array length (OUT)

allocate_array will ask the user for the size of the array and will validate that it is between 5 (exclusive) and 10 (inclusive) elements or (5, 10]. If an invalid length is entered, allocate_array will print an error message and reprompt the user for the length. When a valid length is entered, allocate_array will dynamically allocate exactly enough memory to hold the array, and then return base address and array size back to create_array subprogram.

read_array will have two arguments IN and no arguments OUT:

$sp+0 - array base address (IN)

$sp+4 - array length (IN)

read_array will read values from the user and store them in the array until the array is full. A prompt must be printed before each entry is read (e.g. “Enter an integer: “).

print_array will have two arguments IN and no arguments OUT:

$sp+0 - array length (IN)

$sp+4 - array base address (IN)

print_array will print all values from the array with each value separated by a space.

print_every_nth will have three arguments IN and no arguments OUT:

$sp+0 - array base address (IN)

$sp+4 - array length (IN)

$sp+8 - element stride N (IN)

print_every_nth will print every nth value from the array, starting from the first value (index 0). For example, consider the array [1 2 3 4 5 6 7 8 9 0].

For N = 3, the output would be [1 4 7 0].

For N = 4, the output would be [1 5 9].

If N ≤ 0, the subprogram must print an error and return without printing anything.

sum_odd_values will have two arguments IN and one argument OUT:

$sp+0 - array base address (IN)
$sp+4 - array length (IN)
$sp+8 - sum of odd values (OUT)


sum_odd_values will calculate the sum of all odd values in the array and return that sum. For example: given the array [8 4 3 6 5 5 2 8 7 2], the sum would be 30. sum_odd_values MAY NOT print anything (main must print the sum).

reverse_array will have two arguments IN and one argument OUT:

$sp+0 - array base address (IN)
$sp+4 - array length (IN)

$sp+8 - array base address of reversed array (OUT)

reverse_array will dynamically allocate an array with the same size as original array. Then copies values from original array into reversed array. Lastly, it will return array base address of reversed array back to main. Remember the size of reverse array is the same as size of original array so there is no need to return it back to main.

pseudocode:

revered array [0] = original array [size -1]

revered array [1] = original array [size -2]

revered array [size - 1] = original array [0]

Array: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]

Reversed array: [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution