Saturn ASM question
12-28-2017, 03:32 PM
Post: #1
 grsbanks Senior Member Posts: 1,219 Joined: Jan 2017
Saturn ASM question
Hi all,

I've been taking advantage of some time off work between Christmas and the New Year to come to grips with both SysRPL and ASM programming on the HP 50g. My learning material for the latter is the excellent "Introduction to Saturn Assembly Language" by Gilbert Fernandes and Eric Rechlin. I'm basically copy/pasting source code strings from my text editor onto the stack of an emulated HP 50g and running ASM to get executable code. I do have extable installed both on the emulator and on my physical 50g to make things that much easier.

My question is, how do I make use of pointers to the built-in real numbers in ASM?

I'm (finally...) writing a bunch of archival utilities, including one that tests for the presence of an SD card and returns either 1. or 0. to the stack using code such as this:

Code:
LC 2F94C % %1 D=D-1 A D1=D1- 5 DAT1=C A

Fairly straightforward. Load the address of %1 (\$2F94C on the 49/50) into C, decrement the number of 5-nibble blocks available, decrement the stack pointer and place the address in C on the top of that stack.

This code will never run on a 48 so it's not a problem in this instance, however I'd be happier if I could use the symbol defined in extable rather than the literal 2F94C. How do I do that? This is probably just a question of syntax that I haven't yet managed to figure out.

"LC %1" is clearly not the way because the "%" sign introduces a comment...

12-28-2017, 03:53 PM
Post: #2
 pier4r Senior Member Posts: 2,076 Joined: Nov 2014
RE: Saturn ASM question
(12-28-2017 03:32 PM)grsbanks Wrote:  I'm (finally...) writing a bunch of archival utilities, including one that tests for the presence of an SD card and returns either 1. or 0.

I guess that every user that uses the 50g daily may use them. I personally have to improve my archival utilities (userRPL, userRPL + SDLIB) as well but wouldn't be bad if you share when you get some good results (even alpha works)!

(This is valid also for other people. If you working backup programs, please share! I shared mine in the little explorations thread).

Wikis are great, Contribute :)
12-28-2017, 04:32 PM
Post: #3
 DavidM Senior Member Posts: 835 Joined: Dec 2013
RE: Saturn ASM question
The exact syntax may vary depending on how you are compiling your code. I use the Debug4x environment (which in turn uses HP's SASM compiler), and loading a previously defined address constant into C.A inside a MASD code object would look like this:

Code:
 CODEM    LC(5) =%1 ENDCODE

The "(5)" specifies the width (in nibbles) of the data to be loaded into C. "=" designates that the constant ID which follows is a global label (as opposed to local). The "%" isn't interpreted here as a comment token by the parser.

Also, a word of caution: pushing new stack items in your relocatable Saturn code requires care. In this particular situation, your chance for a problem is remote since about the only thing that could cause a (memory-related) problem is the stack being completely full prior to execution. The more common scenario, though, is that of a TEMPOB allocation occurring as a result of some process. I generally try to allocate "placeholders" at SysRPL-time prior to calling the Saturn code, which then simply updates the placeholder objects as needed (and drops no-longer-needed stack items).
12-28-2017, 04:51 PM
Post: #4
 grsbanks Senior Member Posts: 1,219 Joined: Jan 2017
RE: Saturn ASM question
Thanks for the reply but nope.

It balks completely on the "(5)" in "LC(5) =%1".

If I omit "(5)" and just use "LC =%1" it bails out demanding a HEX expression.

Also, I've been doing necessary memory checks before pushing something onto the stack. Bad Things(tm) can happen without that
12-28-2017, 05:14 PM
Post: #5
 grsbanks Senior Member Posts: 1,219 Joined: Jan 2017
RE: Saturn ASM question
FWIW this is the code so far:

Code:
% Do we have room for one more level on the stack? ?D#0 A GOYES CANDO LA 00001 GOVLNG =Errjmp *CANDO P= 8 ACCESSSD P= 0 % Space on SD card or error (negative value) should be in lower 8 nibbles of A % Test bit 31 of A % Shift A right by 4 nibbles ASR W ASR W ASR W ASR W % Is bit 15 set? ?ABIT=1 15 GOYES NOSDCARD LC 2F94C % %1 *PUSHRESP D=D-1 A D1=D1- 5 DAT1=C A % We're done A=DAT0 A D0=D0+ 5 PC=(A) *NOSDCARD LC 2F937 % %0 GOTO PUSHRESP @
12-28-2017, 05:48 PM
Post: #6
 DavidM Senior Member Posts: 835 Joined: Dec 2013
RE: Saturn ASM question
(12-28-2017 04:51 PM)grsbanks Wrote:  Thanks for the reply but nope.

It balks completely on the "(5)" in "LC(5) =%1".

If I omit "(5)" and just use "LC =%1" it bails out demanding a HEX expression.

Apologies, I missed in your first post that you were using the built-in ASM command to compile. I'm no expert in the built-in ASM syntax, but the following appears to compile (though I haven't tested it):
Code:
LC(5)"%1"

FWIW, the syntax I used previously is perfectly acceptable to SASM.
12-28-2017, 05:57 PM
Post: #7
 grsbanks Senior Member Posts: 1,219 Joined: Jan 2017
RE: Saturn ASM question
(12-28-2017 05:48 PM)DavidM Wrote:
Code:
LC(5)"%1"

Bingo! That did it. Many thanks for your help.
12-28-2017, 06:03 PM
Post: #8
 grsbanks Senior Member Posts: 1,219 Joined: Jan 2017
RE: Saturn ASM question
Source code updated to the following:

Code:
% Do we have room for one more level on the stack? ?D#0 A GOYES CANDO LA 00001 GOVLNG =Errjmp *CANDO P= 8 ACCESSSD P= 0 % Space on SD card or error (negative value) should be in lower 8 nibbles of A % Test bit 31 of A % Shift A right by 4 nibbles ASR W ASR W ASR W ASR W % Is bit 15 set? ?ABIT=1 15 GOYES NOSDCARD % We do have an SD card so push 1. onto the RPL stack LC(5)"%1" *PUSHRESP D=D-1 A D1=D1- 5 DAT1=C A % We're done, move on to the next object in the run stream A=DAT0 A D0=D0+ 5 PC=(A) % No SD card found so push 0. onto the RPL stack *NOSDCARD LC(5)"%0" GOTO PUSHRESP @
12-29-2017, 04:56 PM
Post: #9
 DavidM Senior Member Posts: 835 Joined: Dec 2013
RE: Saturn ASM question
That's looking good, grsbanks!

I hope you don't mind if I offer a similar function -- not because I think it's better, but simply to introduce some different approaches for your consideration.

As mentioned earlier, I like to pre-load the stack with placeholders while still in the SysRPL environment if possible. Especially when the possible results are clearly defined as in this case, which then keeps you from having to worry about memory allocations or error conditions within the Saturn code (where it usually has a larger memory footprint). Additionally, this example shows an alternative method to test the bit in question:

Code:
!NO CODE !RPL ::   ( no arguments expected )   CK0NOLASTWD   ( assume SD card is present )   %1   CODE     % returns space available or negative error code if card not present in     % low-order 8 nibbles of A     P= 8     ACCESSSD     P= 0     % shift high bit of result into bit 0     C=0 W     LC 1F     A=A>C W     % if bit 0 of A is 1, an error occurred (assume no SD card)     % this simply changes the SL1 pointer to now reference %0 instead of %1     ?ABIT=1 0 ->{       LC(5)"%0"       DAT1=C A     }     % return to RPL     RPL   ENDCODE ; @

Note that this example uses an opcode for shifting the A register which is only available on the ARM-based systems (aka "the Saturnator"). That shouldn't be a problem here, as this function is already limited in scope to those systems anyway.
12-30-2017, 12:11 AM
Post: #10
 grsbanks Senior Member Posts: 1,219 Joined: Jan 2017
RE: Saturn ASM question
(12-29-2017 04:56 PM)DavidM Wrote:  I hope you don't mind if I offer a similar function -- not because I think it's better, but simply to introduce some different approaches for your consideration.

I like it

As you say, the choice of instructions isn't a problem. I'm already using "ACCESSSD" in there and that is only available on the Saturn+ as well.
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)