Pure C scratch registers

GFA, ASM, STOS, ...

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

mikro
Hardware Guru
Hardware Guru
Posts: 1943
Joined: Sat Sep 10, 2005 11:11 am
Location: Kosice, Slovakia
Contact:

Pure C scratch registers

Postby mikro » Fri Apr 19, 2019 6:11 pm

For a world I can't find an exact description of this: I do know that Pure C uses d0-d2 and a0-a1 as its calling convention but what about guaranties for preserving register content? gcc has this well defined but for Pure C I'm finding only information about calling convention what isn't the same thing.

So in other words, when calling a C function from assembler, which registers do I have to save?

czietz
Hardware Guru
Hardware Guru
Posts: 918
Joined: Tue May 24, 2016 6:47 pm

Re: Pure C scratch registers

Postby czietz » Fri Apr 19, 2019 7:31 pm

According to the manual, the function that is called needs to save D3-D7, A2-A6 and FP3-FP7 if it modifies them. I.e., when calling a C function, the compiler should have taken care of saving the registers. On the other hand, when calling an assembler function from C, the assembler function needs to save the registers listed above.

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2462
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: Pure C scratch registers

Postby charles » Fri Apr 19, 2019 7:32 pm

doesn't the ataris bios xbios gemdos etc use registers too?
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!

mikro
Hardware Guru
Hardware Guru
Posts: 1943
Joined: Sat Sep 10, 2005 11:11 am
Location: Kosice, Slovakia
Contact:

Re: Pure C scratch registers

Postby mikro » Fri Apr 19, 2019 8:11 pm

czietz: thank you very much for clarification.

ThorstenOtto
Atari Super Hero
Atari Super Hero
Posts: 582
Joined: Sun Aug 03, 2014 5:54 pm

Re: Pure C scratch registers

Postby ThorstenOtto » Fri Apr 19, 2019 11:20 pm

@charles: Atari bios/xbios/gemdos uses (clobbers) d0-d2/a0-a2. So when invoking traps from PureC, you have to save/restore also A2 since the compiler expects it to be unchanged after the call.

@mikro: same calling convention of course also applies when you call a C function from assembler: in that case you have to be prepared that d0-d2/a0-a1 might be clobbered, no matter whether they are used for passing parameters.


Social Media

     

Return to “Coding”

Who is online

Users browsing this forum: No registered users and 2 guests