From owner-freebsd-doc@FreeBSD.ORG Thu Apr 2 09:48:52 2009 Return-Path: Delivered-To: doc@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8A7A3106568F for ; Thu, 2 Apr 2009 09:48:52 +0000 (UTC) (envelope-from mauro.borella@studenti.unipr.it) Received: from avas-univ-1.cineca.it (avas-univ-1.cineca.com [130.186.81.104]) by mx1.freebsd.org (Postfix) with ESMTP id 1AF638FC2A for ; Thu, 2 Apr 2009 09:48:51 +0000 (UTC) (envelope-from mauro.borella@studenti.unipr.it) X-IronPort-AV: E=McAfee;i="5300,2777,5571"; a="8561244" Received: from unipr.mm.cineca.it ([130.186.10.204]) by avas-univ-1.cineca.it with ESMTP; 02 Apr 2009 11:19:08 +0200 Received: from localhost (unipr.mm.cineca.it [130.186.10.204]) as user anonymous by unipr.mm.cineca.it (Postfix) with ESMTP id 877E82E6878 for ; Thu, 2 Apr 2009 11:19:08 +0200 (MEST) Received: from 160.78.28.106 ( [160.78.28.106]) as user mauro.borella@studenti.unipr.it@posta.studenti.unipr.it by posta.studenti.unipr.it with HTTP; Thu, 2 Apr 2009 11:19:08 +0200 Message-ID: <1238663948.49d4830c7ba82@posta.studenti.unipr.it> Date: Thu, 2 Apr 2009 11:19:08 +0200 From: MAURO To: doc@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: Internet Messaging Program (IMP) 3.1 X-Originating-IP: 160.78.28.106 Cc: Subject: Assembly exercise.Help!!! X-BeenThere: freebsd-doc@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Documentation project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Apr 2009 09:48:53 -0000 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!