Skip to content

Commit

Permalink
[sample] save ra in bf.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
herumi committed Jan 8, 2024
1 parent 3016577 commit 1c843d0
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions sample/bf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ class Brainfuck : public Xbyak_riscv::CodeGenerator {
const auto &pPutchar = s2;
const auto &pGetchar = s3;
const auto &stack = s4;
const int saveSize = 16*3;
const int saveSize = 16*2;
addi(sp, sp, -saveSize);
sd(pPutchar, sp, 16);
sd(pGetchar, sp, 24);
sd(stack, sp, 32);
sd(pPutchar, sp, 8);
sd(pGetchar, sp, 16);
sd(stack, sp, 24);
sd(ra, sp, 32);

mv(pPutchar, a0);
mv(pGetchar, a1);
Expand Down Expand Up @@ -88,9 +89,10 @@ class Brainfuck : public Xbyak_riscv::CodeGenerator {
}
}

ld(stack, sp, 32);
ld(pGetchar, sp, 24);
ld(pPutchar, sp, 16);
ld(ra, sp, 32);
ld(stack, sp, 24);
ld(pGetchar, sp, 16);
ld(pPutchar, sp, 8);
addi(sp, sp, saveSize);
ret();
}
Expand Down

0 comments on commit 1c843d0

Please sign in to comment.