From 78b4407869f2d89c72cf7139c2df9a438993307d Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Wed, 21 Aug 2024 11:18:12 +0900 Subject: [PATCH] [sample] resize stack element --- sample/bf.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sample/bf.cpp b/sample/bf.cpp index 2abb8a54..657c87c6 100644 --- a/sample/bf.cpp +++ b/sample/bf.cpp @@ -30,7 +30,7 @@ class Brainfuck : public Xbyak::CodeGenerator { const Reg32& pPutchar(esi); const Reg32& pGetchar(edi); const Reg32& stack(ebp); - const Address cur = dword [stack]; + const Address cur = byte [stack]; push(ebp); // stack push(esi); push(edi); @@ -42,7 +42,7 @@ class Brainfuck : public Xbyak::CodeGenerator { const Reg64& pPutchar(rsi); const Reg64& pGetchar(rdi); const Reg64& stack(rbp); // stack - const Address cur = dword [stack]; + const Address cur = byte [stack]; push(rsi); push(rdi); push(rbp); @@ -53,7 +53,7 @@ class Brainfuck : public Xbyak::CodeGenerator { const Reg64& pPutchar(rbx); const Reg64& pGetchar(rbp); const Reg64& stack(r12); // stack - const Address cur = dword [stack]; + const Address cur = byte [stack]; push(rbx); push(rbp); push(r12); @@ -80,7 +80,7 @@ class Brainfuck : public Xbyak::CodeGenerator { case '<': { int count = getContinuousChar(is, c); - add(stack, 4 * (c == '>' ? count : -count)); + add(stack, (c == '>' ? count : -count)); } break; case '.': @@ -89,12 +89,12 @@ class Brainfuck : public Xbyak::CodeGenerator { call(pPutchar); pop(eax); #elif defined(XBYAK64_WIN) - mov(ecx, cur); + movzx(ecx, cur); sub(rsp, 32); call(pPutchar); add(rsp, 32); #else - mov(edi, cur); + movzx(edi, cur); call(pPutchar); #endif break; @@ -106,13 +106,13 @@ class Brainfuck : public Xbyak::CodeGenerator { call(pGetchar); add(rsp, 32); #endif - mov(cur, eax); + mov(cur, al); break; case '[': { Label B = L(); labelB.push(B); - mov(eax, cur); + movzx(eax, cur); test(eax, eax); Label F; jz(F, T_NEAR);