Saturday, April 25, 2009

Our offline

Offline Assignment (A2)


1. Input and Output Procedure: Upto now you have used signle character numbers as
input/output which restricted the input/output to the range 0 to 9. Now, you have to write two
procedures that can handle multi character inputs/outputs. These procedures will be needed in
all the upcoming sessionals to be used as default I/O routine.
a) Write a procedure INDEC in assembly language that can be used to take input as signed
decimal or hexadecimal integers. The procedure will print a question mark, lets the user enter
an optional sign , followed by a string of digits, followed by a carriage return. Decimal numbers
will start with a number other than zero(0) and hexadecimal number will start with a zero(0). If
the procedure enters a character outside the range “0”….”9” for decimal input or outside the
range “0” to “F” for hexadecimal numbers the procedure goes to a new line and starts over to
take input again. After the carriage return the input will be saved on DX register.
b) Write a procedure OUTDEC in assembly language to print the contents of DX as a signed
decimal integer. If DX>=0, OUTDEC will print the contents in decimal. If DX<0, OUTDEC will print
a minus sign, replace DX by –DX and print the contents in decimal.
Sample Input :
?
-21
Sample Output:
-21
Sample Input :
?
314
Sample Output:
314
Sample Input :
?
0E9
Sample Output:
233
Sample Input :
?
-0FA
Sample Output:
-250

2. Postfix arithmetic evaluation: Write an assembly program to evaluate an arithmetic expression

given as polish postfix notations. Take the expression as a string using slightly modified version
of the INDEC procedure. Scan the expression one number at a time separated by comma(,) from
left to right and display the final result after calculating the expression. Here, modified INDEC
need not to take optional sign and need to be terminated by comma(,). The operand numbers
will be at most one byte long and you do not need to consider fractions after division operation
that is only quotient will be evaluated into the result of the expression.
Sample Input :
3,10,+4,7,-2,*11,+*
Sample Output:
65
Sample Input :
3,50,12,/+
Sample Output:
7
Sample Input :
5,7,4,*-2,+
Sample Output:

-21

No comments:

Post a Comment