Exemplo n.º 1
0
    def memAddressToReg(self, p, reg1, reg2):
        declaration = self.declaration

        if not declaration.isArray():
            raise Exception("'%s' is not an Array" % declaration.pidentifier)

        memoryId = declaration.memoryId
        arrRangeFrom = declaration.rangeFrom
        arrRangeTo = declaration.rangeTo

        indexIdentifier = Identifier(self.index)

        # tab(5:15)         [memoryId:memoryId+10]
        # a := 7
        # tab(a)
        Instructions.LOAD_IDENTIFIER_VALUE_TO_REGISTER(p, indexIdentifier, reg2)  # reg2 = a.value
        Instructions.setRegisterConst(p, reg1, arrRangeFrom)                      # reg1 = arrRangeFrom
        Instructions.SUB(p, reg2, reg1)                                           # reg2 = reg2 - reg1 // offset
        Instructions.setRegisterConst(p, reg1, memoryId)                          # reg1 = memoryId
        Instructions.ADD(p, reg1, reg2)                                           # reg1 = reg1 + reg2 // memid + offset