Write an assembly program called hw4_ex1, stored in file hw4_ex1.asm, to implement a simple calculator for 1-byte unsigned values. The program prompts the user to enter 2 positive integers. The program should abort with an error message if either number is not encodable as a 1-byte value. The program then computes the sum of the two integers. If there is an overflow, the program should print an error message. Otherwise, the program should print the result. You may assume that the user will always type numbers.
Here are example interactions with the program:
% ./hw4_ex1
Enter a 1-byte unsigned number: 41
Enter a 1-byte unsigned number: 13
54
% ./hw4_ex1
Enter a 1-byte unsigned number: -12
Invalid number...
% ./hw4_ex1
Enter a 1-byte unsigned number: 12
Enter a 1-byte unsigned number: -82
Invalid number...
% ./hw4_ex1
Enter a 1-byte unsigned number: 257
Invalid number...
% ./hw4_ex1
Enter a 1-byte unsigned number: 100
Enter a 1-byte unsigned number: 230
Overflow!
Exercise #2: A 1-byte calculator - step 2 [20pts]
Extend the program from the previous question so that it asks the user whether an addition or a multiplication is needed (still using only 1-byte operations on unsigned quantities). The user is prompted for a character, which can be '+' or '*', and the program should print an error message if an invalid operation is entered. Call your program hw4_ex2, stored in file hw4_ex2.asm.
Here are example interactions with the program:
% ./hw4_ex2
Enter a 1-byte unsigned number: 12
Enter a 1-byte unsigned number: 13
Enter an operation: +
25
% ./hw4_ex2
Enter a 1-byte unsigned number: 12
Enter a 1-byte unsigned number: 13
Enter an operation: *
156
% ./hw4_ex2
Enter a 1-byte unsigned number: 12
Enter a 1-byte unsigned number: 13
Enter an operation: /
Invalid operation...
% ./hw4_ex2
Enter a 1-byte unsigned number: -1
Invalid number...
% ./hw4_ex2
Enter a 1-byte unsigned number: 256
Invalid number...
% ./hw4_ex2
Enter a 1-byte unsigned number: 132
Enter a 1-byte unsigned number: 250
Enter an operation: +
Overflow!
% ./hw4_ex2
Enter a 1-byte unsigned number: 10
Enter a 1-byte unsigned number: 30
Enter an operation: *
Overflow!
% ./hw4_ex2
Enter a 1-byte unsigned number: 10
Enter a 1-byte unsigned number: 30
Enter an operation: +
40
warning: The read_char macro is a bit odd in the way it deals with carriage returns, and you may have to call it twice in a row to get a single character. This kind of experimenting/tinkering/looking-at-registers is part of the assembly code writing experience.
Exercise #3: A 1-byte calculator - step 3 [ 10pts EXTRA CREDIT ]
Modify your program from the previous section so that numbers are signed, and still encodable on 1 byte. Call your new program hw4_ex3, stored in file hw4_ex3.asm.
Here are example interactions with the program:
% ./hw4_ex3
Enter a 1-byte signed number: 243
Invalid number...
% ./hw4_ex3
Enter a 1-byte signed number: -129
Invalid number...
% ./hw4_ex3
Enter a 1-byte signed number: -127
Enter a 1-byte signed number: 54
Enter an operation: +
-73
% ./hw4_ex3
Enter a 1-byte signed number: -80
Enter a 1-byte signed number: 2
Enter an operation: *
Overflow!
% ./hw4_ex3
Enter a 1-byte signed number: -5
Enter a 1-byte signed number: -10
Enter an operation: *
50
% ./hw4_ex3
Enter a 1-byte signed number: 45
Enter a 1-byte signed number: -46
Enter an operation: +
-1
% ./hw4_ex3
Enter a 1-byte signed number: 126
Enter a 1-byte signed number: 5
Enter an operation: +
Overflow!
% ./hw4_ex3
Enter a 1-byte signed number: 4
Enter a 1-byte signed number: 5
Enter an operation: /
Invalid operation...