<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.sarg.dev/index.php?action=history&amp;feed=atom&amp;title=Three-address_code</id>
	<title>Three-address code - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.sarg.dev/index.php?action=history&amp;feed=atom&amp;title=Three-address_code"/>
	<link rel="alternate" type="text/html" href="https://wiki.sarg.dev/index.php?title=Three-address_code&amp;action=history"/>
	<updated>2026-04-20T05:07:02Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://wiki.sarg.dev/index.php?title=Three-address_code&amp;diff=295404&amp;oldid=prev</id>
		<title>imported&gt;HKLionel: Adding local short description: &quot;Intermediate code used by optimizing compilers&quot;, overriding Wikidata description &quot;representation of intermediate code used by compilers&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.sarg.dev/index.php?title=Three-address_code&amp;diff=295404&amp;oldid=prev"/>
		<updated>2025-05-13T03:04:04Z</updated>

		<summary type="html">&lt;p&gt;Adding local &lt;a href=&quot;https://en.wikipedia.org/wiki/Short_description&quot; class=&quot;extiw&quot; title=&quot;wikipedia:Short description&quot;&gt;short description&lt;/a&gt;: &amp;quot;Intermediate code used by optimizing compilers&amp;quot;, overriding Wikidata description &amp;quot;representation of intermediate code used by compilers&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Short description|Intermediate code used by optimizing compilers}}&lt;br /&gt;
In [[computer science]], &amp;#039;&amp;#039;&amp;#039;three-address code&amp;#039;&amp;#039;&amp;#039;&amp;lt;ref&amp;gt;{{Cite book|url=https://archive.org/details/compilersprincip00ahoa/page/466|title=Compilers, principles, techniques, and tools|last=V.|first=Aho, Alfred|date=1986|publisher=Addison-Wesley Pub. Co|others=Sethi, Ravi., Ullman, Jeffrey D., 1942-|isbn=0201100886|location=Reading, Mass.|pages=[https://archive.org/details/compilersprincip00ahoa/page/466 466]|oclc=12285707|url-access=registration}}&amp;lt;/ref&amp;gt; (often abbreviated to TAC or 3AC) is an [[intermediate language|intermediate code]] used by [[optimizing compiler]]s to aid in the implementation of [[code-improving transformation]]s. Each TAC instruction has at most three operands and is typically a combination of assignment and a binary operator. For example, &amp;lt;code&amp;gt;t1 := t2 + t3&amp;lt;/code&amp;gt;. The name derives from the use of three operands in these statements even though instructions with fewer operands may occur.&lt;br /&gt;
&lt;br /&gt;
Since three-address code is used as an intermediate language within compilers, the operands will most likely not be concrete memory addresses or [[processor registers]], but rather symbolic addresses that will be translated into actual addresses during [[register allocation]]. It is also not uncommon that operand names are numbered sequentially since three-address code is typically generated by the compiler.&lt;br /&gt;
&lt;br /&gt;
A refinement of three-address code is [[A-normal form]] (ANF).&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
In three-address code, this would be broken down into several separate instructions. These instructions translate more easily to [[assembly language]]. It is also easier to detect [[common subexpression elimination|common sub-expressions]] for shortening the code. In the following example, one calculation is composed of several smaller ones:&lt;br /&gt;
&lt;br /&gt;
{{col-begin}}&lt;br /&gt;
{{col-2}}&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# Calculate one solution to the [[Quadratic equation]].&lt;br /&gt;
x = (-b + sqrt(b^2 - 4*a*c)) / (2*a)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
{{col-2}}&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow: auto;&amp;quot;&amp;gt;&lt;br /&gt;
t1 := b * b&lt;br /&gt;
t2 := 4 * a&lt;br /&gt;
t3 := t2 * c&lt;br /&gt;
t4 := t1 - t3&lt;br /&gt;
t5 := sqrt(t4)&lt;br /&gt;
t6 := 0 - b&lt;br /&gt;
t7 := t5 + t6&lt;br /&gt;
t8 := 2 * a&lt;br /&gt;
t9 := t7 / t8&lt;br /&gt;
x := t9&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
{{col-end}}&lt;br /&gt;
&lt;br /&gt;
Three-address code may have conditional and unconditional jumps and methods of accessing memory. It may also have methods of calling functions, or it may reduce these to jumps. In this way, three-address code may be useful in [[control-flow analysis]]. In the following C-like example, a loop stores the squares of the numbers between 0 and 9:&lt;br /&gt;
&lt;br /&gt;
{{col-begin}}&lt;br /&gt;
{{col-2}}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot; style=&amp;quot;margin-top: 1em;&amp;quot;&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
for (i = 0; i &amp;lt; 10; ++i) {&lt;br /&gt;
    b[i] = i*i; &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{col-2}}&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow: auto;&amp;quot;&amp;gt;&lt;br /&gt;
     t1 := 0                ; initialize i&lt;br /&gt;
L1:  if t1 &amp;gt;= 10 goto L2    ; conditional jump&lt;br /&gt;
     t2 := t1 * t1          ; square of i&lt;br /&gt;
     t3 := t1 * 4           ; word-align address&lt;br /&gt;
     t4 := b + t3           ; address to store i*i&lt;br /&gt;
     *t4 := t2              ; store through pointer&lt;br /&gt;
     t1 := t1 + 1           ; increase i&lt;br /&gt;
     goto L1                ; repeat loop&lt;br /&gt;
L2:&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
{{col-end}}&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
{{Portal|Computer programming}}&lt;br /&gt;
&lt;br /&gt;
* [[Intermediate language]]&lt;br /&gt;
* [[Reduced instruction set computer]]&lt;br /&gt;
* [[Static single-assignment form]] (SSA)&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Compiler construction]]&lt;br /&gt;
[[Category:Articles with example C code]]&lt;/div&gt;</summary>
		<author><name>imported&gt;HKLionel</name></author>
	</entry>
</feed>