Practice Question 1
Write assembly code (NOT a complete program) that: assuming that r1 holds a positive integer, prints out whether that integer is even or odd. If r1 holds a value that is even, your program should print "even", otherwise it should print "odd". For example, when your code is placed at the indicated position, the program below should print "odd".
.globl _start
_start:
mov r1, #17
@@@ Place your code here.
Hint: you can divide by two using the lsr instruction (logical shift right).
Practice Question 2
Write assembly code (NOT a complete program) that: assuming that r1 holds an ASCII code of a lowercase letter, prints out whether that letter is a vowel or a consonant. If it is a vowel, your program should print "vowel", otherwise it should print "constant". If the value of r1 is less than 97 or greater than 122, your code should print "out of range".
For example, when your code is placed at the indicated position, the program below should print "vowel".
.globl _start
_start:
mov r1, #'e'
@@@ Place your code here.
Tip: note that you can use an ASCII code as a constant in ARM-7 assembly, by placing the corresponding character in quotes. See the example above: mov r1, #'e'.
Practice Question 3
Write assembly code that: assuming that r1 holds a positive integer between 0 and 1000, determines if that integer is a multiple of 10, and prints "*10" if so and "no" otherwise. If the value of r1 is less than zero or greater than 1000, your code should print "out of range". Your code can use the mul instruction, but it is not allowed to use any division instruction (since division is not supported in our assembly environment).
For example, when you place your code as indicated in the program below, the output should be "*10".
.globl _start
_start:
mov r1, #170
@@@ Place your code here.
Hint: If r1 is a multiple of 10, then you can find an integer X such that r1 = X * 10. You can find this X by brute force, by trying all numbers less than r1.
Practice Question 4
Write assembly code that: assuming that r1 holds a positive integer between 0 and 20, prints out a square using '-' characters to draw the horizontal sides, and using '|' characters to draw the vertical sides. The number of characters used for each side should be equal to the value of r1. If the value of r1 is less than zero or greater than 20, your code should print "out of range". For example, a square of size 5 can be drawn as:
-----
| |
| |
| |
| |
| |
-----
When you place your code as indicated in the program below, the output should the square of size 5 shown above.
.globl _start
_start:
mov r1, #5
@@@ Place your code here.
Practice Question 5
Write assembly code that: assuming that r1 holds a positive integer between 0 and 1000, prints out the sum of all integers between 0 and the value of r1, in hexadecimal. If the value of r1 is less than zero or greater than 1000, your code should print "out of range".
For example, when you place your code as indicated in the program below, the output should be "37" (hex for 55).
.globl _start
_start:
mov r1, #10
@@@ Place your code here.
Hint: If r1 is a multiple of 10, then you can find an integer X such that r1 = X * 10. You can find this X by brute force, by trying all numbers less than r1.
(Challenge) Practice Question 6
Write assembly code that: assuming that r1 holds a positive integer, determines if that integer is a multiple of 10, and prints "*10" if so and "no" otherwise. Your code should work even for large integers (over 1 billion). Your code can use the mul instruction, but it is not allowed to use any division instruction (since division is not supported in our assembly environment).
For example, when you place your code as indicated in the program below, the output should be "*10".
.globl _start
_start:
mov r1, #170
@@@ Place your code here.
Hints:
(Challenge) Practice Question 7
Write assembly code that: assuming that r1 holds a positive integer, determines if that integer is a prime number, and prints "p" if so and "np" otherwise. Your code can use the mul instruction, but it is not allowed to use any division instruction (since division is not supported in our assembly environment).
For example, when you place your code as indicated in the program below, the output should be "p".
.globl _start
_start:
mov r1, #17
@@@ Place your code here.
The hints given in Practice Exercise 6 are also relevant here, but harder to apply. Still, you should be able to have a solution that works reasonably fast when r1 has a value not greater than 1000, or perhaps 10000.
Back to the list of assignments.