flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > CALM load and store

Author
Thread Post new topic Reply to topic
fabbel



Joined: 30 Oct 2012
Posts: 83
fabbel 19 Apr 2023, 15:04
Hi Tomasz,

Can u pls clarify
1/ what is meant by 'pre-compiled expressions', in the context of load and store CALM instructions
typ., reg load, doc says :
Quote:

The arguments to "load" are, in order: target variable, offset to load from, number of bytes to load. The first argument must be an identifier of a symbol, the latter two are pre-compiled expressions.


2/ typ., acceptable syntax for 2nd argument to load (or 1st argument to store), when need to refer to some specific addresss space area (i.e. using :: ...) ?
.. can u pls give concrete example

... doc says :
Quote:

The second argument may contain a label of the area, followed by ":" and then offset, or just a plain numeric expression, in which case it is an offset within entire output generated up to this point.

.. does that typ. mean like, assuming :
... some stuff ...
Some_Area::
... more stuff ...

... then in CALM, to load 1 byte into symbol c, from offset 16 in addresss space area 'Some_Area', we would do sthg like :
compute offset, 16
arrange offset, =Some_Area=:offset
load c, offset, 1

.... equiv to load c:1 from Some_Area:16 in macro syntax ??


[/i]
Post 19 Apr 2023, 15:04
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8346
Location: Kraków, Poland
Tomasz Grysztar 19 Apr 2023, 16:24
fabbel wrote:
1/ what is meant by 'pre-compiled expressions', in the context of load and store CALM instructions
This is expanded on in the beginning of the section:
16. Assembly commands in CALM instructions wrote:
They perform elementary operations, mostly on a single unit of data, but at the same time they can perform many calculations in-place, because their arguments, with few exceptions, are pre-compiled expressions, similar to the second argument to "compute".
Therefore the same rules that apply to COMPUTE, apply also here. The expression can be formed as usual, as a combination of symbols/literals and operators.

Whether you need more information depends on your use patterns and if you are likely to encounter some of the rarer interactions. For example, because the expression is pre-compiled, any references to symbols are frozen in place at the time of definition of CALM instruction. And text replacements (defined with DEFINE or EQU) are not applied when pre-compiling an expression, the expression keeps references to all these symbols and check their values at run-time, when the expression is evaluated. These details do matter only under specific circumstances, though.

The manual is organized in such way, that later sections often refer to things specified in the earlier ones, so if you're not reading it all consecutively, you may need to do a lot of jumping back.

fabbel wrote:
2/ typ., acceptable syntax for 2nd argument to load (or 1st argument to store), when need to refer to some specific addresss space area (i.e. using :: ...) ?
.. can u pls give concrete example
Yes, this section currently lacks necessary examples, because it is unfinished, as I have still not decided on all the inclusions of "CALM stage 3" expansion. I am certainly going to add some examples there in the future.

As mentioned in the first paragraph of this section, this set of commands allows each of the arguments to be a freely formed expression, so even though the commands themselves are elementary operations, the arguments are allowed to be complex. You specify everything directly, for example:
Code:
virtual
   Some_Area::
   db 'ABC'
end virtual

calminstruction demo
        local char
        load char, Some_Area: 0, 1
        display char+20h
end calminstruction

demo ; displays 'a'    
Be wary that the offset given to CALM command is an offset relative to the beginning of the area, no matter the addressing that the area uses for its labels. This differs from how the legacy LOAD works, and you can converted between offsets and addresses by adding or subtracting "1 metadataof area":
Code:
virtual at 1000h
   Some_Area::
   example db 'ABC'
end virtual

calminstruction demo address
        local char
        load char, Some_Area: address - 1 metadataof Some_Area, 1
        display char+20h
end calminstruction

demo example ; displays 'a'    
You should never need to use COMPUTE to prepare values for these commands, you can calculate everything directly in the arguments - that's what it means that they are all pre-compiled expressions.
Code:
HEADER_LENGTH := 0

calminstruction patch offset*, str*
        store HEADER_LENGTH+offset, lengthof str, str
end calminstruction

db "Example text"

patch 7+1, "here"    
And yet another example, this time a macro that loads the entire contents of given area (at this moment it requires the latest version of fasmg, at least "k0v2", because the size metadata of area label was not accessible this way in the earlier versions):
Code:
calminstruction (target) AreaContent? area*
        local string
        load string, area: 0, sizeof area
        publish target, string
end calminstruction

text AreaContent Some_Area
display text    
Post 19 Apr 2023, 16:24
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8346
Location: Kraków, Poland
Tomasz Grysztar 19 Apr 2023, 16:54
A more complex example from my own testing:
Code:
        file 'fasmg.exe'

        macro xorwithkey value*
                local   key
                virtual
                        key:: db string value
                end virtual
                xorout  key
        end macro 

        calminstruction xorout key_area
                local   offset, bytes, key, length
                compute length, sizeof key_area
                load    key, key_area:0, length
                compute offset, 0
            loop:
                check   offset = $%
                jyes    done
                check   offset + length <= $%
                jyes    xor
                compute length, $% - offset
                load    key, key_area:0, length
            xor:
                load    bytes, offset, length
                store   offset, length, bytes xor key
                compute offset, offset + length
                jump    loop
            done:
        end calminstruction

        xorwithkey 'fasmg'    
It XORs entire file with a repeating string.
Post 19 Apr 2023, 16:54
View user's profile Send private message Visit poster's website Reply with quote
fabbel



Joined: 30 Oct 2012
Posts: 83
fabbel 28 Apr 2023, 00:33
Hi again,

First, thx for prev feedback.

Now, another question:
is there a load/store syntax to specify access to current virtual area - w/o explicitely naming it ?
i.e. typ. :

Code:
macro test
   virtual at 0
   (...)

   calm_inx

   (...)
   end virtual
end macro

calminstruction calm_inx
   local _tmp

   load _tmp,????,10 ; ??? load 10 bytes from current area ??? 
end calminstruction
    


How can I direct load (or store) to operate on current area ?
I tried: load _tmp,0,10 to load 10 first bytes, but does not seem to work...
.. it looks like it is only able to operate on general output, even if calm_inx is enclosed in a virtual block (as in macro above)

tx
Post 28 Apr 2023, 00:33
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8346
Location: Kraków, Poland
Tomasz Grysztar 28 Apr 2023, 05:55
There is no way to access current area without having it labeled. Like most CALM instructions, these variants of LOAD/STORE have streamlined syntax and for anything out of its limited scope they require assistance.
Post 28 Apr 2023, 05:55
View user's profile Send private message Visit poster's website Reply with quote
fabbel



Joined: 30 Oct 2012
Posts: 83
fabbel 28 Apr 2023, 08:49
Ok.. not possible by design then. Tx
Post 28 Apr 2023, 08:49
View user's profile Send private message 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.