-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocedural_array.py
More file actions
68 lines (56 loc) · 1.4 KB
/
procedural_array.py
File metadata and controls
68 lines (56 loc) · 1.4 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
stack = []
RAX = 0
R9 = 0
R10 = 0
R11 = 0
RSP = -1
def procedural_array(array_content, expr):
global stack, RAX, R9, R10, R11, RSP
R9 = expr
R10 = expr
while R10 > 0:
if isinstance(array_content, int):
stack.append(array_content)
RSP += 1
R11 += 1
else:
stack.append(R9)
RSP += 1
R11 += 1
stack.append(R10)
RSP += 1
R11 += 2
stack.append(R11)
RSP += 1
R11 = 0
procedural_array(array_content[0], array_content[1])
stack.append(RAX)
RSP += 1
R11 += 1
R9 = stack[-R11-3]
R10 = stack[-R11-2]
R11 += stack[-R11-1]
R10 -= 1
if not isinstance(array_content, int):
R8 = 0
while R10 < R9:
stack.append(RSP - R8 - 3 - R10)
RSP += 1
R11 += 1
R10 += 1
R8 += stack[RSP - R8 - 1 - R10]
R8 += 5
stack.append(R9)
RSP += 1
R11 += 1
RAX = RSP - 1 # Simulate the stack pointer
stack.append(R11)
RSP += 1
R11 += 1
def printstack(stack):
print("Stack contents:")
for i in range(len(stack)):
print(f" {i}: {stack[i]}")
print(f"RSP: {RSP}, RAX: {RAX}, R8: {R9}, R9: {R10}, R10: {R11}")
procedural_array(((0, 5), 5), 5)
printstack(stack)