arithmetic.h
来自「简单的虚拟机」· C头文件 代码 · 共 128 行
H
128 行
/* opcode r/m8 r8| op r8 r/m8 */#define handle_arith_rm8(opstr, op1,op2) \{\ word __dest = get_op_val(op1); \ word __src = get_op_val(op2); \ __asm__("push %%edx\n\t" \ "popfl \n\t" \ #opstr" %%bl,%%al\n\t" \ "pushfl \n\t" \ "pop %%edx\n\t" \ :"=a"(__dest),"=d"(cpu.flags) \ :"a"(__dest),"b"(__src),"d"(cpu.flags)); \ set_op_val(op1,__dest); \}/* opcode r/m16 r16 | op r16 r/m16 */#define handle_arith_rm16(opstr,op1,op2) \{ \ word __dest = get_op_val(op1); \ word __src = get_op_val(op2); \ __asm__("push %%edx\n\t" \ "popfl\n\t" \ #opstr" %%bx,%%ax\n\t" \ "pushfl\n\t" \ "pop %%edx\n\t" \ :"=a"(__dest),"=d"(cpu.flags) \ :"a"(__dest),"b"(__src),"d"(cpu.flags)); \ set_op_val(op1,__dest); \}#define handle_arith_rm(opstr,op1,op2,wFlag) \ if(wFlag) \ { \ handle_arith_rm16(opstr,op1,op2) \ } \ else \ { \ handle_arith_rm8(opstr,op1,op2) \ }/****************************************************************************//* opcode r/m8 imm8 */#define handle_arith_rm8_imm(opstr, op, imm) \{ \ word __dest = get_op_val(op); \ __asm__("push %%edx\n\t" \ "popfl\n\t" \ #opstr" %%bl,%%al\n\t" \ "pushfl\n\t" \ "pop %%edx\n\t" \ :"=a"(__dest),"=d"(cpu.flags) \ :"a"(__dest),"d"(cpu.flags),"b"(imm)); \ set_op_val(op,__dest); \}/* opcode r/m16 imm16 */#define handle_arith_rm16_imm(opstr,op,imm) \{ \ word __dest = get_op_val(op); \ __asm__("push %%edx\n\t" \ "popfl\n\t" \ #opstr" %%bx,%%ax\n\t" \ "pushfl\n\t" \ "pop %%edx\n\t" \ :"=a"(__dest),"=d"(cpu.flags) \ :"a"(__dest),"d"(cpu.flags),"b"(imm)); \ set_op_val(op,__dest); \}#define handle_arith_rm_imm(opstr,op,imm,wFlag) \ if(wFlag) \ { \ handle_arith_rm16_imm(opstr,op,imm) \ } \ else \ { \ handle_arith_rm8_imm(opstr,op,imm) \ }/****************************************************************************/#define handle_bcdadjust(opstr) \{ \ __asm__("push %%edx\n\t" \ "popfl\n\t" \ #opstr"\n\t" \ "pushfl\n\t" \ "pop %%edx\n\t" \ :"=d"(cpu.flags),"=a"(cpu.greg.ax) \ :"d"(cpu.flags),"a"(cpu.greg.ax)); \}/*****************************************************************************/#define handle_incdec16(opstr,op) \{ \ word __dest = get_op_val(op); \ __asm__("push %%edx\n\t" \ "popfl\n\t" \ #opstr" %%ax\n\t" \ "pushfl\n\t" \ "pop %%edx\n\t" \ :"=a"(__dest),"=d"(cpu.flags) \ :"a"(__dest),"d"(cpu.flags)); \ set_op_val(op,__dest); \}#define handle_incdec8(opstr,op) \{ \ word __dest = get_op_val(op); \ __asm__("push %%edx\n\t" \ "popfl\n\t" \ #opstr" %%al\n\t" \ "pushfl\n\t" \ "pop %%edx\n\t" \ :"=a"(__dest),"=d"(cpu.flags) \ :"a"(__dest),"d"(cpu.flags)); \ set_op_val(op,__dest); \}#define handle_incdec(opstr,op,wFlag) \ if(wFlag) \ { \ handle_incdec16(opstr,op) \ } \ else \ { \ handle_incdec8(opstr,op) \ }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?