简体   繁体   English

这个方程式的三地址代码是什么?

[英]What is a three address code for this equation?

The equation I have is x = y+z; 我的方程是x = y + z;

I have seen that when solving problems where x = y+zx,y,z are variables which are often converted to three address code like this: t1 = y+z; 我已经看到,当解决x = y + zx,y,z是问题的变量时,这些变量通常会转换为如下所示的三个地址代码:t1 = y + z; x = t1; x = t1;

My doubt is when x = y+z is itself a three address code and therefore why we use temporary variables. 我的疑问是,何时x = y + z本身是一个三地址代码,因此为什么我们使用临时变量。

For example converting 例如转换

for(int i=1; i<10; i++) x = y+z;

3 address code: 3个地址码:

i = 1
l1: if(i>=10) goto l2
    t1 = y+z;
    x = t1;
    goto l1;
l2:

Why can't we write x = y+z instead of t1 = y+z and x = t1; 为什么我们不能写x = y + z而不是t1 = y + z和x = t1;

x = y + z is a three address code. x = y + z是一个三地址代码。

No. It's a 4 address code. 否。这是4位地址代码。

Usually, the "three" means we have to consider a register variable or temporal variable, additionally. 通常,“三个”意味着我们必须另外考虑寄存器变量或时间变量。

A possible equivalent could be: 可能的等效项可能是:

y = <some value>
z= <some value>
T1 = z
T1 += y
x = T1

Some developers use a assembler like syntax: 一些开发人员使用类似于汇编程序的语法:

Move y, <some value>
Move z, <some value>
Move T1, z
Add T1, y
Move x, T1

As you may know, some important things to consider in order to use intermediate code, (or three address code expressions) : 如您所知,使用中间代码(或三个地址代码表达式)需要考虑一些重要事项:

  • "Three" means the limit, not rule, there can be less, like one or two operands. “三个”表示限制,而不是规则,可以少于一个或两个操作数。

    x++; x ++; x = y; x = y; x = y + z; x = y + z;

  • Start thinking with constants, numbers, or variables as "location (s)", each operand or address code ("PO Box"), represents a place in a computer's memory. 开始考虑将常量,数字或变量表示为“位置”,每个操作数或地址代码(“邮政信箱”)代表计算机内存中的一个位置。

  • Unleast one of the variables, is a destination location of the result. 变量中的至少一个是结果的目标位置。

    w = a * 2; w = a * 2;

  • That same destination variable can be used as a source operand. 该目标变量可以用作源操作数。

    x = x * y; x = x * y; y = y + 1; y = y + 1;

  • Three address code expressions, are short mathematical expressions, that are written, similar, to commonly used expressions, but, with lesser elements, because there meant to be translated to assembly code. 三个地址代码表达式是简短的数学表达式,与常用的表达式相似,但是使用较少的元素,因为这意味着可以转换为汇编代码。

Besides usings not just, 1, 2 or 3 locations, is that some operations, cannot be done, in any location, usually the temporal variables represent a CPU register. 除了仅使用1、2或3个位置以外,还不能在任何位置进行某些操作,通常时间变量代表CPU寄存器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM