Page 1 of 1

SH-2 question(s)

Posted: Wed Jan 13, 2010 11:02 pm
by andlabs
Hi. I'm disassembling some 32X code primarily for my own research purposes and I was wondering if you could help me with something I can't decipher, and the SH-2 docs don't help with this case:

Code: Select all

    mov #0,r0
    mov.w loc_whatever, r1
    braf r1 ; consider this at address 0x6789ABC)
; ...
loc_whatever: .data.w h'4567 ; example value
Would this jump to 0x6789ABC+0x4567 or to loc_whatever+0x4567 or to a different place? I tried the former case but it wound up with

Code: Select all

mov r0,@r0
which in this case would be illegal. Thanks!

PS - if this particular question isn't allowed, just feel free to delete it (someone pointed me to ask here).

Re: SH-2 question(s)

Posted: Wed Jan 13, 2010 11:53 pm
by Snake
It will jump to 0x6789ABC+0x4567+0x4.

This is a relative branch, so it takes the current Program Counter, adds your value, and jumps there.

The SH2 Program Counter is always 4 ahead of the instruction being executed due to pipelining.

Posted: Sat Jan 16, 2010 5:13 pm
by andlabs
Thanks! Does that also explain why the disassembler disassembles an instruction after the ret? And would I have to code like that myself?