flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > How using store ?

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1823
Roman 15 Apr 2023, 09:22
Fasmw 1.73
Code:
Virtual text "a tion"
store ;I want put symbol "c" in second char. How do this ?
    


I try this
Code:
virtual at 0
        hex_digits::
        db 'a ction',0
    end virtual 

load a byte from hex_digits:1
;but store not work
store byte a +5 at  hex_digits:1 ;ok
store byte a "c" at  hex_digits:1 ;fasm error
    


Last edited by Roman on 15 Apr 2023, 09:36; edited 1 time in total
Post 15 Apr 2023, 09:22
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 15 Apr 2023, 09:33
If the STORE is within the same addressing space (that is: before END VIRTUAL), you can do this quite directly:
Code:
virtual
        text db "a tion"
        store byte "c" at text+1
end virtual    
If you plan to use STORE from somewhere else, you need to have a name for this virtual area, defined as a "::" label. It doesn't matter where in the virtual block you put it, it labels the whole area, not a specific point within.
Code:
virtual
    area::
        text db "a tion"
end virtual

store byte "c" at area:text+1    

Note: these examples apply to both fasm 1 and fasmg. For fasmg this is a legacy syntax though, the new syntax would have <"c":byte> instead of <byte "c">.
Post 15 Apr 2023, 09:33
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20424
Location: In your JS exploiting you and your system
revolution 15 Apr 2023, 09:37
You have a bad value
Quote:
store byte a "c" at hex_digits:2 ;fasm error
That needs to be a single byte value. a "c" is not a valid byte. Did you mean a + "c" or just "c"?
Post 15 Apr 2023, 09:37
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1823
Roman 15 Apr 2023, 09:41
Thanks.
How put virtual text in data ?
Code:
;section data
virtual at 0
    area::
        text db "a tion",0
end virtual

textA area ;fasm error
    


I do this variant. Work
Code:
virtual at 0
    area::
        text db "a tion",0
end virtual

textAa:   rept 7 n:0 { load a byte from area:text+n
    store byte 'c' at  area:text+1    
    db a
         }
         db 0 
;now textAa db 'action',0 in data section.
    


Last edited by Roman on 15 Apr 2023, 09:55; edited 1 time in total
Post 15 Apr 2023, 09:41
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 15 Apr 2023, 09:55
With fasmg it could go like this:
Code:
virtual at 0
    area::
        text db "a tion",0
    area_size:
end virtual

load all: area_size from area:0
textA db all    
With fasm 1 a little more effort is needed, because you can only operate on small data units:
Code:
virtual at 0
    area::
        text db "a tion",0
    area_size:
end virtual

textA:
repeat area_size
  load a byte from area:%-1
  db a
end repeat    
(This obviously works with fasmg too, but there simpler and faster method is available.)
Post 15 Apr 2023, 09:55
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1823
Roman 15 Apr 2023, 09:57
Thanks.

rept not see area_size
repeat see area_size
Post 15 Apr 2023, 09:57
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20424
Location: In your JS exploiting you and your system
revolution 15 Apr 2023, 16:11
With the named virtual blocks if there is a non-numeric base we have to remember the register base when it is used later. If the load/store code is in a macro and has the "area" label passed as a parameter then it might be unknown to the macro how to correctly address the bytes.
Code:
virtual at edx
    area::
        text db "a tion",0
    area_size = $-edx
end virtual

repeat area_size
  load a byte from area: edx + % - 1 ; <--- we have to know the implicit edx register base
  db a
end repeat    
The named virtual blocks could be more flexible by supporting $$ and $.
Code:
virtual at edx
        area:: text db "a tion",0
end virtual

repeat area:$ - area:$$  ; <--- get start and end offsets without knowing any internal details
        load a byte from area:$$ + % - 1 ; <--- use $$ to get the base offset that may include non-numeric components
        db a
end repeat    
Post 15 Apr 2023, 16:11
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 15 Apr 2023, 17:48
fasmg allows "1 metadataof area" to get the base address of the block:
Code:
include 'cpu/x64.inc'

virtual at edx
    area::
end virtual

        mov     eax,[1 metadataof area] ; assembles to mov eax,[edx]    
I was planning to make the "0 metadataof area" (equivalent to "sizeof area") to get the current length, but it's not there yet. [EDIT: And now it is.]


Last edited by Tomasz Grysztar on 16 Apr 2023, 07:20; edited 1 time in total
Post 15 Apr 2023, 17:48
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1823
Roman 15 Apr 2023, 19:55
Mini c.
How convert text number to int ?
Code:
macro m1 { mov al,1  }
macro m2 { mov bl,2  }
macro ifcmd p1,p2,pp {
      load a p1 from cmdout:0
                if a = p2
                 display 13,10,'yes '#`p2
                 pp
                end if
      }
macro valCMD {
      repeat 300
  load a byte from area:cnt1+%-1+cnt0
  if a = ';'
   break
  end if
  store byte a at cmdout:cnt1+%-1
  display a
end repeat
}
macro nxtcmd { store qword '        ' at cmdout:0
               store qword '        ' at cmdout:8
               store qword '        ' at cmdout:16
repeat area_size
  load a byte from area:%-1+cnt0
  cnt2 = cnt0+%
  if a = ';'
   break
  end if
  end repeat
  cnt0 = cnt2
      }
macro fcmd {
      display 13,10
      repeat area_size
  cnt1 = %
  load a byte from area:%-1+cnt0
  if a = ' '
   break
  end if
  store byte a at cmdout:%-1
  display  a
end repeat
      }                     

virtual at 0
     area::
         text1 db 'for_ 551450022;',\
                  'next 44  ;',\
                  'deco ; ',0
     area_size:
end virtual
virtual at 0
     cmdout::
         text db 40 dup (32)
     cmdout_size:
end virtual      

;in code
cnt0 = 0
 fcmd
 valCMD
 ifcmd  dword,'for_',m1
 nxtcmd
 fcmd
 valCMD
 ifcmd  dword,'next',m1
 nxtcmd
 fcmd
 ifcmd  dword,'deco',m2
    
Post 15 Apr 2023, 19:55
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.