Exercises
The aim of the following two exercises is to code in assembler the pseudo-coded algorithms on the left. Organize the corresponding assembler instructions on the right in the correct order, by dragging them around.
Perform the following tasks (please remember that any label needs to be defined in the leftmost column of the RAM before it can be used in any instruction):
1) Describe the difference between numeric and direct addressing.
2) Describe the data transmitted on the data, address and control buses, respectively, during the execution of the instructions LOD #5, and LOD 5.
3) Identify the binary code of the assembler instruction MUL 5.
4) Identify the mnemonic instruction corresponding to the machine language instruction 00010011.
Develop suitable programs in assembly code, to solve the following problems:
1) Perform the addition, subtraction, multiplication and division of 2 numbers; if the operation is not commutative and the first number is smaller than the second one, reverse them.
2) Calculate the mean of 3 numbers.
3) Find the maximum and the minimum of 2 numbers.
4) Determine the parity (even or odd) of a number.
5) Sum the numbers from 1 to 5.
6) Calculate the factorial of a number.
7) Compute the result of the expression: Y= 3*X + 5, where X and Y are labels corresponding to memory addresses.
8) Compute the sum of the numbers from X to Y included, where X and Y are labels corresponding to memory adresses.
9) Compute the Greatest Common Divisor problem, using the "Euclid's Method".
10) Translate the following pseudo-code to assembler:
​
COUNT:=0; K:=5;
DO
K:=K+37;
COUNT:=COUNT+1;
WHILE K < 612
11) Determine how many bits are set (i.e. have value “1”) in a given byte.
Example: 87 = 0101 0111 -> 5
Hint: check the last bit, shift right the original number, repeat.
12) Translate the following pattern in pseudo-code to assembler:
​
FOR I:= 5 DOWNTO 0 DO {
// Body code here
}
// Additional code here
13) Translate the following pattern in pseudo-code to assembler:
IF <boolean expression>
THEN <statements>
ENDIF
<other statements>
14) Translate the following pattern in pseudo-code to assembler:
IF W<X
THEN
exchange W and X
ENDIF
15) Determine whether a given positive integer number satisfies the Collatz conjecture (see the definition at https://en.wikipedia.org/wiki/Collatz_conjecture), computing the number of iterations necessary to reach the number 1.
CC BY-NC-SA 4.0 Credits