def _pop_2_mem(sgm, index): dec_sp() # Mem[SP] = Mem[SP] - 1 asm.set_areg_from_sgm() # A=M asm.set_dreg_from_sgm() # D=M asm.set_areg('%s' % asm.sgm_2_reg(sgm)) # @reg asm.inc_areg(index) # Loop: A=A+1 asm.set_sgm_from_dreg() # M=D
def _push(sgm, index): asm.set_areg_from_reg('%s' % asm.sgm_2_reg(sgm)) # @REGISTER, A=M asm.inc_areg(index) # Loop: A=A+1 asm.set_dreg_from_sgm() # D=M asm.set_areg_from_reg('SP') # @SP, A=M asm.set_sgm_from_dreg() # M=D inc_sp() # Mem[SP] = Mem[SP] + 1