Date: Thu, 2 Apr 2009 11:19:08 +0200 From: MAURO <mauro.borella@studenti.unipr.it> To: doc@FreeBSD.org Subject: Assembly exercise.Help!!! Message-ID: <1238663948.49d4830c7ba82@posta.studenti.unipr.it>
next in thread | raw e-mail | index | archive | help
Hello, Sorry for my english. I must do an exercise in assembly language. This is the text of the exercise: One of the classic problems of computing the resolution of simple expressions such as, for example: ((10-5)+((8-2)-(3+4))). Indeed, the presence of brackets complicates the resolution forcing the calculation and storage of partial results. The resolution of such expressions is simpler if you write in reverse Polish notation that does not require the use of parentheses. In the case seen above: 10 5 - 8 2 - 3 4 + - + Exercise: write an assembly program that takes input expressions and result in reverse Polish notation. Let's say that the terms do not contain negative numbers and that the only operations are the sum (+) and subtraction (-). Subsequently implement the calculation of the outcome assuming that the numbers and the result (even partial) have at most 2 digits. Tip: The transformation of an expression in reverse Polish notation can be easily implemented using the stack. We must scan the expression from left to right and print (or save) the number that you encounter. When you encounter a transaction that is placed on the stack. Conversely, if you arrive at a closed parenthesis should be taken that the transaction is in the stack and print it. Similarly, the calculation of the result from the reverse Polish notation can be implemented using the stack. Even in this case it is necessary to scan the expression from left to right and put any numbers you find on the stack.When it comes to a transaction should be taking the two numbers at the top of the stack, perform calculations and store the result on the stack. At the end the result will be in the top of the stack. Example: introduce an expression: ((10-5) + ((8-2) - (3 +4))) inverse notation: 10 5-8 2-3 4 + - + result: 4 The CPU is 8086 and the kind of assembler is Intel x86 (say the classical assembler, the most common) Sincerely, I hope to help me succeed!
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1238663948.49d4830c7ba82>