Assignment#2: DUE DATE: Monday, March 13, 2005, by Midnight. Email to your section's GA. Warning: 1) For this assignment you must use only the instructions, macros, and directives that are described in lectures 1 to 7. Exception to this is in question 1, where you'll be using the Rint code discussed in Lecture 8 (page 17). 2) Make sure your program is well commented. ================================================================================== Programming Exercise 1 (50 points): a) (30 points) Write a procedure called multiply that takes two signed 16 bit values and returns the result of their multiplication. You are not allowed to use instructions discussed in Chapter 8, including MUL and IMUL. You should implement multiply by addition. The first argument to multiply is passed through AX register. The second argument is passed through BX. The result of multiplication is returned in EAX. Make sure after execution of multiply all general purpose registers maintain their original value before the call except for EAX which will contain the result of multiplication. b) (20 points) To test multiply you'll write a main program that prompts the user to enter two numbers and then output the result of multiplication using multiply as shown below. In your main program: You'll have to check that the input value N is within range -32768 <= N <= 32767. If the entered number is out of range your program will issue an error message as shown below and asks the user to enter two new numbers. You should only make the call to multiply if the entered numbers are within acceptable range. After showing the result of multiplication your main program will give the user an option to quit the program. If the user enters y ,Y or any sequence of characters that starts with a lowercase or uppercase Y, the program exits. If the user enters any other character or string of characters the program continues with asking the user to enter two more numbers .... Hint: To simplify the code in the main portion of your program you may want to write a procedure that will perform the within range check and sets a flag that you can test after return from the call. NOTE: To read signed integer numbers from standard input you can use procedure Rint. The code for this procedure is in page 17 of Lecture 8. Make sure you do the following: 1) Save this code in a file called Rint.inc 2) Use an include directive immediately after .code directive to include this file in your program. NOTE: Make sure you name your program ass2-1.asm. Here are some sample execution scenarios: C:\ASM>ass2-1 Enter the first number: 0 Enter the second number: 0 0*0=0 Quit ? n Enter the first number: 0 Enter the second number: 3 0*3=0 Quit ? Y C:\ASM>ass2-1 Enter the first number: 3 Enter the second number: 0 3*0=0 Quit ? n Enter the first number: 32767 Enter the second number: -32768 32767*-32768=-1073709056 Quit ? n Enter the first number: -32768 Enter the second number: 32767 -32768*32767=-1073709056 Quit ? No Enter the first number: 32768 32768 Is Out of Range ! Enter the first number: 32767 Enter the second number: -32769 -32769 Is Out of Range ! Enter the first number: 32767 Enter the second number: 32767 32767*32767=1073676289 Quit ? n Enter the first number: -32768 Enter the second number: -32768 -32768*-32768=1073741824 Quit ? n Enter the first number: 1 Enter the second number: 5 1*5=5 Quit ? n Enter the first number: 1 Enter the second number: -1 1*-1=-1 Quit ? n Enter the first number: -1 Enter the second number: -1 -1*-1=1 Quit ? y C:\ASM> ==================================================================================== Programming Exercise 2 (50 points): a) (10 points) Write a procedure called DisplayHexDigit that takes as input a number between 0 and 15 stored in BX register and prints it in hexadecimal. b) (10 points) Write a procedure called DisplayHexByte that takes as input a number between 0 and 255 stored in BX register and prints it in hexadecimal. Procedure DisplayHexByte should call DisplayHexDigit to print the number. c) (15 points) Write a procedure called DisplayHexWord that takes as input a number between 0 and 65535 stored in BX register and prints it in hexadecimal. Procedure DisplayHexWord should call DisplayHexByte to print the number. d) (15 points) To test these procedures your main program should read a number from the input between 0 and 65535 and depending on the range that the input number falls call one of the above procedure. NOTE: Make sure you name your programs ass2-2-a.asm, ass2-2-b.asm, ass2-2-c.asm and ass2-2-d.asm. To read a number from standard input use the Rint procedure as it was discussed in Question 1. Here are some sample execution scenarios: C:\ASM>ass2-2 0 0 C:\ASM>ass2-2 15 F C:\ASM>ass2-2 16 10 C:\ASM>ass2-2 255 FF C:\ASM>ass2-2 256 0100 C:\ASM>ass2-2 1000 03E8 C:\ASM>ass2-2 65535 FFFF