View Single Post
Old 21 March 2024, 16:55   #8
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,050
You can't multiply, shift, swap or split in some way, divide, and/or/eor/not/neg a relocatable address, you can only add or subtract a constant.
A very simple example... If your code looks like abc+$20, when you hexdump it you will see e.g. $00000320, and then in run-time when your program is loaded at e.g. address $120000, the loader will add that and then address will finally become $120320.
Because $120000 is the unknown at compile time.

So what in c/c++ looks like a simple solution, when you translate it to asm it won't necessarily end up being pretty. I feel little in the dark here, not seeing the whole picture...
If you have to do the swap multiple times, maybe load both pointers to aregs and use exg ax,ay?
Or use eor to swap, something like:
Code:
; a4=&buffer[0], d4=curr_offset
  eor.w #24,d4   ; swap
  lea (a4,d4.w),a0
; proceed to use a0
If it's a once per frame deal, have offset (d4) be in memory:
Code:
; e.g. if a5 is a base register pointing to my_data, otherwise use absolute addressing or pc-relative where possible
  eor.w #24,offset-my_data(a5)   ; swap
...
  lea buffer,a0
  add.w offset-my_data(a5),a0
; proceed to use a0
There are better ways to handle this than 32-bit pointer arithmetics, but it depends on the context.
a/b is online now  
 
Page generated in 0.04473 seconds with 11 queries