self.lines.push(line.to_string());
}
- asm_macro!(copy_top_stack_value_to, "lw {}, 0(s2)", &str);
- asm_macro!(copy_offset_stack_value_to, "lw {}, {}*8(s2)", &str, isize);
- asm_macro!(copy_to_top_of_stack, "sw {}, 0(s2)", &str);
+ asm_macro!(copy_top_stack_value_to, "ld {}, 0(s2)", &str);
+ asm_macro!(copy_offset_stack_value_to, "ld {}, {}*8(s2)", &str, isize);
+ asm_macro!(copy_to_top_of_stack, "sd {}, 0(s2)", &str);
asm_macro!(move_stack_ptr_by_cells, "addi s2, s2, {}*8", isize);
fn pop_to(&mut self, reg: &str) {
self.label(format!("{}:", name));
}
self.line("addi sp, sp, -16 # allocate 16 bytes on stack"); // allocate 16 bytes on stack
- self.line("sw ra, 8(sp) # store return address on stack"); // store return address on stack
+ self.line("sd ra, 8(sp) # store return address on stack"); // store return address on stack
},
IR::Call(name) => {
self.label(format!("# call {}", name));
self.line("mv a0, x0");
self.line("ecall");
} else {
- self.line("lw ra, 8(sp)"); // load return address from stack
+ self.line("ld ra, 8(sp)"); // load return address from stack
self.line("addi sp, sp, 16"); // restore stack pointer
self.line("ret");
}
},
IR::Load => {
self.copy_top_stack_value_to("t0");
- self.line(format!("lw {}, 0({})", "t0", "t0")); // deref pointer int t0 to t0
+ self.line(format!("ld {}, 0({})", "t0", "t0")); // deref pointer int t0 to t0
self.copy_to_top_of_stack("t0");
},
IR::Store => { // ( x addr -- )
- self.copy_top_stack_value_to("t1");
- self.copy_offset_stack_value_to("t0", 1);
- self.line("sw t0, 0(t1)"); // store x at addr
- self.move_stack_ptr_by_cells(2);
+ self.pop_some_to("t0 t1");
+ self.line("sd t0, 0(t1)"); // store x at addr
},
IR::StackPush(num) => {
self.label(format!("# stackpush {}", num));