0

MARS & RARS contain a disassembler, but

  1. don't allow .word within .text
  2. will only disassemble the .text section

Is there a way to get these simulators to disassemble an instruction from hex?

(The common online disassemblers also don't support RISC V!)

Erik Eidt
  • 23,049
  • 2
  • 29
  • 53

1 Answers1

0

The following code sequence will make RARS/MARS disassemble from hex (RARS version here).  The program can be edited to use other instructions as hex, and, after running the program, disassembly can be seen in the "Text Segment" column "Basic".  The option for "Self-modifying code" must be enabled in the "Settings" menu.

    .data
WStart: 
    .word 0x00052283     # as many instructions in hex or other here as will fit in the nop's below
    .word 0xfae7d2e3
WEnd:
    .text
main:
    j next
CC0:                # after running the program,
    nop             # find disassembly here in the "Basic" column of the "Text Segment" window
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
next:
    la a0, WStart
    la a1, WEnd
    la a2, CC0
loop1:
    lw t0, (a0)
    sw t0, (a2)
    addi a0, a0, 4
    addi a2, a2, 4
    bne a0, a1, loop1
    
    li a7, 10
    ecall

enter image description here

Erik Eidt
  • 23,049
  • 2
  • 29
  • 53
  • So, if I understand correctly, self-modifying code is only deterministic on MIPS/RISC-V if you do it to code that's "behind" the current value of `$pc` as has been done here, due to pipelining. – puppydrum64 Jan 12 '23 at 12:07
  • We're not executing the self-modfying code, just disassembling it. – Erik Eidt Jan 12 '23 at 13:24
  • Ah, I see. You're just copying it over the `nop`s so that you can see what it is. – puppydrum64 Jan 30 '23 at 18:48