SH-2 question(s)

Ask anything your want about the 32X Mushroom programming.

Moderator: BigEvilCorporation

Post Reply
andlabs
Very interested
Posts: 62
Joined: Sat Aug 08, 2009 4:44 pm

SH-2 question(s)

Post by andlabs » Wed Jan 13, 2010 11:02 pm

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).

Snake
Very interested
Posts: 206
Joined: Sat Sep 13, 2008 1:01 am

Re: SH-2 question(s)

Post by Snake » Wed Jan 13, 2010 11:53 pm

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.

andlabs
Very interested
Posts: 62
Joined: Sat Aug 08, 2009 4:44 pm

Post by andlabs » Sat Jan 16, 2010 5:13 pm

Thanks! Does that also explain why the disassembler disassembles an instruction after the ret? And would I have to code like that myself?

Post Reply