ICS312 - Spring 2009 - Homework #3 -

Work alone
You are expected to do your own work on all homework assignments. You may (and are encouraged to) engage in general discussions with your classmates regarding the assignments, but specific details of a solution, including the solution itself, must always be your own work. (See the statement of Academic Dishonesty on the course's syllabus.)

What to turn in?
Turn it you NASM file and a text file with your answers to Question #2 via a single e-mail to henric@hawaii.edu with a subject line like "ICS312: HW#3" before midnight on the day the assignment is due.


Exercise #1: Your First Program [30pts]

Write an assembly program called hw3_ex1, stored in file hw3_ex1.asm, that prompts the user to type a 5-character string. The program reads the first 5 characters of that string and prints two strings. The first string contains the 5 characters entered by the user, but in reverse order. The second string contains the 5 characters entered by the user, but whose ASCII code has been decremented by 32. Match the example shown below, where user input is shown in bold face:

% ./hw3_ex1
Enter a 5-character string: hguot
String #1: tough
String #2: HGUOT
You may assume that the user will always type exactly 5 characters followed by a carriage return (no need to deal with errors, etc.).

Reading a character from the keyboard is done via the read_char macro (see page 17 of the textbook for a description). So you'll have to call this macro 5 times to get the 5 characters.

Remember that when you print a string it should be null-terminated. So, to store a 5-character string that you will print you need to store it in 6 bytes, with the last byte equal to 0.

Exercise #2: Overflow [20 pts]

For each of the following hex operation say whether the carry bit is set and whether the overflow bit is set. Also, for each operation, if the result were sign-extended into the EAX register, say what print_int would print? (Remember that this macro prints signed numbers in decimal representation).

  1. 2-byte quantities: 8FF0 + A026
  2. 2-byte quantities: 6043 + 7ABC
  3. 1-byte quantities: F3 + 0D
  4. 1-byte quantities: E5 + 03

henric@hawaii.edu