forked from ccccourse/sp110b
-
Notifications
You must be signed in to change notification settings - Fork 0
week5.md
Lin610313 edited this page May 25, 2022
·
1 revision
push推入堆疊
--sp推入暫存器
指令 意義 實作
LEA : load local address 載入區域變數 a = (int)(bp + *pc++);
IMM : load global address or immediate 載入全域變數或立即值 a = *pc++;
JMP : jump 躍躍指令 pc = (int *)*pc;
JSR : jump to subroutine 跳到副程式 *--sp = (int)(pc + 1); pc = (int *)*pc;
BZ : branch if zero if (a==0) goto m[pc] pc = a ? pc + 1 : (int *)*pc;
BNZ : branch if not zero if (a!=0) goto m[pc] pc = a ? (int *)*pc : pc + 1;
ENT : enter subroutine 進入副程式 *--sp = (int)bp; bp = sp; sp = sp - *pc++;
ADJ : stack adjust 調整堆疊 sp = sp + *pc++;
LEV : leave subroutine 離開副程式 sp = bp; bp = (int *)*sp++; pc = (int *)*sp++;
LI : load int 載入整數 a = *(int *)a;
LC : load char 載入字元 a = *(char *)a;
SI : store int 儲存整數 *(int *)*sp++ = a;
SC : store char 儲存字元 a = *(char *)*sp++ = a;
PSH : push 推入堆疊 *--sp = a;
OR : a = a OR pop pop 代表從堆疊中取出一個元素 a = *sp++ | a;
XOR : a = a XOR pop a = *sp++ ^ a;
AND : a = a AND pop a = *sp++ & a;
EQ : a = a EQ pop a = *sp++ == a;
NE : a = a NE pop a = *sp++ != a;
LT : a = a LT pop a = *sp++ < a;
GT : a = a GT pop a = *sp++ > a;
LE : a = a LE pop a = *sp++ <= a;
GE : a = a GE pop a = *sp++ >= a;
SHL : a = a SHL pop a = *sp++ << a;
SHR : a = a SHR pop a = *sp++ >> a;
ADD : a = a ADD pop a = *sp++ + a;
SUB : a = a SUB pop a = *sp++ - a;
MUL : a = a MUL pop a = *sp++ * a;
DIV : a = a DIV pop a = *sp++ / a;
MOD : a = a MOD pop a = *sp++ % a;
EXIT : 終止離開 return *sp;
指令 意義 實作
OPEN: open a = open((char *)sp[1], *sp);
READ: read a = read(sp[2], (char *)sp[1], *sp);
CLOS: close a = close(*sp);
PRTF: printf t = sp + pc[1]; a = printf((char *)t[-1], t[-2], t[-3], t[-4], t[-5], t[-6]);
MALC: malloc a = (int)malloc(*sp);
FREE: free free((void *)*sp);
MSET: memset a = (int)memset((char *)sp[2], sp[1], *sp);
MCMP: memcmp a = memcmp((char *)sp[2], (char *)sp[1], *sp);