flat assembler
Message board for the users of flat assembler.

Index > Windows > A little question about string

Author
Thread Post new topic Reply to topic
pearlz



Joined: 07 Jun 2010
Posts: 55
Location: Viet Nam
pearlz 25 Jun 2010, 07:49
Hi everybody!, i'm a new bie, i have a little problem in my project
it can't run
Code:
format pe gui 4.0
include 'win32ax.inc'

macro copy   des, sour
{
   if sour eqtype ""
      local  lcl
      jmp  @f
      lcl     db    sour,0
      @@:
      mov    des,lcl
   else
      mov    des,sour
   end if
   ;invoke MessageBox,0,des,des,MB_OK

}
.code
start:
        copy    Title,'Hello World'
        invoke  MessageBox,0,Title,Title,MB_OK
        invoke  ExitProcess,0
.end start
section 'data' data readable writeable
dataA       rb      4*1024*1024
wc      WNDCLASS
Title       rb      20
    

with 'Win32ax.inc' i can MessageBox,0,'Hello World','Hello',MB_OK
but i want use macro copy
how to i fix it?
thank all.

_________________
welcome to VietNam!
Post 25 Jun 2010, 07:49
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel 25 Jun 2010, 09:19
You expect a single mov instruction to copy 11 characters all at once? Check the movsb instruction (<- first Google result I got), and use it with the rep instruction after setting up the esi, edi and ecx registers properly.
But you'd better do this with a procedure/subroutine instead of a macro.

Or maybe just use
Code:
invoke  MessageBox,0,"My message text","My title caption",MB_OK    

and fasm will do the rest, i.e. what you're trying to do with your copy macro.
Post 25 Jun 2010, 09:19
View user's profile Send private message Reply with quote
pearlz



Joined: 07 Jun 2010
Posts: 55
Location: Viet Nam
pearlz 25 Jun 2010, 10:20
Thank's
but i want copy const string to other varible string
please tell me, how to I do it?
Post 25 Jun 2010, 10:20
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 790
Location: Massachusetts, USA
bitshifter 25 Jun 2010, 10:24
macro is for assembly time, code is for run time...
Code:
mov esi,_src_block
mov edi,_dst_block
mov ecx,_block_size
cld
rep movsb
    
Post 25 Jun 2010, 10:24
View user's profile Send private message Reply with quote
pearlz



Joined: 07 Jun 2010
Posts: 55
Location: Viet Nam
pearlz 25 Jun 2010, 10:35
this code can copy values from varible to varible
i want copy value of const string to varible string
can do it?
Post 25 Jun 2010, 10:35
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 790
Location: Massachusetts, USA
bitshifter 25 Jun 2010, 10:39
It copies n bytes from ds:esi to es:edi
Post 25 Jun 2010, 10:39
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 790
Location: Massachusetts, USA
bitshifter 25 Jun 2010, 10:47
Also WINAPI has lstrcpy function...
Code:
format pe gui 4.0
entry WinMain

include 'win32a.inc'

section '.code' code readable executable

  WinMain:
        invoke  lstrcpy,_buffer,_message
        invoke  MessageBox,0,_buffer,_caption,MB_OK
        invoke  ExitProcess,0 

section 'data' data readable writeable

  _message db 'Hello World!',0
  _caption db 'Notice...',0
  _buffer  rb 256

section '.idata' import data readable

  library kernel32,'kernel32.dll',\
          user32,'user32.dll'

  include 'api/kernel32.inc'
  include 'api/user32.inc'
    
Post 25 Jun 2010, 10:47
View user's profile Send private message Reply with quote
pearlz



Joined: 07 Jun 2010
Posts: 55
Location: Viet Nam
pearlz 25 Jun 2010, 11:01
ok, walkaway, actually I want declare any varible, and no give them any values then i copy value of const to them
because i declare
Code:
buffer    rb    4*1024*1024 ' 4MB
exam    db   ?
......................
    

if exam have any value output file win contain size of buffer
Therefore size of output file will >= 4M
Post 25 Jun 2010, 11:01
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 25 Jun 2010, 15:07
pearlz,

Looks like you're as crazy as I am. Such big buffers are have to be dynamically allocated.
Post 25 Jun 2010, 15:07
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 25 Jun 2010, 18:32
baldr, I don't see why, if he knows that will use 4MB then why not allocating it in the uninitialized area of a section? It may be a little selfish with the rest of the applications if those 4MB are unused most of the time though, but still, 4 MB seems to be very little nowadays.

pearlz, are you aware that in assembly the concept of constants barely exists here? (only achievable by marking the section containing them read-only)

Just make sure to store initialized data before any uninitialized data inside the containing section.

bitshifter example could be rewritten as this:
Code:
format pe gui 4.0
entry WinMain

include 'win32a.inc'

section '.code' code readable executable

  WinMain:
        invoke  lstrcpy,_buffer,_message
        invoke  MessageBox,0,_buffer,_caption,MB_OK
        invoke  ExitProcess,0 

; Now these are real constants (also executable though but there is no chance of that happening here)
  _message db 'Hello World!',0
  _caption db 'Notice...',0

section 'data' data readable writeable

  _buffer  rb 1024*1024*4 ; EXE file will still weight 1536 bytes

section '.idata' import data readable

  library kernel32,'kernel32.dll',\
          user32,'user32.dll'

  include 'api/kernel32.inc'
  include 'api/user32.inc'    
Post 25 Jun 2010, 18:32
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-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.