Skip to content

Commit 10a5051

Browse files
committed
Add hex representation for any field value > 9
Some values are easier to read as hex values than as decimal. For example peripheral register addresses like 0x123 where the first digit (1) indicates which peripheral register to address, while the remaining 2 digits (0x23) are the offset within that register in number of 32-bit words. Also absolute JUMP addresses are easier to find via the hex value given that the disassembler includes the byte offset of each instruction in hex format.
1 parent 59766fb commit 10a5051

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

Diff for: tests/disassemble.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -150,22 +150,22 @@ def test_all_instructions():
150150
@test
151151
def test_instruction_field_decoding():
152152
# OPCODE_WR_REG = 1
153-
assert_decode_fields("000c8810", [ # REG_WR 0x0, 1, 2, 3
154-
('addr' , 0, ''),
153+
assert_decode_fields("230d8810", [ # REG_WR 0x123, 1, 2, 3
154+
('addr' , 35, ' (0x23)'),
155155
('data' , 3, ''),
156156
('high' , 1, ''),
157157
('low' , 2, ''),
158158
('opcode' , 1, ''),
159-
('periph_sel', 0, ''),
159+
('periph_sel', 1, ''),
160160
])
161161

162162
# OPCODE_RD_REG = 2
163-
assert_decode_fields("03000421", [ # REG_RD 0x3, 2, 1
164-
('addr' , 3, ''),
163+
assert_decode_fields("21030421", [ # REG_RD 0x321, 2, 1
164+
('addr' , 33, ' (0x21)'),
165165
('high' , 2, ''),
166166
('low' , 1, ''),
167167
('opcode' , 2, ''),
168-
('periph_sel', 0, ''),
168+
('periph_sel', 3, ''),
169169
('unused' , 0, ''),
170170
])
171171

@@ -558,21 +558,21 @@ def test_instruction_field_decoding():
558558
assert_decode_fields("090000a0", [ # TSENS r0, 0
559559
('delay' , 2, ''),
560560
('dreg' , 1, ''),
561-
('opcode' , 10, ''),
561+
('opcode' , 10, ' (0x0a)'),
562562
('unused' , 0, ''),
563563
])
564564

565565
# OPCODE_HALT = 11
566566
assert_decode_fields("000000b0", [ # HALT
567-
('opcode' , 11, ''),
567+
('opcode' , 11, ' (0x0b)'),
568568
('unused' , 0, ''),
569569
])
570570

571571
# OPCODE_LD = 13
572572
assert_decode_fields("060000d0", [ # LD r2, r1, 0
573573
('dreg' , 2, ''),
574574
('offset' , 0, ''),
575-
('opcode' , 13, ''),
575+
('opcode' , 13, ' (0x0d)'),
576576
('sreg' , 1, ''),
577577
('unused1' , 0, ''),
578578
('unused2' , 0, ''),

Diff for: tools/disassemble.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,15 @@ def get_instruction_fields(ins):
131131
)
132132
field_details = []
133133
for field in possible_fields:
134+
extra = ''
134135
try:
135136
# eval is ugly but constrained to possible_fields and variable ins
136137
val = eval('i.%s' % field, {}, {'i': ins})
138+
if (val>9):
139+
extra = ' (0x%02x)' % val
137140
except KeyError:
138141
continue
139-
extra = ''
142+
140143
if field == 'sel': # ALU
141144
if ins.sub_opcode == opcodes.SUB_OPCODE_ALU_CNT:
142145
extra = ' (%s)' % alu_cnt_ops[val]

0 commit comments

Comments
 (0)