Quiz 11: User Friendly Assembler Program for Computing the Factorial
Write an assembly program factorial.s where a user is first asked to type in some unsigned integer \(n\), then prints the value of \(n\) followed by the string “! = ” (characters: '!', space, '=', space) and then prints the value of \(n!\) followed by a newline. So an example run could look as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | theon$ 1_ulm_build/func/ulm a.out
n = 0
0! = 1
theon$ 1_ulm_build/func/ulm a.out
n = 1
1! = 1
theon$ 1_ulm_build/func/ulm a.out
n = 2
2! = 2
theon$ 1_ulm_build/func/ulm a.out
n = 3
3! = 6
theon$ 1_ulm_build/func/ulm a.out
n = 4
4! = 24
theon$ 1_ulm_build/func/ulm a.out
n = 5
5! = 120
theon$ 1_ulm_build/func/ulm a.out
n = 6
6! = 720
theon$ 1_ulm_build/func/ulm a.out
n = 7
7! = 5040
theon$ 1_ulm_build/func/ulm a.out
n = 15
15! = 1307674368000
|
Submit your program and the used isa.txt with submit hpc quiz11 isa.txt factorial.s
How Submit Checks Results
Submit will use shell command to get results computed by your program. It therefore uses the echo connected by a pipe with your program. Try this with your program yourself:
theon$ echo 5 | 1_ulm_build/func/ulm a.out n = 5! = 120 theon$
So the output that you see does not contain the user input. It only contains what your program prints, i.e.
-
the string “n = ” (without a newline),
-
the value of \(n\),
-
the string “! = ” (without a newline),
-
the value of \(n!\),
In addition it will write the output of your program into a file, like this:
theon$ echo 5 | 1_ulm_build/func/ulm a.out > res theon$
It will then compare with diff whether res contains what we expect by comparing it with some solution file sol.
So obviously file res here contains
n = 5! = 120
and this is identical with the content of sol. But let's assume res would have this content (where a space is missing now):
1 | n = 5! =120
|
Then with diff we get
theon$ diff res_ups sol 1c1 < n = 5! =120 --- > n = 5! = 120 theon$
and this will also show up in the error report.