Example #1
0
def write_bool_jumps(jump_cond):
    eq_label_true = true_label()
    eq_label_false = false_label()
    add_line('@' + eq_label_true)
    add_line('D;' + jump_cond)
    add_line('@' + eq_label_false)
    add_line('0;JMP')
    add_symbol_link(eq_label_true)
    set_bool_to_stack(True)
    add_next_symbol()
    add_symbol_link(eq_label_false)
    set_bool_to_stack(False)
    symb_next = add_next_symbol()
    add_symbol_link(symb_next)
    increase_stack_pointer()
    global next_counter
    next_counter += 1
    global equality_counter
    equality_counter += 1
Example #2
0
def unconditional_jump(location):
    add_line('@' + location)
    add_line('0;JMP')
Example #3
0
def write_to_stack(source):
    point_stack_current()
    add_line("M=" + source)
    increase_stack_pointer()
Example #4
0
def read_stack_to(dest: str, discrease_pointer=True):
    if discrease_pointer:
        descrease_stack_pointer()
    point_stack_current()
    add_line(dest + '=M')
Example #5
0
def point_top_stack_val():
    point_sp()
    add_line('A=M')
Example #6
0
def descrease_stack_pointer():
    global stack_pointer
    stack_pointer -= 1
    point_sp()
    add_line("M=M-1")
Example #7
0
def increase_stack_pointer():
    global stack_pointer
    stack_pointer += 1
    point_sp()
    add_line("M=M+1")
Example #8
0
def add_symbol_link(label):
    add_line(get_symbol_link(label))
Example #9
0
def point_to_local_tmp():
    add_line('@lcl_temp')
Example #10
0
def point_sp():
    add_line('@SP')
Example #11
0
def point_to_base(base, location):
    add_line('@' + str(base + location))
Example #12
0
def point_static(name, location):
    add_line('@' + name + '.' + location)
Example #13
0
def write_const_to(const, dest):
    add_line('@' + const)
    write_c_command(dest, 'A')
Example #14
0
def read_stack_and_write(dest, op):
    descrease_stack_pointer()
    point_stack_current()
    add_line(dest + '=' + op)
    if dest == "M":
        increase_stack_pointer()
Example #15
0
def write_c_command(dest, source):
    add_line(dest + '=' + source)
Example #16
0
def point_stack_current():
    global stack_pointer
    point_sp()
    add_line('A=M')
Example #17
0
def init_stack_pointer():
    add_line('@' + str(stack_pointer))
    add_line('D=A')
    point_sp()
    add_line('M=D')