HomeForumsWhat's newResources 
 
 
CyberWarriorX Blog : SH2 assembly optimizations
vbt - Aug 31, 2016
 vbt Aug 31, 2016

  
	
	
Through working on Princess Crown and more recently Langrisser III there’s been times where I’ve been working with tight code space. Sometimes you need to add a few instructions and you just have no space to put them. Anyways, here’s some areas I found where you can often optimize the code giving you a few extra precious bytes to work with:

Negative or high value word’s stored as long’s. Sometimes you run into following scenario:

mov.l my_label, r0
[more code here]
my_label: .long 0xFFFD

The data then is basically treated as a word for its entire use. It’s a bit inefficient since you should be able to store it as a word instead. Of course you may also have to deal with data alignment which may negate the savings. So a better approach instead is as follows:

mov #0xFD, r0
extu.w r0, r0


source : http://cyberwarriorx.com/sh2-assembly-optimization...

 paul_met Oct 8, 2016
Very useful information.
I think the next optimization is also possible:
Usually after the "jump" instructions (JSR, BSR, RTS...) should be NOP. So you can use this instruction. But we should remember that it will be executed before the "jump" instructions.
Code:
  
...
JSR Rm
Nop
...