添加一些指令设想
This commit is contained in:
39
cpu.py
39
cpu.py
@@ -24,6 +24,9 @@ class cpu(object):
|
||||
self.sp=self.mem_addr
|
||||
self.rp=self.pc
|
||||
self.fp=self.sp
|
||||
self.regs=[]
|
||||
for i in range(32):
|
||||
self.regs.append(0)
|
||||
def get_value(self,addr:int,size:int):
|
||||
if not (size in [1,2,4,8]):
|
||||
raise Exception(f"CPU 异常 因为地址未对齐 {size}")
|
||||
@@ -81,3 +84,39 @@ class cpu(object):
|
||||
return ret
|
||||
|
||||
|
||||
# 数据操作指令 1000_xxxx_0000_0000_0000_0000_0000_0000
|
||||
# 加法指令 1000_0001_src1[8]_src2[8]_dst[8]
|
||||
# 减法指令 1000_0010_src1[8]_src2[8]_dst[8]
|
||||
# 乘法指令 1000_0011_src1[8]_src2[8]_dst[8]
|
||||
# 除法指令 1000_0100_src1[8]_src2[8]_dst[8]
|
||||
# 按位与指令 1000_0101_src1[8]_src2[8]_dst[8]
|
||||
# 按位或指令 1000_0110_src1[8]_src2[8]_dst[8]
|
||||
# 按位异或指令 1000_0111_src1[8]_src2[8]_dst[8]
|
||||
# 复制数据指令 1000_1000_0000_0000_src[8]_dst[8]
|
||||
# 左移数据指令 1000_1001_shit[8]_src[8]_dst[8]
|
||||
# 右移数据指令 1000_1010_shit[8]_src[8]_dst[8]
|
||||
# 取反指令 1000_1011_0000_0000_src[8]_dst[8]
|
||||
|
||||
# 数据搬运指令 1001_xxxx_0000_0000_0000_0000_0000_0000
|
||||
# 从内存绝对地址搬运数据到指定寄存器,mem_addr_reg是要保存在内存的地址
|
||||
# 1001_0001_0000_0000_reg[8]_mem_addr_reg[8]
|
||||
# 从指定寄存器搬运数据到内存,mem_addr_reg是要保存在内存的地址
|
||||
# 1001_0010_0000_0000_reg[8]_mem_addr_reg[8]
|
||||
|
||||
# 跳转指令 1010_xxxx_0000_0000_0000_0000_0000_0000
|
||||
# 无条件跳转指令 跳转地址保存在reg中
|
||||
# 1010_0000_0000_0000_0000_0000_reg[8]
|
||||
# 在指定寄存器为0时跳转
|
||||
# 1010_0001_0000_0000_juge_reg[8]_reg[8]
|
||||
# 在指定寄存器不为0时跳转
|
||||
# 1010_0010_0000_0000_juge_reg[8]_reg[8]
|
||||
|
||||
|
||||
class instruction(object):
|
||||
def __init__(self) -> None:
|
||||
self.jmp
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user