From 77ac95b9985f5669d6659bfb54728786d28c2ef0 Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 20 Jul 2020 09:42:30 +0800 Subject: *misc --- src/lua51/lopcodes.h | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'src/lua51/lopcodes.h') diff --git a/src/lua51/lopcodes.h b/src/lua51/lopcodes.h index 41224d6..8c0d1a8 100644 --- a/src/lua51/lopcodes.h +++ b/src/lua51/lopcodes.h @@ -34,13 +34,24 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ /* ** size and position of opcode arguments. */ -#define SIZE_C 9 -#define SIZE_B 9 -#define SIZE_Bx (SIZE_C + SIZE_B) -#define SIZE_A 8 +/* +三种指令的格式 +iABC B:9 C:9 A:8 Opcode:6 +iABx Bx:18 A:8 Opcode:6 +iAsBx sBx:18 A:8 Opcode:6 +注:sBx是signed BX +寄存器就是相对于callinfo和lua_state的当前调用的base的某个偏移(即ABC值) +*/ +//c 单个指令Instruction的每部分的大小 +// 9 + 9 + 8 + 6 = 32 bits +#define SIZE_B 9 +#define SIZE_C 9 +#define SIZE_Bx (SIZE_C + SIZE_B) +#define SIZE_A 8 #define SIZE_OP 6 +//c 每个部分在Instruction中的偏移量,从低位到高位 #define POS_OP 0 #define POS_A (POS_OP + SIZE_OP) #define POS_C (POS_A + SIZE_A) @@ -76,7 +87,7 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ /* ** the following macros help to manipulate instructions */ - +//c 获取和设置Instruction中的某个部分 #define GET_OPCODE(i) (cast(OpCode, ((i)>>POS_OP) & MASK1(SIZE_OP,0))) #define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \ ((cast(Instruction, o)<