diff --git a/asm.vp b/asm.vp index f1b0f4c..ae55d66 100644 --- a/asm.vp +++ b/asm.vp @@ -18,9 +18,13 @@ def pause(): def inb(port: t.CUInt16T) -> t.CUInt8T: value: t.CUInt32T + # 显式 mov 到输出寄存器:EAX 作临时(CLOBBER_RAX 声明),避免 + # AsmOut 分配到非 RAX 时读到 asm 前残留(加 CLOBBER_RAX 后 LLVM + # 不再把 value 绑到 RAX,需 asm 内显式存值)。 c.Asm(f"""mov edx, {c.AsmInp(t.CUInt32T(port), t.ASM_DESCR.REG_ANY)} in al, dx - movzx eax, al""", + movzx eax, al + mov {c.AsmOut(value, t.ASM_DESCR.OUTPUT_REG)}, eax""", out = [c.AsmOut(value, t.ASM_DESCR.OUTPUT_REG)], op =[t.ASM_DESCR.CLOBBER_RDX, t.ASM_DESCR.CLOBBER_RAX]) return t.CUInt8T(value) @@ -36,7 +40,8 @@ def inw(port: t.CUInt16T) -> t.CUInt16T: value: t.CUInt32T c.Asm(f"""mov edx, {c.AsmInp(t.CUInt32T(port), t.ASM_DESCR.REG_ANY)} in ax, dx - movzx eax, ax""", + movzx eax, ax + mov {c.AsmOut(value, t.ASM_DESCR.OUTPUT_REG)}, eax""", out = [c.AsmOut(value, t.ASM_DESCR.OUTPUT_REG)], op =[t.ASM_DESCR.CLOBBER_RDX, t.ASM_DESCR.CLOBBER_RAX]) return t.CUInt16T(value) @@ -50,7 +55,8 @@ def outw(port: t.CUInt16T, value: t.CUInt16T): def inl(port: t.CUInt16T) -> t.CUInt32T: value: t.CUInt32T c.Asm(f"""mov edx, {c.AsmInp(t.CUInt32T(port), t.ASM_DESCR.REG_ANY)} - in eax, dx""", + in eax, dx + mov {c.AsmOut(value, t.ASM_DESCR.OUTPUT_REG)}, eax""", out = [c.AsmOut(value, t.ASM_DESCR.OUTPUT_REG)], op =[t.ASM_DESCR.CLOBBER_RDX, t.ASM_DESCR.CLOBBER_RAX]) return value