<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://web.tecnico.ulisboa.pt/~david.matos/w/pt/index.php?action=history&amp;feed=atom&amp;title=Optimization_Topics%2FExercise_07</id>
	<title>Optimization Topics/Exercise 07 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://web.tecnico.ulisboa.pt/~david.matos/w/pt/index.php?action=history&amp;feed=atom&amp;title=Optimization_Topics%2FExercise_07"/>
	<link rel="alternate" type="text/html" href="https://web.tecnico.ulisboa.pt/~david.matos/w/pt/index.php?title=Optimization_Topics/Exercise_07&amp;action=history"/>
	<updated>2026-04-26T23:23:56Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.3</generator>
	<entry>
		<id>https://web.tecnico.ulisboa.pt/~david.matos/w/pt/index.php?title=Optimization_Topics/Exercise_07&amp;diff=15794&amp;oldid=prev</id>
		<title>Root: Created page with &quot;{{TOCright}} == Problema ==  Considere a seguinte função em C: # Que optimizações independentes da máquina são possíveis? # Traduza-a para Postfix optimizado.  &lt;source...&quot;</title>
		<link rel="alternate" type="text/html" href="https://web.tecnico.ulisboa.pt/~david.matos/w/pt/index.php?title=Optimization_Topics/Exercise_07&amp;diff=15794&amp;oldid=prev"/>
		<updated>2023-06-12T10:58:28Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{TOCright}} == Problema ==  Considere a seguinte função em C: # Que optimizações independentes da máquina são possíveis? # Traduza-a para Postfix optimizado.  &amp;lt;source...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{TOCright}}&lt;br /&gt;
== Problema ==&lt;br /&gt;
&lt;br /&gt;
Considere a seguinte função em C:&lt;br /&gt;
# Que optimizações independentes da máquina são possíveis?&lt;br /&gt;
# Traduza-a para Postfix optimizado.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int fun(double a, double b) {&lt;br /&gt;
  int i = 10, c;&lt;br /&gt;
  c = 20 * 1024 + i;&lt;br /&gt;
  while (++i &amp;lt; a + b) {&lt;br /&gt;
    if (a + b &amp;lt; 3 * i + 5) c += 2 * i;&lt;br /&gt;
  }&lt;br /&gt;
  return c;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Código Postfix (não optimizado) ==&lt;br /&gt;
&lt;br /&gt;
O código Postfix correspondente ao código C é o seguinte (agradece-se a comunicação de questões relativas a este código).&lt;br /&gt;
&lt;br /&gt;
{{CollapsedCode|Código Postfix|&lt;br /&gt;
&amp;lt;source lang=&amp;quot;asm&amp;quot;&amp;gt;&lt;br /&gt;
;;---- BB1 START ----&lt;br /&gt;
TEXT&lt;br /&gt;
ALIGN&lt;br /&gt;
GLOBAL fun, FUNC&lt;br /&gt;
LABEL fun&lt;br /&gt;
ENTER 8   ; i@-4 c@-8 a@+8 b@+16&lt;br /&gt;
&lt;br /&gt;
INT 10&lt;br /&gt;
LOCA -4 ; i=10&lt;br /&gt;
&lt;br /&gt;
INT 20&lt;br /&gt;
INT 1024&lt;br /&gt;
MUL&lt;br /&gt;
LOCAL -4&lt;br /&gt;
LDINT&lt;br /&gt;
ADD&lt;br /&gt;
DUP32&lt;br /&gt;
LOCAL -8&lt;br /&gt;
STINT ; c = ...&lt;br /&gt;
TRASH 4&lt;br /&gt;
;;---- BB1 END ----&lt;br /&gt;
&lt;br /&gt;
;;---- BB2 START ----&lt;br /&gt;
ALIGN&lt;br /&gt;
LABEL while_test&lt;br /&gt;
LOCAL -4&lt;br /&gt;
LDINT&lt;br /&gt;
INT 1&lt;br /&gt;
ADD&lt;br /&gt;
DUP32&lt;br /&gt;
LOCAL -4&lt;br /&gt;
STINT  ; ++i&lt;br /&gt;
I2D&lt;br /&gt;
&lt;br /&gt;
LOCAL +8&lt;br /&gt;
LDDOUBLE&lt;br /&gt;
LOCAL +16&lt;br /&gt;
LDDOUBLE&lt;br /&gt;
DADD  ; a + b&lt;br /&gt;
&lt;br /&gt;
DCMP&lt;br /&gt;
INT 0&lt;br /&gt;
LT&lt;br /&gt;
JZ while_end&lt;br /&gt;
;;---- BB2 END ----&lt;br /&gt;
&lt;br /&gt;
;;---- BB3 START ----&lt;br /&gt;
LOCAL +8&lt;br /&gt;
LDDOUBLE&lt;br /&gt;
LOCAL +16&lt;br /&gt;
LDDOUBLE&lt;br /&gt;
DADD  ; a + b&lt;br /&gt;
&lt;br /&gt;
INT 3&lt;br /&gt;
LOCAL -4&lt;br /&gt;
LDINT&lt;br /&gt;
MUL&lt;br /&gt;
INT 5&lt;br /&gt;
ADD&lt;br /&gt;
I2D&lt;br /&gt;
&lt;br /&gt;
DCMP&lt;br /&gt;
INT 0&lt;br /&gt;
LT&lt;br /&gt;
JZ ifend&lt;br /&gt;
;;---- BB3 END ----&lt;br /&gt;
&lt;br /&gt;
;;---- BB4 START ----&lt;br /&gt;
LOCAL -8&lt;br /&gt;
LDINT ; c&lt;br /&gt;
INT 2&lt;br /&gt;
LOCAL -4&lt;br /&gt;
LDINT&lt;br /&gt;
MUL ; 2 * i&lt;br /&gt;
ADD&lt;br /&gt;
DUP32&lt;br /&gt;
LOCAL -8  ; &amp;amp;c&lt;br /&gt;
STINT&lt;br /&gt;
TRASH 4&lt;br /&gt;
;;---- BB4 END ----&lt;br /&gt;
&lt;br /&gt;
;;---- BB5 START ----&lt;br /&gt;
ALIGN&lt;br /&gt;
LABEL ifend&lt;br /&gt;
&lt;br /&gt;
JMP while_test&lt;br /&gt;
;;---- BB5 END ----&lt;br /&gt;
&lt;br /&gt;
;;---- BB6 START ----&lt;br /&gt;
ALIGN &lt;br /&gt;
LABEL while_end&lt;br /&gt;
&lt;br /&gt;
LOCAL -8&lt;br /&gt;
LDINT  ; c&lt;br /&gt;
STFVAL32&lt;br /&gt;
LEAVE&lt;br /&gt;
RET&lt;br /&gt;
;;---- BB6 END ----&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Compiling and Running ==&lt;br /&gt;
&lt;br /&gt;
Para compilar o código Postfix directamente, pode ser utilizada a ferramenta [[Compiladores/Projecto de Compiladores/Compiladores Exemplo|pf2asm]] (assumindo uma arquitectura Intel de 32 bits -- ix86):&lt;br /&gt;
&lt;br /&gt;
 pf2asm code.pf&lt;br /&gt;
 yasm -felf32 code.asm&lt;br /&gt;
&lt;br /&gt;
[[category:Compiladores]]&lt;br /&gt;
[[category: Ensino]]&lt;/div&gt;</summary>
		<author><name>Root</name></author>
	</entry>
</feed>