Posté le 29/07/2020 21:16
Planète Casio v4.3 © créé par Neuronix et Muelsaco 2004 - 2024 | Il y a 205 connectés | Nous contacter | Qui sommes-nous ? | Licences et remerciements
Planète Casio est un site communautaire non affilié à Casio. Toute reproduction de Planète Casio, même partielle, est interdite.
Les programmes et autres publications présentes sur Planète Casio restent la propriété de leurs auteurs et peuvent être soumis à des licences ou copyrights.
CASIO est une marque déposée par CASIO Computer Co., Ltd
Citer : Posté le 29/07/2020 21:20 | #
I see so you store data and code within the G1A header to save space? Nice compacity trick!
The assembler is unable to construct a PC-relative address for _main since it is in a different compilation unit.
Citer : Posté le 29/07/2020 21:21 | #
Ah, so how could you get around that problem? I honestly don't know much about assembly or linking.
Citer : Posté le 29/07/2020 21:23 | #
The way to go is exactly as you did - create a reference to the symbol that the linker can resolve and substitute, then load it and call it. This is a very common structure in all SuperH assembly code to call external functions.
Citer : Posté le 29/07/2020 21:27 | #
Yeah, but it would be nice to only do
nop
since that would save some bytes at the end
For example, the main code is always located at offset 0x22, so is it possible to hard-code the value instead?
Citer : Posté le 29/07/2020 21:31 | #
You can do mov #22, r0; jmp @r0; nop, or since you also know the offset of the entry point (0x200), you can also do bra @(offset,pc) where offset is 0x200 - 0x22 - 4. (The -4 is because PC points 4 bytes after the current instruction.)
Citer : Posté le 29/07/2020 21:42 | #
For the first one I would need the full address as a long, which is basically what I'm doing already. For the second one, I get a bad expression error If I try to manually write the displacement value, like so:
I get this very cryptic error message:
Citer : Posté le 29/07/2020 22:11 | #
The first one saves you the .long which is a 4-byte gain. Not optimal, but still something.
As for the second one, the error messages means that the linker, while attempting to adjust the target of bra after selecting the location of the _entry and _main functions, found itself confronted to the problem that the argument of bra only has 12 bits (this particular case of adjusting addresses is named R_SH_IND12W) and the value to be put here did not fit.
This reason it did not fit is because it is absolute (ie. it starts counting at the 0 of the address space) instead of being relative to either the file header, or a program section, or a symbol. You should provide a relative address suitable for relocation by using a different format.
bra start - 0x200 + 0x22
nop
The @(offset,pc) I mentioned earlier does not work here, sorry for the confusion.
Citer : Posté le 29/07/2020 22:22 | #
Perfect, thanks
worked for me! This brought the size down to 516 bytes.
Citer : Posté le 29/07/2020 22:24 | #
Good catch, now this can't be made any more compact since all 1-instruction jumps (bt/bf) are conditional.