简体   繁体   English

如何将三地址代码转换为MIPS汇编语言?

[英]How to convert a three address code to MIPS Assembly language?

I am doing a project in which I have to create a translator that would generate a MIPS assembly code for a C code. 我正在做一个项目,我必须创建一个转换器,为C代码生成MIPS汇编代码。 The programming language that am using is C++ and I have done till generation of three address code and am really confused about how to proceed further. 我正在使用的编程语言是C ++,我已经完成了三个地址代码的生成,我真的很困惑如何继续前进。

As already stated, it's a direct translation. 如前所述,这是一个直接的翻译。 There's really nothing to clarify. 没有什么可以澄清的。 As an example, take the following three-address code: 例如,请使用以下三地址代码:

      i := 0                  ; assignment
L1:   if i >= 10 goto L2      ; conditional jump
      t0 := i*i
      t1 := &b                ; address-of operation
      t2 := t1 + i            ; t2 holds the address of b[i]
      *t2 := t0               ; store through pointer
      i := i + 1
      goto L1
L2:

The MIPS translation is: MIPS翻译是:

        li $t0, 0             #allocator assigned i to t0
L1:     bge $t0, 10, L2    
        mult $t1, $t0, $t0  
        la $t2, b             
        add $t3, $t2, $t0   
        sw $t1, ($t3)       
        addi $t0, $t0, 1
        j L1
L2:

If your lucky enough to have three-address like that, you barely have to do anything. 如果你有幸拥有这样的三个地址,你几乎不需要做任何事情。 Find the corresponding opcode to go with the instruction. 找到相应的操作码以符合指令。 The register allocation has already been done. 寄存器分配已经完成。 If the three-address code is literally a bunch a strings, I'd consider writing a small parser (using a generator) instead of trying to extract information from the strings. 如果三地址代码实际上是一串字符串,我会考虑编写一个小解析器(使用生成器)而不是尝试从字符串中提取信息。

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

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