flat assembler
Message board for the users of flat assembler.

Index > Non-x86 architectures > HP Saturn

Author
Thread Post new topic Reply to topic
ldbeth



Joined: 15 Nov 2022
Posts: 2
ldbeth 19 Nov 2022, 18:14
I'm trying to build a cross assembler for HP50g calculator. 50g (and 49g) runs a HP Saturn emulator on 32bit ARMv4T. Although it is possible to run ARM on 50g, the entire OS is still based on the emulated HP Saturn instruction set. HP Saturn itself is nibble addressed, which can be demonstrated by this example program

Code:
    1             * -*- mode:sasm -*-
    2 00000 31FF        LCHEX FF
    3 00004 A6E   LOOP  C=C-1 B
    4 00007 5CF         GONC LOOP
    5 0000A 143         A=DAT1 A
    6 0000D 164         D0=D0+ 5
    7 00010 808C        PC=(A)
    8 00014             END
    


The assembly language is in the simple
Code:
Label Mnemonic Argument Comment    
format, each field separated by white space.

I could imaging it is possible to write each nibble as a byte, and do a post processing step to merge nearby two nibbles into one byte, my question would be if I can do that post processing in fasmg. The output format would be a header contains the number of nibbles in program, a block of machine codes, and a symbol table.

There is an open source assembler for HP Saturn written in C that also works for HP50g, but that was mainly targeted to HP48 series which lacks support to opcode exclusive to ARM emulated models, so it is only suitable for compiling System RPL which is essentially a variant of Forth which only requires the assembler to link with the symbol table to form a series of pointers.

All the opcode of HP Saturn are recorded at https://www.hpcalc.org/details/1693, including those specific to ARM based models.

The conventional mnemonics are not likely to work with fasmg, as arith symbols are involved, but I think I'm ok with come up a new set of mnemonics.
Post 19 Nov 2022, 18:14
View user's profile Send private message Visit poster's website Reply with quote
ldbeth



Joined: 15 Nov 2022
Posts: 2
ldbeth 19 Nov 2022, 18:18
A hexdump of the above assembly program is like:

Code:
0000000 6153 7574 6e72 0033 0002 0000 0014 0000
0000010 0000 0000 0000 5300 7461 4e20 766f 3120
0000020 2039 3231 313a 3a37 3330 3220 3230 2032
0000030 2020 2020 2020 2020 2020 2020 2020 2020
*
0000060 2020 2020 2020 2020 2020 2020 cc20 40db
0000070 0109 2020 2020 2020 2020 2020 2020 2020
0000080 2020 2020 2020 0020 0000 0000 0000 0000
0000090 0000 0000 0000 0000 0000 0000 0000 0000
*
0000100 ff31 e5a6 14cf 6431 8c80 0000 0000 0000  ; code starts here
0000110 0000 0000 0000 0000 0000 0000 0000 0000
*
0000200
    
Post 19 Nov 2022, 18:18
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 19 Nov 2022, 21:03
ldbeth wrote:
I could imaging it is possible to write each nibble as a byte, and do a post processing step to merge nearby two nibbles into one byte, my question would be if I can do that post processing in fasmg. The output format would be a header contains the number of nibbles in program, a block of machine codes, and a symbol table.
There are several options to consider, you may choose whichever is the best fit for your purpose.

The most classic one is to generate instructions into a virtual block, and then finally convert it into actual output:
Code:
Header dd code.nibbles ; etc.

virtual at 0
code::

postpone
        code.nibbles = $
        if $ and 1
                db 0
        end if
        end virtual
        repeat (code.nibbles+1)/2
                load low:byte from code:(%-1)*2
                load high:byte from code:(%-1)*2+1
                db low + high shl 4
        end repeat
end postpone    
You can also avoid a virtual block by using RESTARTOUT directive instead. This command prevents the previously generated bytes from going into the output file, but still allows to access them with LOAD:
Code:
code::

postpone ?
        code.nibbles = $
        if $ and 1
                db 0
        end if

        restartout

        Header dd code.nibbles ; etc.
        repeat (code.nibbles+1)/2
                load low:byte from code:(%-1)*2
                load high:byte from code:(%-1)*2+1
                db low + high shl 4
        end repeat
end postpone    
Here I used the variant of POSTPONE that allows to only perform the conversion in the final pass, this block is not executed unless all the previous code is already resolved.

Also, instead of postponing the conversion, you could implement the instructions to use a macro to output nibbles, which would lay them out into bytes immediately. And you can re-define the $ symbol to give a nibble-granular address:
Code:
$nibble = 0

$ equ ($? shl 1 - $nibble) ; $? allows to access built-in symbol instead of this re-defined one

macro nibble values&
        iterate n, values
                if $nibble = 1
                        load tmp : byte from $?-1
                        store tmp or (n) shl 4 : byte at $?-1
                else
                        db n
                end if
                $nibble = $nibble xor 1
        end iterate
end macro    
You may also need to intercept the labels and define them with nibble-based values, similar to how AVR example does it (but in the other direction). See also "How are the labels processed?" questions in the fasmg.txt.

The engine is flexible and there are many directions you could consider - but whichever variant you choose, it is going to require careful design and some relatively complex macros. The examples I've given here are very simplified.
Post 19 Nov 2022, 21:03
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.