English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 30 July 2016, 20:36   #1
iliak
Registered User

 
Join Date: Jan 2008
Location: somewhere
Posts: 34
vbcc bind a variable to a register

Hi
source code :
Code:
    __reg("d6") ULONG test = 10;
    tests++;
Asm output :
Code:
    moveq    #10,d0
    addq.l    #1,d0
command line :
Code:
vbccm68k -quiet "test.c" -o= "test.asm" -c99 -sc -cpu=68020  -O=1
What am I doing wrong to make test assigned to d6 ??
iliak is offline  
Old 31 July 2016, 06:11   #2
matthey
Banned
 
Join Date: Jan 2010
Location: Kansas
Posts: 1,284
Quote:
Originally Posted by iliak View Post
What am I doing wrong to make test assigned to d6 ??
I don't believe what you are trying to do is currently possible with the 68k vbcc backend. I don't believe it is possible to specify a register for a variable or even give a hint to the compiler to use a register for a variable (like GCC "register" variables). It is possible to specify a register for functions and inlines and it is possible to leave values in certain registers but vbcc will only use returns in d0 (d0/d1 for 64 bit returns). It is only possible to reserve a4 (when not in a function or inline) so vbcc doesn't use it although it doesn't look difficult to add support to reserve other registers. In general, what you are trying to do is not a good programming practice. If you do have a legitimate reason to do what you are doing then you may want to contact Volker Barthelmann.
matthey is offline  
Old 31 July 2016, 10:56   #3
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,538
The __reg() attribute only works for function arguments at the moment. You can still use __asm() to insert any kind of assembler code into a function you like:
Code:
  ...
  __asm("\tmoveq\t#11,d6");
  ...
phx is offline  
Old 31 July 2016, 11:20   #4
iliak
Registered User

 
Join Date: Jan 2008
Location: somewhere
Posts: 34
The idea is to rewrite the function RawDoFmt in C. It takes a callback function :
Code:
 PutChProc(Char (d0.w),  PutChData (a3));
I must send the arguments in the right registers.

My first (naive) try was in my question. Another approach, as suggest phx is to write some asm (I'll give it a try). Another way is maybe define the callback like this :
Code:
PutChrProc(__reg("d0") UBYTE Char, __reg("a3") APTR PutChData)
Any (better) idea ?
iliak is offline  
Old 31 July 2016, 11:29   #5
iliak
Registered User

 
Join Date: Jan 2008
Location: somewhere
Posts: 34
Quote:
Originally Posted by phx View Post
The __reg() attribute only works for function arguments at the moment. You can still use __asm() to insert any kind of assembler code into a function you like:
Code:
  ...
  __asm("\tmoveq\t#11,d6");
  ...
How can I set in a register the value of a variable :
Code:
ULONG test = 0x100;
__asm("\tmove.l test,d5");
?
iliak is offline  
Old 31 July 2016, 11:40   #6
thomas
Registered User
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 5,900
Quote:
Originally Posted by iliak View Post
Another way is maybe define the callback like this :
Code:
PutChrProc(__reg("d0") UBYTE Char, __reg("a3") APTR PutChData)
This is what you should do. It properly tells the compiler what to do. Everything else is dirty.
thomas is offline  
Old 31 July 2016, 13:29   #7
iliak
Registered User

 
Join Date: Jan 2008
Location: somewhere
Posts: 34
Seems to be a the solution :
Code:
typedef void (*callback)(__reg("d0") UBYTE, __reg("a3") APTR);
UBYTE t = '#';
APTR aptr = NULL;

callback cb = putChProc;
cb(t, aptr);
Thanks !
iliak is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Join variable and string in scripts. olesio support.Apps 3 31 January 2013 12:44
Speedy. The variable speed accellerator. DDNI Hardware mods 9 18 June 2012 22:33
NTSC variable-length scanlines TheDarkCoder Coders. Asm / Hardware 3 23 November 2011 16:51
Variable Master Clock wiltshireguyuk request.UAE Wishlist 0 13 December 2004 17:40
One RING to BIND them ALL. blobrana Amiga websites reviews 9 20 March 2003 09:40

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 15:54.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Page generated in 0.07049 seconds with 13 queries