Skip to content

Add Disassembler #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jul 12, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve/clean-up dissambled output format
Now the instruction (hex) and disassembled code will appear on one line
next to each other and the bytes are no longer printed with Python
specific formatting (not wrapped in b''). This results in a much cleaner
looking output.

Example output:

40008072  MOVE r0, 4
010000d0  LD r1, r0, 0
  • Loading branch information
wnienhaus committed Jul 2, 2023
commit b51677df56c4f9f3d6f1283d1fcfcc9761848879
14 changes: 9 additions & 5 deletions tools/disassemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,24 @@ def chunk_into_words(code, bytes_per_word, byteorder):
return words


def decode_instruction_and_print(i, verbose=False):
print(ubinascii.hexlify(i.to_bytes(4, 'little')))
def print_code_line(i, asm):
lineformat = '{0} {1}'
hex = ubinascii.hexlify(i.to_bytes(4, 'little'))
print(lineformat.format(hex.decode('utf-8'), asm))


def decode_instruction_and_print(i, verbose=False):
try:
ins, name = decode_instruction(i)
except Exception as e:
print(e)
print_code_line(i, e)
return

print(name)
print_code_line(i, name)

if verbose:
for field, val, extra in get_instruction_fields(ins):
print(" {:10} = {:3}{}".format(field, val, extra))
print(" {:10} = {:3}{}".format(field, val, extra))


def disassemble_manually(byte_sequence_string, verbose=False):
Expand Down