flat assembler
Message board for the users of flat assembler.

Index > Main > pointer or what?

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
gumletis



Joined: 18 Dec 2004
Posts: 128
gumletis 27 Dec 2004, 17:25
I have a small code there is use like 20 kilo byte, only becuase of it use alot of registry. So i want to make it smaller, but i got some problem while i do it. I use like 2 hours for finding the problem, and the problem is that when i use mov instruction its are like a pointer not that i move it whole to another one. How do i do so its not a pointer. FX

xor edi,edi
invoke lstrcat,esi,'Hello'
mov esi,edi
invoke lstrcat,esi,' World'
invoke MessageBox,0,esi,esi,MB_OK

its not my code, but work the same like my code. Please help me out with this guru's Cool

_________________
LOOOL
Post 27 Dec 2004, 17:25
View user's profile Send private message Reply with quote
beppe85



Joined: 23 Oct 2004
Posts: 181
beppe85 27 Dec 2004, 20:32
The invoke macro has a trick that allocates space for string arguments. You cannot do this with a mov or lea because they treats strings as number, not data.

Tip: See the listing for the generated code.

You can replicate the code like this:

Code:
.code

  mov edi, Text
  mov [edi], byte 0
  mov esi, Hello
  call ConcatNullTerminatedString
  mov esi, World
  call ConcatNullTerminatedString
  

.data

  Hello db 'Hello', 0
  World db ' World!', 0
  Text rb 1000    
Post 27 Dec 2004, 20:32
View user's profile Send private message Reply with quote
gumletis



Joined: 18 Dec 2004
Posts: 128
gumletis 27 Dec 2004, 20:50
i don't understand it, i shall have it to not be a pointer. So i used this

Code:
xor edi,edi 
mov edi, hello
mov esi, hello
invoke lstrcat,edi,' World' 
invoke MessageBox,0,edi,0,0 

.data
hello db 'hello ',0
    

but its just shows "hello world", its should't...
and if i use this
Code:
xor edi,edi 
mov edi, hello
mov esi, hello
mov edi,byte 0
invoke lstrcat,edi,' World' 
invoke MessageBox,0,edi,0,0 
    


it will display ' world'....

_________________
LOOOL
Post 27 Dec 2004, 20:50
View user's profile Send private message Reply with quote
beppe85



Joined: 23 Oct 2004
Posts: 181
beppe85 27 Dec 2004, 21:05
I think I could not help you too much, because I'm not a C library fan, but read on...

Code:
xor edi,edi  ; no effect, edi overwritten by next instruction
mov edi, hello ; edi points to 'hello '
mov esi, hello ; esi points to 'hello '
mov edi,byte 0 ; DON'T WORK
invoke lstrcat,edi,' World'  ; puts ' World' from the first null found
invoke MessageBox,0,edi,0,0    


The instruction I noted as not working is because edi is 32 bits and byte 0 is 8 bits. If you mean "mov [edi], byte 0", then the string would be "0, 'ello', 0". So the lstrcat overwrites this string as there's is a null at first position.

Maybe you should write your own strng handling functions, the C ones are too slow.
Post 27 Dec 2004, 21:05
View user's profile Send private message Reply with quote
gumletis



Joined: 18 Dec 2004
Posts: 128
gumletis 27 Dec 2004, 21:09
okay, i also didn't understand it, but how do i get hello to two registry, without being a pointer... ps what you mean with writng my own handling functions with c?
Post 27 Dec 2004, 21:09
View user's profile Send private message Reply with quote
beppe85



Joined: 23 Oct 2004
Posts: 181
beppe85 27 Dec 2004, 21:36
That's OK, I didn't understand you too.

My last attempt: you wanna copy a asciiz to another place.

Code:
  mov esi, source string is here
  mov edi, destination buffer of appropriate size
.move:
  movsb
  cmp [esi-1], 0
  jne .move    
Post 27 Dec 2004, 21:36
View user's profile Send private message Reply with quote
gumletis



Joined: 18 Dec 2004
Posts: 128
gumletis 28 Dec 2004, 09:53
I don't understand movsb. The thing i wanna do is some sort of this i will replace with registry

Code:
include 'win32ax.inc'
.data
sysdir   rb 100
me      rb 100
.code
start:
invoke GetModuleFileName,0,me,100
invoke GetSystemDirectory,sysdir,100
invoke lstrcat,sysdir," = systemdir..."
invoke lstrcat,me," =  me EXE name..."
invoke MessageBox,0,sysdir,"system dir",MB_OK
invoke MessageBox,0,me,"My file name",MB_OK
.end start
    


i would replace with some sort of this
Code:
include 'win32ax.inc'
.data
duck   rb 100
.code
start:
invoke GetModuleFileName,0,duck,100
mov edi,duck
invoke GetSystemDirectory,duck,100
mov esi,duck
invoke lstrcat,edi," = systemdir..."
invoke lstrcat,esi," =  Me EXEname..."
invoke MessageBox,0,esi,"system dir",MB_OK
invoke MessageBox,0,edi,"My file name",MB_OK
.end start
    

I wanna do this becuase registry doesn't use so much bytes. Example 1 fills like 2000 byte, the other one like 1.500 byte... And with another example i try do it, its only fills like 2000 byte, instead of 15.000 bytes... do you understand now?

_________________
LOOOL
Post 28 Dec 2004, 09:53
View user's profile Send private message Reply with quote
gumletis



Joined: 18 Dec 2004
Posts: 128
gumletis 28 Dec 2004, 17:14
any one?
Post 28 Dec 2004, 17:14
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 28 Dec 2004, 21:02
gumletis: try to explain what you want again, and as clearly a you can, seems nobody is understanding you (or at least i am not).
Post 28 Dec 2004, 21:02
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
gumletis



Joined: 18 Dec 2004
Posts: 128
gumletis 29 Dec 2004, 09:39
okay, when i use the mov instuction, its only do a pointer to the registry(or variable), So if edit one of them registr(or variable) it will change in every one... like when you do this is MASM
mov edi,offset esi ; This give a pointer, that i don't wont
mov ebx,eax ; THIS IS WHAT I WONT, this doesn't give a pointer

that was in MASM, i want to translate it to FASM
understand...?
Post 29 Dec 2004, 09:39
View user's profile Send private message Reply with quote
gumletis



Joined: 18 Dec 2004
Posts: 128
gumletis 29 Dec 2004, 13:57
do somebody understand me?
Post 29 Dec 2004, 13:57
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 29 Dec 2004, 14:03
Well, I will try (but you definately need to understand what actually you want to know. Wink )

1. Registers don't have address and because of that you can't write "mov eax, offset esi" not in MASM neither on any assembler.

2. In FASM you have following syntax:
Code:
SomeLabel  dd 1234, 5678    ; some variable defined.

mov  eax, SomeLabel     ; loads the address (offset, whatever you call it) of "SomeLabel" in eax.
mov  eax, [SomeLabel]   ; loads the content of memory at SomeLabel to eax.
    


Regards
Post 29 Dec 2004, 14:03
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 29 Dec 2004, 14:44
also "registry" is name of windoze's control variables. Things like eax, ebx, esi are called "registers", or "register" in singular.
Post 29 Dec 2004, 14:44
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner 29 Dec 2004, 16:17
gumletis wrote:

mov edi,offset esi ; This give a pointer, that i don't wont
mov ebx,eax ; THIS IS WHAT I WONT, this doesn't give a pointer

that was in MASM, i want to translate it to FASM


hi, i try to understand u :-p
Code:
line 3333 label1 dd 88
line 3337 mov  eax,[label1]    ; woudl move the value 88 into eax
line 3340 mov  eax,label1     ;would move the value 3333 into eax
    

hopefully u got it :-p
Post 29 Dec 2004, 16:17
View user's profile Send private message Visit poster's website Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner 29 Dec 2004, 16:29
btw, the line is not the line in your notepad or zibu
it is the line in your pc memory
Post 29 Dec 2004, 16:29
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 29 Dec 2004, 17:20
Quote:
hopefully u got it :-p

yes.

Quote:
btw, the line is not the line in your notepad or zibu
it is the line in your pc memory

yes, but it's called "address" or more exactly "offset".
Post 29 Dec 2004, 17:20
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner 30 Dec 2004, 05:39
offset :-[p
yup, inside 16 bits :-p
i thought we shift to 32 bits already :0 :-p


btw, don't get serious, i try to joke, hopefully u laugh
Post 30 Dec 2004, 05:39
View user's profile Send private message Visit poster's website Reply with quote
gumletis



Joined: 18 Dec 2004
Posts: 128
gumletis 31 Dec 2004, 10:11
thanks... but when i do this

.data
state rb 100
.code
invoke GetModuleFileName,0,state,100
mov eax,[state]


its says error with 'mov eax,[state]' says wrong size... register
Post 31 Dec 2004, 10:11
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 31 Dec 2004, 10:25
gumletis wrote:
its says error with 'mov eax,[state]' says wrong size... register


Right, there is an error. "state" is byte array but eax is dword register. You have several options (depending on what you want to do):
1. Using byte register (al, ah, bl, bh, etc.): "mov al, [state]" - will load the first character from [state] into register al.
2. Using dword register (eax, ebx, ecx, etc.) with type casting: "mov eax, dword [state]" - will load the first 4 characters from [state] into eax register.

Regards.
Post 31 Dec 2004, 10:25
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
gumletis



Joined: 18 Dec 2004
Posts: 128
gumletis 31 Dec 2004, 10:35
okay, but what shall i do, if i shall use it for at msgbox api, becuase i have tryed the

mov eax,dword[state]
invoke MessageBox,0,eax,eax,MB_OK

it will just assemble, but it will crash when i start it
Post 31 Dec 2004, 10:35
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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.