44 lines
899 B
Python
44 lines
899 B
Python
### Python script to generate specific instructions for testing
|
|
import struct
|
|
|
|
output_file = "test.out"
|
|
|
|
machine_code = bytes([
|
|
0xC5, 0x06, 0x34, 0x12, 0xFF, 0x1E, 0x34, 0x12, 0x9A, 0x78, 0x56, 0x34, 0x12, 0xEA, 0x78, 0x56, 0x34, 0x12, 0xFF, 0x1E, 0x34, 0x12, 0xFF, 0x2E, 0x34, 0x12
|
|
])
|
|
|
|
magic = b'\x01\x03'
|
|
flags = 0x20
|
|
cpu = 0x0
|
|
hdrlen = 0x20
|
|
unused = 0x00
|
|
version = 0
|
|
text = len(machine_code)
|
|
data = 0x00 # 4b
|
|
bss = 0x00 # 4b
|
|
entry = 0x00 # 4b
|
|
total = text + data + bss + entry # 4b
|
|
syms = 0x00 # 4b
|
|
|
|
# pack with LE
|
|
header = struct.pack('<2sBBBBHLLLLLL',
|
|
magic,
|
|
flags,
|
|
cpu,
|
|
hdrlen,
|
|
unused,
|
|
version,
|
|
text,
|
|
data,
|
|
bss,
|
|
entry,
|
|
total,
|
|
syms
|
|
)
|
|
|
|
with open(output_file, "wb") as f:
|
|
f.write(header + machine_code)
|
|
|
|
print(f"a.out written to: {output_file}")
|
|
|