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: 70
Location: Russia
Jin X
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: 7782
Location: Kraków, Poland
Tomasz Grysztar
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: 70
Location: Russia
Jin X
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: 7782
Location: Kraków, Poland
Tomasz Grysztar
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: 70
Location: Russia
Jin X
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: 7782
Location: Kraków, Poland
Tomasz Grysztar
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: 70
Location: Russia
Jin X
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.