Grevle Posted July 7, 2016 Share Posted July 7, 2016 (edited) This question is about using assembler programs with the use of the USR command within turbo basic. So i did get this to work when my assembler program was simpler. When using a USR command :example (K=USR (35000). then you have to use one PLA in the assembler program for the stack. When one needs go back to basic, A RTS command with no attachments should bring the program back to Basic at the line after of the USR command that where issued in Basic. It worked at first but now my Assembler program seem to get to complicated so a RTS wont bring it back to basic. i tried som PLA,s but that doesnt work. So when using USR does this put a return adress on the stack so that when using RTS in assembler this is how it knows where to return to in Basic ?. Maybe my assembler program messes up the stack somehow. Is there a way to find out exacly witch adress is put on the stack by Basic and the somehow Manually push that adress onto the stack when needed ? Would a CRC command remove the Basic return info from the stack. I tried tracing my program buts it seems very difficult to resolve the issue. Edited July 7, 2016 by Grevle Quote Link to comment Share on other sites More sharing options...
Rybags Posted July 7, 2016 Share Posted July 7, 2016 Debugger in emulation can be helpful here. The first PLA in your program pulls a number which is = the number of extra parameters that are on the stack, this number will always be present whether you've supplied extra parameters or not. Careful programs will check this and pull everything and only everything needed (each parameter is 2 extra bytes to PLA from the stack) but most only do what they need to. The only time Basic ever directly manipulates the Stack pointer is when it starts up. Otherwise the changing of the stack pointer is just as would be expected from JSR/RTS/PHA/PLA etc. The operative thing for your assembler routine is that it should always do at least 1 PLA. If extra parameters are present then there's 2 PLAs for each of those. Whether your program puts in the effort to check the right number of parameters are present is up to you. But so long as your Basic program and assembly routine are doing things such that the stack level isn't corrupted then you should be OK. If you're really paranoid about it, this would be a bit of a kludge but you could do something like: PLA ; get # of parameters STA PARMS TSX STX SAVESP ; retain stack level ; ; rest of routine here ; LDX SAVESP TXS RTS ; back to Basic Quote Link to comment Share on other sites More sharing options...
Grevle Posted July 7, 2016 Author Share Posted July 7, 2016 Ok so SAVESP is a memory location equate to store the return stack info ? Thank you. Il give it a try Quote Link to comment Share on other sites More sharing options...
Grevle Posted July 7, 2016 Author Share Posted July 7, 2016 Yes . It worked ..Thanks a lot. actually very helpful to know this when using assembler programs within Basic Quote Link to comment Share on other sites More sharing options...
Rybags Posted July 7, 2016 Share Posted July 7, 2016 You'd do well to work out why it wasn't working. That method is OK if you've left stuff on the stack. If you've pulled too much off the stack then there's the real prospect of corruption so wrong data would be there when you return. Quote Link to comment Share on other sites More sharing options...
Grevle Posted July 7, 2016 Author Share Posted July 7, 2016 Yes. well the program works now as it should with multiple jumps back and forth between Basic and assembler so its probably some stuff left on the stack that was the issue, probably i guess so. Thanks for the help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.