-
Notifications
You must be signed in to change notification settings - Fork 0
/
bit_operations.py
57 lines (39 loc) · 1.14 KB
/
bit_operations.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
from flag_register import setFlags
# add two numbers bit by bit and activate OF flag
def bitAddition(num1:int, num2:int, opSize, flags):
cfvalue = 1 if "CF" in flags else 0
result = num1 + num2 + cfvalue
flagsOn , flagsOff = [], []
# set Carry Flag
if result >= 2**opSize:
result -= 2**opSize
flagsOn.append("CF")
else:
flagsOff.append("CF")
# set Zero Flag
if result: flagsOff.append("ZF")
else: flagsOn.append("ZF")
# set Overflow Flag
setFlags(flagsOn,flagsOff)
return result
#? sub two numbers bit by bit and activate OF flag
def bitSubstraction(num1:int, num2:int, opSize, flags):
result = num1 - num2
flagsOn , flagsOff = [], []
#? flagi do ustawienia
setFlags(flagsOn,flagsOff)
return result
#? xor two numbers bit by bit and activate OF flag
def bitXOR(num1:int, num2: int, opSize, flags):
result = num1 ^ num2
flagsOn , flagsOff = [], []
#? flagi do ustawienia
setFlags(flagsOn,flagsOff)
return result
# binary multiplication
def binaryMultiplication(num1:int, num2: int, opSize, flags):
result = num1 * num2
flagsOn , flagsOff = [], []
#? flagi do ustawienia
setFlags(flagsOn,flagsOff)
return result