English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 29 April 2017, 21:23   #1
Nightfox
Registered User
 
Nightfox's Avatar
 
Join Date: Apr 2016
Location: Perth, Australia
Posts: 384
Help with GetReg and PutReg

Hello guys

I was wanting help with being able to access the registers with putreg and getreg.

I expect the following code to output "The value in D1 is: 20" but instead it outputs "The value in D1 is: 0". What am I doing wrong here?

Code:
move.w #20,d1
PutReg d1,test.w
NPrint "The value in D1 is: ", test
Nightfox is offline  
Old 30 April 2017, 01:30   #2
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
Not entirely sure... It works fine here.
Attached Thumbnails
Click image for larger version

Name:	BlitzOutput1.png
Views:	100
Size:	1.9 KB
ID:	52940  
Daedalus is offline  
Old 30 April 2017, 10:13   #3
AlgoRythmic
Registered User
 
Join Date: Jun 2016
Location: MiggyLand
Age: 43
Posts: 13
Tested it and works fine in BB 2.1 also.
Did you try to declare the variable before using it in putreg?

like so:
Code:
test.w
move.w #20,d1
PutReg d1,test
NPrint "The value in D1 is: ", test
AlgoRythmic is offline  
Old 30 April 2017, 19:39   #4
Nightfox
Registered User
 
Nightfox's Avatar
 
Join Date: Apr 2016
Location: Perth, Australia
Posts: 384
OK the code seems to work except for when it's inside a statement. I wanted to do assembly inside a statement but it's not working for some reason.
Nightfox is offline  
Old 30 April 2017, 20:50   #5
Anakirob
Unregistered User
 
Anakirob's Avatar
 
Join Date: Nov 2005
Location: Tasmania
Age: 42
Posts: 893
Quote:
Originally Posted by sacredbanana View Post
OK the code seems to work except for when it's inside a statement. I wanted to do assembly inside a statement but it's not working for some reason.
Ript^DisasterArea came across this problem pretty early on when he was adding his assembly routines to our Blitz based engine. There were a couple of crude workarounds, I honestly cannot recall what they were though.

If you have the technical expertice you can make your own Blitz Commands library, but if it's just a routine that you only need to use in one particular program then this may be more trouble than it's worth.

Also don't be surprised when your code fails if you try to use all the registers. I cannot recall exactly which ones, but I'm pretty sure that we just stayed away from the upper four address and data registers as much as possible.
Anakirob is offline  
Old 30 April 2017, 20:59   #6
Cylon
Registered User
 
Join Date: Oct 2014
Location: Europe
Posts: 470
In a statement the registers d0-d5 are automatically set by the first 5 parameters given to the function. the rest goes onto the stack iirc. Also it is a good idea to 'unlk a4' at the beginning of the asm code and return with 'asmexit'.
i have to reread the chapter, but afaik that could be the problem somehow.
Cylon is offline  
Old 30 April 2017, 21:40   #7
Nightfox
Registered User
 
Nightfox's Avatar
 
Join Date: Apr 2016
Location: Perth, Australia
Posts: 384
Quote:
Originally Posted by Cylon View Post
In a statement the registers d0-d5 are automatically set by the first 5 parameters given to the function. the rest goes onto the stack iirc. Also it is a good idea to 'unlk a4' at the beginning of the asm code and return with 'asmexit'.
i have to reread the chapter, but afaik that could be the problem somehow.
I put a MouseWait after the NPrint line and when I do unlk a4 the NPrint reports the value as 16492 and as soon as I click the mouse the OS crashes with a software error.
Nightfox is offline  
Old 01 May 2017, 02:01   #8
Cylon
Registered User
 
Join Date: Oct 2014
Location: Europe
Posts: 470
Basically it is never a good idea to mix asm with BB2 cmds, especially when your setup seems to be messed up in some other way. When you are able to code in asm then keep it strictly asm and only return the result you need from the function. Avoid mixing e.g. Print (which involves several different libs) with the asm code. Probably the debugger gets fucked up while trying to figure out whats going on in there.
Cylon is offline  
Old 01 May 2017, 16:21   #9
Nightfox
Registered User
 
Nightfox's Avatar
 
Join Date: Apr 2016
Location: Perth, Australia
Posts: 384
I hope there is an easy workaround because otherwise I think I'll just stick with learning pure assembly
Nightfox is offline  
Old 01 May 2017, 17:06   #10
MickGyver
Registered User
 
MickGyver's Avatar
 
Join Date: Oct 2008
Location: Finland
Posts: 643
Quote:
Originally Posted by sacredbanana View Post
I hope there is an easy workaround because otherwise I think I'll just stick with learning pure assembly
As I understand from this thread, the problem with mixing assembly and basic is in statements. You can create statements with only assembly code in them, and call them from basic.
MickGyver is offline  
Old 01 May 2017, 17:52   #11
Nightfox
Registered User
 
Nightfox's Avatar
 
Join Date: Apr 2016
Location: Perth, Australia
Posts: 384
This is annoying but I can probably work with this. I just therefore need to know how to obtain the address of an array so I can put it in an address register. Anyone know how?
Nightfox is offline  
Old 01 May 2017, 21:33   #12
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
The address of any variable can be obtained using the & symbol:

Address.l = &MyVariable.w

You can't get an address for an array specifically, but you can get the address of the first element using:

Address.l = &MyArray(0)
Daedalus is offline  
Old 02 May 2017, 00:14   #13
Nightfox
Registered User
 
Nightfox's Avatar
 
Join Date: Apr 2016
Location: Perth, Australia
Posts: 384
Thanks so much! I just wrote an InsertionSort program in Blitz except the actual statement that does the actual sorting is in pure assembly! I used Blitz to read a text file containing a list of numbers and my assembly statement sorts the numbers.
Nightfox is offline  
Old 02 May 2017, 20:38   #14
Anakirob
Unregistered User
 
Anakirob's Avatar
 
Join Date: Nov 2005
Location: Tasmania
Age: 42
Posts: 893
Quote:
Originally Posted by Cylon View Post
Basically it is never a good idea to mix asm with BB2 cmds, especially when your setup seems to be messed up in some other way. When you are able to code in asm then keep it strictly asm and only return the result you need from the function. Avoid mixing e.g. Print (which involves several different libs) with the asm code. Probably the debugger gets fucked up while trying to figure out whats going on in there.
I seem to recall that setting up the display in Blitz, compiling the code and then dissassembling the code to use in a proper assembler seemed to be somewhat effective. Blitz can make some pretty fancy copper tricks quite easy to set up. But then there's the issue with mixing Blitz commands with ASM so this was how we approached the issue I seem to recall.

Also writing your own command library in 68k can be another thing you might like to consider.

Or assemble the routine you want into an executable, include it with IncBin and call it from your code is another approach to this problem.

But I have actually found that certain commands like JSR, LSL, etc. can be used instead of their Basic style equivalents no problems, just long and elaborate sections of 68K code will probably fail unless you are very careful.
Anakirob is offline  
Old 03 May 2017, 02:15   #15
Cylon
Registered User
 
Join Date: Oct 2014
Location: Europe
Posts: 470
'Careful' is the word of the day, imho. You have to understand how a compiler works: A simple cmd might cause a stack swap, malloc, register chg or whatever while you still think you are just swapping some asm register value or whatever.
Cylon is offline  
 


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

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:09.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.08851 seconds with 15 queries