Difference between revisions of "CSC231 Homework 4 Fall 2017"
(→Problem 2) |
(→Problem 3) |
||
Line 63: | Line 63: | ||
=Problem 3= | =Problem 3= | ||
<br /> | <br /> | ||
+ | Write a series of bash commands that will print four triangles of 10 lines made of the '*', '2', '3', and '1' characters, as shown below: | ||
+ | |||
+ | ::<source lang="text"> | ||
+ | 2 | ||
+ | 22 | ||
+ | 222 | ||
+ | 2222 | ||
+ | 22222 | ||
+ | 222222 | ||
+ | 2222222 | ||
+ | 22222222 | ||
+ | 222222222 | ||
+ | 2222222222 | ||
+ | |||
+ | 3 | ||
+ | 33 | ||
+ | 333 | ||
+ | 3333 | ||
+ | 33333 | ||
+ | 333333 | ||
+ | 3333333 | ||
+ | 33333333 | ||
+ | 333333333 | ||
+ | 3333333333 | ||
+ | |||
+ | 1 | ||
+ | 11 | ||
+ | 111 | ||
+ | 1111 | ||
+ | 11111 | ||
+ | 111111 | ||
+ | 1111111 | ||
+ | 11111111 | ||
+ | 111111111 | ||
+ | 1111111111 | ||
+ | |||
+ | a | ||
+ | aa | ||
+ | aaa | ||
+ | aaaa | ||
+ | aaaaa | ||
+ | aaaaaa | ||
+ | aaaaaaa | ||
+ | aaaaaaaa | ||
+ | aaaaaaaaa | ||
+ | aaaaaaaaaa | ||
+ | |||
+ | </source> |
Revision as of 15:21, 13 October 2017
--D. Thiebaut (talk) 15:15, 13 October 2017 (EDT)
Contents
Problem 1
Write an assembly language program called hw4a.asm that translate a decimal unsigned integer into its octal equivalent.
Here is an example of how it should behave:
cs231a@aurora ~/ $ nasm -f elf hw4a.asm cs231a@aurora ~/ $ ld -melf_i386 hw4a.o 231Lib.o -o hw4a cs231a@aurora ~/ $ ./hw4a > 12345 0...030071
I used ellipsis in the output above to mask the number of leading 0s actually output by the program. It's part of your assignment to figure this out. Be resourceful!
Details
- Your program must be linked with the 231Lib.asm library
- Your program will print a prompt ( "> " ) first, then the user enters a positive number (it will never be negative)
- Your program gets the input using the _getInput() function in the 231Lib.asm library
- Your program outputs the octal equivalent, padded with leading 0s.
Submission
Submit your program on Moodle. Make sure you test it well before submitting it. In particular, if you add comments to your program just before submitting it, you should assemble, link and run it at least once to make sure you didn't change the logic of your program by adding comments.
Problem 2
Your assignment is to write an assembly program named hw4b.asm that can be used to decipher a secret message.
Your program will read a 32-bit unsigned integer from the user, decipher it (explained shortly), and print the corresponding string. For example:
./hw4b > 1094861636 ABCD
In hexadecimal, 1094861636 is 0x41424344, where you will recognize 41 as the hexadecimal ascii for 'A', 42 the ascii for 'B', 43 the ascii for 'C', and 44 the ascii for 'D'. Hence the output "ABCD."
Note that the program outputs a line-feed after the string.
Another example:
./hw4b > 1131376492 Cool
Implementation Details
- Your program should be linked against the 231Lib library.
- Your program must output a line-feed at the end of the 4-character message.
Submission
- Submit your program on Moodle, in the Homework 4, Problem 2 section.
Problem 3
Write a series of bash commands that will print four triangles of 10 lines made of the '*', '2', '3', and '1' characters, as shown below:
2 22 222 2222 22222 222222 2222222 22222222 222222222 2222222222 3 33 333 3333 33333 333333 3333333 33333333 333333333 3333333333 1 11 111 1111 11111 111111 1111111 11111111 111111111 1111111111 a aa aaa aaaa aaaaa aaaaaa aaaaaaa aaaaaaaa aaaaaaaaa aaaaaaaaaa