flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Copy from real space to virtual

Author
Thread Post new topic Reply to topic
Jin X



Joined: 06 Mar 2004
Posts: 133
Location: Russia
Jin X 26 Mar 2020, 14:23
Hello.
How can I copy the code from real space to virtual one?

I can do it like this:
Code:
  len = $-start
  virtual at $100 as 'com'
    jmp copy
    dbg::
  end virtual
  repeat len
    load x byte from start+%-1
    virtual dbg
      db x
    end virtual
  end repeat
  virtual dbg
    copy:
  end virtual    

But it seems like I can do it more optimal.
Post 26 Mar 2020, 14:23
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8354
Location: Kraków, Poland
Tomasz Grysztar 26 Mar 2020, 14:31
Your snippet is compatible with both fasm 1 and fasmg, but I assume that you have fasm in mind. There you can load no more than 8 bytes at a time, so this the best you could do:
Code:
  repeat len / 8
    load x qword from start+(%-1)*8
    virtual dbg
      dq x
    end virtual
  end repeat
  repeat len mod 8
    load x byte from start+(len/8)*8+%-1
    virtual dbg
      db x
    end virtual
  end repeat    
With fasmg the are no limits on the length of loaded string, so you could do a simple:
Code:
  load x: len from start
  virtual dbg
    emit len: x
  end virtual    
Post 26 Mar 2020, 14:31
View user's profile Send private message Visit poster's website Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 133
Location: Russia
Jin X 26 Mar 2020, 14:59
So, I can't get access to real code inside virtual block?
Post 26 Mar 2020, 14:59
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8354
Location: Kraków, Poland
Tomasz Grysztar 26 Mar 2020, 15:04
Jin X wrote:
So, I can't get access to real code inside virtual block?
Oh, I did not realize that this is what you were asking for. You can do it as long as you use "format binary" and you need to use output offsets:
Code:
  start = $%
; ...
  len = $% - start
  virtual at $100 as 'com'
    jmp copy
    dbg::
    repeat len
      load x byte from :start+%-1
      db x
    end repeat
    copy:
  end virtual    
This is a feature that has been recently back-ported from fasmg.
Post 26 Mar 2020, 15:04
View user's profile Send private message Visit poster's website Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 133
Location: Russia
Jin X 26 Mar 2020, 15:40
Oh but can I write:
Code:
  start:
; ...
  startbyte = start-$$
  len = $ - start
  virtual at $100 as 'com'
    jmp copy
    dbg::
    repeat len
      load x byte from :startbyte+%-1
      db x
    end repeat
    copy:
  end virtual    
even if I have old fasm 1 ?
Post 26 Mar 2020, 15:40
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8354
Location: Kraków, Poland
Tomasz Grysztar 26 Mar 2020, 16:35
No, you need fasm 1.73.21 or higher.
Post 26 Mar 2020, 16:35
View user's profile Send private message Visit poster's website Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 133
Location: Russia
Jin X 26 Mar 2020, 17:10
Ok, thanks!
Post 26 Mar 2020, 17:10
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.