-
Notifications
You must be signed in to change notification settings - Fork 0
/
op1arg.py
68 lines (45 loc) · 1.69 KB
/
op1arg.py
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
from registers_operation_check import registerAddressValue,\
additionalOpReq, getValue, saveInDestination, getMaxSize
from flag_register import getRequiredFlags
from op2arg import SUB, ADD
from stack import saveValueToStack, readFromStack
from multipurpose_registers import readFromRegister
from extration_of_data import bitsToInt
def EXE1ARG(function, s : str = ""):
# verification the type of the arguments
sMode = registerAddressValue(s)
#? verification ???
name = function.__name__
additionalOpReq(name, None, s, None, sMode)
# specifies maximum size of the operation (8/16)
maxSize = getMaxSize(s, sMode)
# get values no matter where they are stored
sValue = getValue(s, sMode, maxSize)
# does this operation requires taking into accout some flags
reqFlags = getRequiredFlags(name)
# performa opperations
result = function(sValue, maxSize, reqFlags)
if name not in ["saveValueToStack"]:
saveInDestination(s, sMode, result)
### INSTRUCTION WITH 1 ARGUMENT
# increment register by 1 (ADD register, byte 1)
def INC(r : str) -> None:
ADD(r,"byte 1")
# decrement register by 1 (SUB register, byte 1)
def DEC(r : str) -> None:
SUB(r,"byte 1")
# save value to stack
def PUSH(v : str) -> None:
EXE1ARG(saveValueToStack,v)
# pop value from stack to the destination d
def POP(d : str) -> None:
# verification the type of the arguments
dMode = registerAddressValue(d)
#? verification ???
additionalOpReq("pop", "stack", d, None, dMode)
# specifies maximum size of the operation (8/16)
maxSize = getMaxSize(d, dMode)
if type(maxSize) != int: maxSize = 16
index = bitsToInt(readFromRegister("SP"))
result = bitsToInt(readFromStack(8*index, maxSize))
saveInDestination(d, dMode, result)