-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefinitions.py
More file actions
104 lines (76 loc) · 2.72 KB
/
Definitions.py
File metadata and controls
104 lines (76 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from Instruction import *
"""
MOV AX, 6 reg, direct
MOV BX, label reg, direct
MOV AX, BX reg, reg
MOV CX, [AX] reg, ref
STOR AX, [BX] reg, ref
"""
MAXLABELNAMELENGTH = 12
addressingModes = {
"direct": 10,
"register": 11,
"reference": 12,
"indexed": 13
}
registers = {
"AX": 1,
"BX": 2,
"CX": 3,
"DX": 4,
"IX": 13,
"SP": 14,
"IP": 15,
}
datatypes = { "word" : 2, "byte" : 1, "string" : 0 }
"""
https://www.geeksforgeeks.org/program-execution-transfer-instructions-8086-microprocessor/?ref=lbp
flags: ZF, CF, OF, SF, PF, IF
"""
instructions = {
"MOV": Instruction("MOV", 0x0010, 2),
"CMP": Instruction("CMP", 0x0011, 2),
"ADD": Instruction("ADD", 0x0012, 2),
"SUB": Instruction("SUB", 0x0013, 2),
"MUL": Instruction("MUL", 0x0014, 2),
"DIV": Instruction("DIV", 0x0015, 2), # param1 = param1 / param2, Integer division, remainder in DX
"JMP": Instruction("JMP", 0x0016, 1),
"JZ": Instruction("JZ", 0x0017, 1), # if ZF = 1 then jump
"JNZ": Instruction("JNZ", 0x0018, 1), # if ZF = 0 then jump
"JO": Instruction("JO", 0x0019, 1), # if OF = 1 then jump
"JNO": Instruction("JNO", 0x0020, 1), # if OF = 0 then jump
"JC": Instruction("JC", 0x0021, 1), # if CF = 1 then jump
"JNC": Instruction("JNC", 0x0022, 1), # if CF = 0 then jump
"DEC": Instruction("DEC", 0x0023, 1),
"INC": Instruction("INC", 0x0024, 1),
"AND": Instruction("AND", 0x0025, 2),
"OR": Instruction("OR", 0x0026, 2),
"XOR": Instruction("XOR", 0x0027, 2),
"NOT": Instruction("NOT", 0x0028, 1),
"PUSH": Instruction("PUSH", 0x0029, 1),
"POP": Instruction("POP", 0x0030, 1),
"PUSHF": Instruction("PUSHF", 0x0031, 0),
"POPF": Instruction("POPF", 0x0032, 0),
"CALL": Instruction("CALL", 0x0033, 1),
"RET": Instruction("RET", 0x0034, 0),
"JL": Instruction("JL", 0x0035, 1), # if SF <> OF then jump
"JLE": Instruction("JLE", 0x0036, 1), # if SF <> OF or ZF = 1 then jump
"JG": Instruction("JG", 0x0037, 1), # if (ZF = 0) and (SF = OF) then jump
"JGE": Instruction("JGE", 0x0038, 1), # if SF = OF then jump
"STOR": Instruction("STOR", 0x0039, 2),
"SHL": Instruction("SHL", 0x0040, 1),
"SHR": Instruction("SHR", 0x0041, 1),
"NOP": Instruction("NOP", 0x00EE, 0),
"HLT": Instruction("HLT", 0x00FF, 0)
}
# https://www.programiz.com/python-programming/methods/string/find
def parseNumber(value: str):
if value.isnumeric():
return int(value)
if re.match("^0(x|X)([0-9A-Fa-f]{1,4})$", value):
value = value[2:]
return int(value, 16)
if re.match("^0(b|B)([0-1]{8}|[0-1]{16})$", value):
value = value[2:]
return int(value, 2)
return None