29 April 2017, 21:23 | #1 |
Registered User
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 |
30 April 2017, 01:30 | #2 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
|
Not entirely sure... It works fine here.
|
30 April 2017, 10:13 | #3 |
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 |
30 April 2017, 19:39 | #4 |
Registered User
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.
|
30 April 2017, 20:50 | #5 | |
Unregistered User
Join Date: Nov 2005
Location: Tasmania
Age: 42
Posts: 893
|
Quote:
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. |
|
30 April 2017, 20:59 | #6 |
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. |
30 April 2017, 21:40 | #7 | |
Registered User
Join Date: Apr 2016
Location: Perth, Australia
Posts: 384
|
Quote:
|
|
01 May 2017, 02:01 | #8 |
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.
|
01 May 2017, 16:21 | #9 |
Registered User
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
|
01 May 2017, 17:06 | #10 |
Registered User
Join Date: Oct 2008
Location: Finland
Posts: 643
|
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.
|
01 May 2017, 17:52 | #11 |
Registered User
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?
|
01 May 2017, 21:33 | #12 |
Registered User
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) |
02 May 2017, 00:14 | #13 |
Registered User
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.
|
02 May 2017, 20:38 | #14 | |
Unregistered User
Join Date: Nov 2005
Location: Tasmania
Age: 42
Posts: 893
|
Quote:
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. |
|
03 May 2017, 02:15 | #15 |
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.
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
|
|