After having written some SH-2 code, I tried to assemble it with GNU as (specifically, sh-coff-as and sh-elf-as). It gave me the error message
Error: misaligned offset
on many lines. As it turns out, these were all instructions that use indirect register addressing with displacement, such as
mov.l @(3, r15), r1
The problem lies in the interpretation of the displacement value. According to the SH1/2 programming manual I have, the format of the instruction is (hope this comes out right)
MOV.L @(disp,Rm),Rn 0101nnnnmmmmdddd (disp x 4 + Rm) -> Rn
however, gas implements this as
MOV.L @(disp,Rm),Rn 0101nnnnmmmmdddd (disp + Rm) -> Rn
So in order to get my code to assemble, I had to multiply all the displacements by four; my suspicions were confirmed when gas managed to stick a 20 into four bits without complaining (though I later verified that it was correct with a hex editor 🙂).
Playing with disassemblers to see what the prevailing opinion was didn't help either: sh2d disassembled these to the gas syntax (for compatibility with gas maybe?), while shdis disassembled them to the syntax described in the manual. Is this a bug in gas, or a gas "feature"? Do I just have to put up with doing it the "wrong" way, or is there a good freeware SuperH assembler out there that uses the syntax described in the manual?
Error: misaligned offset
on many lines. As it turns out, these were all instructions that use indirect register addressing with displacement, such as
mov.l @(3, r15), r1
The problem lies in the interpretation of the displacement value. According to the SH1/2 programming manual I have, the format of the instruction is (hope this comes out right)
MOV.L @(disp,Rm),Rn 0101nnnnmmmmdddd (disp x 4 + Rm) -> Rn
however, gas implements this as
MOV.L @(disp,Rm),Rn 0101nnnnmmmmdddd (disp + Rm) -> Rn
So in order to get my code to assemble, I had to multiply all the displacements by four; my suspicions were confirmed when gas managed to stick a 20 into four bits without complaining (though I later verified that it was correct with a hex editor 🙂).
Playing with disassemblers to see what the prevailing opinion was didn't help either: sh2d disassembled these to the gas syntax (for compatibility with gas maybe?), while shdis disassembled them to the syntax described in the manual. Is this a bug in gas, or a gas "feature"? Do I just have to put up with doing it the "wrong" way, or is there a good freeware SuperH assembler out there that uses the syntax described in the manual?