def compile(self): emit.comment("system code") emit.RM("LDC", SP, 0, 0) emit.RM("LDA", 1, 2, PC) emit.RM("ST", 1, 1+_table.nargs("main"), SP) self.mainLabel.produce( lambda origin, target: emit.RMAbs("LDA", PC, target, "jump to main", origin) ) emit.skip() emit.RM("LD", 1, 0, SP) emit.RO("OUT", 1, 0,0) emit.RO("HALT", 0,0,0, "done.") emit.comment("print function") self.printLabel.compile() emit.RM("LD", 1, 1, SP) emit.RM("LDA", 2, 2, SP) emit.RM("LD", 3, 0, 2) emit.RO("OUT", 3, 0, 0) emit.RM("LDA", 2, 1, 2) emit.RM("LDA", 1, -1, 1) emit.RM("JNE", 1, -5, 7) emit.RM("LD", 1, 1, SP) emit.RO("ADD", 1, 1, SP) emit.RM("LD", 7, 2, 1) emit.comment("program code")
def compile(self): condr = _registers.need(self.cond) self.label.produce( lambda origin, target: emit.RMAbs("JNE", condr, target, repr(self), origin) ) emit.skip() _registers.freeReg(condr)
def compile(self): RAoffset = _stack.push(0) # calling sequence, before call emit.RM("LDA", _targetr, 3, PC, repr(self)) emit.RM("ST", _targetr, RAoffset, SP) emit.RM("LDA", SP, _nextFrame, SP) self.label.produce( lambda origin, target: emit.RMAbs("LDA", PC, target, None, origin) ) emit.skip() # calling sequence, after call emit.RM("LD", _targetr, 0, SP) emit.RM("LDA", SP, -_nextFrame, SP)
def compile(self): self.label.produce( lambda origin, target: emit.RMAbs("LDA", PC, target, repr(self), origin) ) emit.skip()