I finally got gcc set up on Linux and got my first working program sent to my new Prizm, but i'm wondering if there's a way outside of using inline assembly to assemble assembly programs for the Prizm.

EDIT: Also, is there any sort of emulator for the Prizm? I am probably very spoiled after so long with the 83/+ Wink
I wouldn't advise it, but GCC is smart enough to recognize when you feed it assembly source:

$ echo > stub.S << EOF
.global main
$ sh3eb-elf-gcc -o stub.o stub.S
$ sh3eb-elf-ld -o stub.bin -nostdlib -lfxcg -T../../toolchain/prizm.x -Wl,-static -Wl,-gc-sections
$ mkg3a stub.bin
That should generate an addin that does nothing from a single assembly source file.
You can also directly invoke gas, but that's more involved.

You'll need to be very careful to follow the ABI when using system facilities or interoperating with C code.

Casio have an emulator that's not free and doesn't emulate very accurately, and that's about it. Most of us do algorithmic debugging by cross-compiling code, and I built a minimal library (thread) that provides some libfxcg facilities as a kind of simulator, which was inspired by MPoupe's approach to the same.
Thanks, i'll test it out. And when you say you wouldn't advise it, do you mean using gcc or writing assembly? Is there some "better" way to assemble assembly source (i figure, if it works it works...). Thanks for the response.
I wouldn't advise writing straight assembly, that is.
Tari wrote:
I wouldn't advise writing straight assembly, that is.
I'm inclined to agree. Unless there's something you really have to write in straight assembly because there's no good way to do it in C, GCC does such an optimized job that even as a die-hard z80 ASM coder I trust it for my Prizm programs. Smile
Ah, right, well i got a Prizm just 'cuz i wanted to learn assembly for it since personally i enjoy assembly much more (on smaller machines, at least) than C/++ Smile I also put together ("copied") a little script from this site to make a listing file out of a C program (interweaved C/assembly translation), if anyone else cares to use it:

 gcc -c -g -Wa,-a,-ad $1.c > $1.lst
 gcc -O2 -S -c $1.c

EDIT: @Kerm: it's not that i don't trust it (i'm sure right now and for a long time coming that the code gcc produces will be much more optimized than my own assembly), i just enjoy it much more and wanted a more complicated machine than the 83+ to play with. I probably won't ever even release anything, it's just a toy to play with Very Happy
Chickendude, I certainly find that understandable. And even if you don't end up releasing your work, I hope you'll keep us posted on the nifty things you make, particularly if it leads you to find out more about the internals that we may not have discovered yet.
Now i'm trying to get a plain ASM file working (the "stub.S" file above) but now i keep getting a "cc1: error: unrecognized command line option "-fno-directives-only"" error. Anything i find online doesn't really talk about, or if it does it's waayy above my head. :/
How are you invoking gcc? Sounds like you're doing something that confuses it about what mode it should be compiling in (-fdirectives-only inhibits macro expansion in the preprocessor, so -fno-directives-only should be normal preprocessor behavior, but it's rather redundant).
Passing -v to GCC may also be useful to see what it's invoking internally.
"sh3eb-elf-gcc" and "sh3eb-elf-ld" weren't recognized, so i tried first copying those two files then the entire directory temporarily into /usr/bin, and that's where i get the error. Running the exact same commands you wrote above.

This is the output with the -v parameter:
~/PrizmSDK-0.3/projects/tut1$ sh3eb-elf-gcc -v -o stub.o stub.S
Using built-in specs.
Target: sh3eb-elf
Configured with: ../gcc/./configure --target=sh3eb-elf --prefix=/usr/local/cross --disable-nls --enable-languages=c,c++ --without-headers
Thread model: single
gcc version 4.6.2 (GCC)
COLLECT_GCC_OPTIONS='-v' '-o' 'stub.o'
cc1 -E -lang-asm -quiet -v -iprefix /usr/bin/../lib/gcc/sh3eb-elf/4.6.2/ stub.S -fno-directives-only -o /tmp/ccfbFGzX.s
cc1: error: unrecognized command line option "-fno-directives-only"
#include "..." search starts here:
#include <...> search starts here:
End of search list.
I'm not sure where that -fno-directives-only is coming from.
chickendude wrote:
so i tried first copying those two files then the entire directory temporarily into /usr/bin, and that's where i get the error.
That's probably the cause of the problem. It looks like a version mismatch between your frontend ('gcc') and the backend (cc1), which would be consistent with your SH compiler attempting to use your system's native cc1.
Add the directory containing your SH toolchain binaries to your PATH and get rid of the copies you made:

$ export PATH="$PATH:/usr/local/cross/bin"

The giveaway here is the search path for include files, which I can tell is wrong:
-iprefix /usr/bin/../lib/gcc/sh3eb-elf/4.6.2/
whereas gcc says it was configured to be installed in /usr/local/cross.
I'm not sure if i've made progress or not, but now i'm getting a different error:
sh3eb-elf-gcc -o stub.o stub.S
/usr/local/cross/lib/gcc/sh3eb-elf/4.6.2/../../../../sh3eb-elf/bin/ld: cannot find -lc
collect2: ld returned 1 exit status
My fault, you need to pass -c to gcc. It's trying to emit a complete binary and there's no libc to link against.
Awesome, thanks! Now the first step is working and i get my .o file. But what is "-Wl,-static"? It's complaining about that as well: "unrecognized option '-Wl,-static'".
Just me being absent-minded again. -Wl passes the following argument to the linker when invoking the compiler driver, but we're invoking ld directly, so just use -static.
Now it's complaining about "-lfxcg" :/
~/PrizmSDK-0.3/projects/tut1$ sh3eb-elf-ld -o stub.bin -nostdlib -lfxcg -T../../toolchain/prizm.x -static -gc-sections
sh3eb-elf-ld: cannot find -lfxcg
Try adding a -Lpath/to/libfxcg.a to that.
Edit: Before the -lfxcg, ideally.
Thanks, now it seems to find it, but again more errors:
"/home/crush/PrizmSDK-0.3/lib/libfxcg.a(crt0.o): In function `main':
(.pretext+0x50): undefined reference to `_main'"
Could you sneak this into the beginning of your code?

.global main
C (and related) programs start from a main function. You need to have what KermM posted above and put in your code there.
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 3
» All times are UTC - 5 Hours
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum