You are on page 1of 2

5.

REVISION AND EXERCISES

5.1 Exercises
5.1.1 Exercise 1
Requirement. Write a subprogram that receives as input parameters two unsigned 16-bit
numbers (sent through the stack) and returns their maximum (in AX). Exemplify the usage of
this subprogram in a program which compares three unsigned 16-bit numbers (defined in the
program as word variables, and called alpha, beta and gamma) with the final goal of finding their
maximum.
Hint. The main program should call the subprogram twice: first it will compare the numbers
alpha i beta and then it will compare the maximum between alpha and beta with gamma.

5.1.2 Exercise 2
Requirement. Write a subprogram that receives as input parameters four unsigned 16-bit
numbers (sent through the stack) and returns the result of the following arithmetic function (in
DX concatenated with AX):
(parameter1 parameter2) * (parameter3 parameter4)
Exemplify the usage of this subprogram in a program which calls it once, sending as input
parameters any four numbers and stores the result in the memory in a variable called result.

5.1.3 Exercise 3
Requirement. Write a subprogram that receives as input parameters four unsigned 8-bit
numbers (sent through the stack) and returns the result of the following logic function (in AX):
NOT ((parameter1 << 2 XOR parameter2) AND (parameter3 << 2 XOR parameter4))
Exemplify the usage of this subprogram in a program which calls it once, sending as input
parameters any four numbers and stores the result in the memory in a variable called result.
Note. XOR, AND, NOT are the regular logic operators and <<, >> are the shift left and shift right
operators.

5.1.4 Exercise 4
Requirement. Write a subprogram that receives as input parameters the start address and the
number of elements in an array of unsigned 16-bit numbers and returns the sum of the
elements (in DX concatenated with AX). Exemplify the usage of this subprogram in a program
which calls it once.
Note. You must use two 16-bit registers to sum the elements of the array because the result
might be a number which cannot be stored on 16 bits.

5.1.5 Exercise 5
Requirement. Write a subprogram that receives as input parameters the start address and the
number of elements in an array of letters and returns the number of uppercase letters (in DX).
Exemplify the usage of this subprogram in a program which calls it once.
Note. In this program you are required to use the string instruction lods to copy the current
element from the array to the accumulator.
Hint. The subprogram should verify if the current element in the array is a capital letter by
comparing its ASCII code with the ASCII codes of A and Z.

5.1.6 Exercise 6
Requirement. Write a subprogram that receives as input parameters the start address and the
number of elements in an array of letters (further called source string) and the start address of a
second array (further called destination string). The subprogram should copy all the lowercase
letters from the source string to the destination string and return (in DX) the number of copied
letters. Exemplify the usage of this subprogram in a program which calls it once.
Note. In this program you are required to use the string instructions lods and stos.
Hint. The subprogram should verify if the current element in the array is a lowercase letter by
comparing its ASCII code with the ASCII codes of a and z.

You might also like