Skip to content

Commit

Permalink
完成pop和push但并未测试
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyHaozeZhu committed Mar 28, 2022
1 parent 45586eb commit b65612d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
8 changes: 6 additions & 2 deletions nemu/include/cpu/rtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,17 @@ static inline void rtl_sext(rtlreg_t* dest, const rtlreg_t* src1, int width) {
static inline void rtl_push(const rtlreg_t* src1) {
// esp <- esp - 4
// M[esp] <- src1
TODO();
//TODO();
rtl_subi(&cpu.esp, &cpu.esp, 4);
rtl_sm(&cpu.esp, 4, src1);
}

static inline void rtl_pop(rtlreg_t* dest) {
// dest <- M[esp]
// esp <- esp + 4
TODO();
// TODO();
rtl_lm(dest, &cpu.esp, 4);
rtl_addi(&cpu.esp, &cpu.esp, 4);
}

static inline void rtl_eq0(rtlreg_t* dest, const rtlreg_t* src1) {
Expand Down
7 changes: 7 additions & 0 deletions nemu/src/cpu/exec/all-instr.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ make_EHelper(operand_size);

make_EHelper(inv);
make_EHelper(nemu_trap);
make_EHelper(call);
make_EHelper(push);
make_EHelper(pop);
make_EHelper(sub);
make_EHelper(xor);
make_EHelper(ret);

11 changes: 6 additions & 5 deletions nemu/src/cpu/exec/data-mov.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ make_EHelper(mov) {
}

make_EHelper(push) {
TODO();

print_asm_template1(push);
//TODO();
rtl_push(&id_dest -> val);
print_asm_template1(push);
}

make_EHelper(pop) {
TODO();

// TODO();
rtl_pop(&t2);
operand_write(id_dest, &t2);
print_asm_template1(pop);
}

Expand Down
8 changes: 4 additions & 4 deletions nemu/src/cpu/exec/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ opcode_entry opcode_table [512] = {
/* 0x4c */ EMPTY, EMPTY, EMPTY, EMPTY,
/* 0x50 */ EMPTY, EMPTY, EMPTY, EMPTY,
/* 0x54 */ EMPTY, EMPTY, EMPTY, EMPTY,
/* 0x58 */ EMPTY, EMPTY, EMPTY, EMPTY,
/* 0x5c */ EMPTY, EMPTY, EMPTY, EMPTY,
/* 0x58 */ IDEX(r, pop), IDEX(r, pop), IDEX(r, pop), IDEX(r, pop),
/* 0x5c */ EMPTY, IDEX(r, pop), IDEX(r, pop), IDEX(r, pop),
/* 0x60 */ EMPTY, EMPTY, EMPTY, EMPTY,
/* 0x64 */ EMPTY, EMPTY, EX(operand_size), EMPTY,
/* 0x68 */ EMPTY, EMPTY, EMPTY, EMPTY,
Expand Down Expand Up @@ -159,8 +159,8 @@ opcode_entry opcode_table [512] = {
/* 0x44 */ EMPTY, EMPTY, EMPTY, EMPTY,
/* 0x48 */ EMPTY, EMPTY, EMPTY, EMPTY,
/* 0x4c */ EMPTY, EMPTY, EMPTY, EMPTY,
/* 0x50 */ EMPTY, EMPTY, EMPTY, EMPTY,
/* 0x54 */ EMPTY, EMPTY, EMPTY, EMPTY,
/* 0x50 */ IDEX(r, push), IDEX(r, push), IDEX(r, push),IDEX(r, push),
/* 0x54 */ IDEX(r, push), IDEX(r, push), IDEX(r, push),IDEX(r, push),
/* 0x58 */ EMPTY, EMPTY, EMPTY, EMPTY,
/* 0x5c */ EMPTY, EMPTY, EMPTY, EMPTY,
/* 0x60 */ EMPTY, EMPTY, EMPTY, EMPTY,
Expand Down

0 comments on commit b65612d

Please sign in to comment.