flat assembler
Message board for the users of flat assembler.

Index > Main > Sizeof?

Author
Thread Post new topic Reply to topic
Todd



Joined: 05 Oct 2003
Posts: 10
Location: US
Todd
Hi,

I've been reading some tutorials on using ODBC with ASM, and some of the ODBC commands require you to specify the length of the strings you pass into it. Is there any way to this automatically in FASM without having to count characters by hand? Here's an example in another assembly language (not sure which one):

Code:
hStmt dd ?
SQLStmt db 'Select * from table',0

invoke SQLExecDirect, hStmt, addr SQLStmt, sizeof SQLStmt
    


What would be the equivilent of this, using FASM? Thanks.
Post 27 Oct 2003, 01:22
View user's profile Send private message Reply with quote
silkodyssey



Joined: 02 Oct 2003
Posts: 198
Location: St.Vincent & the Grenadines
silkodyssey
You can try something like

Code:
 


hStmt dd ?
SQLStmt db 'Select * from table',0
SizeOfSQLStmt = $-SQLStmt 

invoke SQLExecDirect, hStmt, addr SQLStmt, SizeOfSQLStmt 
    


$ is the current offset in the program so $-SQLStmt is the size of the string.

_________________
silkodyssey
Post 27 Oct 2003, 02:05
View user's profile Send private message MSN Messenger Reply with quote
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
scientica
Or if you like to have a little macro to add a ".size" for you, I use this macro in some of my files. (I use it for two reasons, the ".size" which is the size of the stinrg (including the null-terminator!), second I can easily see if a string isn't used.)

Code:
;N.B! The display line contains a function which is not (yet) part of the official release, simply removing "`name,'" is enoguth to allow compile on the offical release. (If you want to use the ` feature you'll need to find fasm ersion 1.49.9 on the board)
macro sz name, [data]{
  common
  if ~ used name
   display '<W> ',`name,' is never used',13,10 ; displays a message if the string isn't used any where in the code.
  else
   name db data
    .size = $-name
  end if
}

; Use like this:
hStmt dd ?
sz SQLStmt, 'Select * from table',0
invoke SQLExecDirect, hStmt, SQLStmt, SQLStmt.size ; the addr is superfluous in fasm, unless you use the "special" invoke macro which uses the pushd macro.
    


If you inted to use a lot of these strings then I strongly sugest you use a macro (like above), macros actually makes life eaiser some times. Smile

_________________
... a professor saying: "use this proprietary software to learn computer science" is the same as English professor handing you a copy of Shakespeare and saying: "use this book to learn Shakespeare without opening the book itself.
- Bradley Kuhn
Post 27 Oct 2003, 11:31
View user's profile Send private message Visit poster's website Reply with quote
Kain



Joined: 26 Oct 2003
Posts: 108
Kain
jcan you not use the $ current offset operator right on the invokation?

Code:
invoke SQLExecDirect, hStmt, addr SQLStmt, $-SQLStmt 
    


seems to me like it would make a more compact code.

also, is $ operator similar to offset and addr for any object?

sorry, just started learning assembly 3 days ago from anything i can find on the web.
Post 27 Oct 2003, 18:12
View user's profile Send private message Reply with quote
eet_1024



Joined: 22 Jul 2003
Posts: 59
eet_1024
No. $ is the current address pointer. To calculate size, you must create a numeric constant (using =, not equ) after the string, but before anything else advances the pointer.

Code:
push $   ; These place two different values onto the stack
push $
    
Post 27 Oct 2003, 19:05
View user's profile Send private message Reply with quote
Kain



Joined: 26 Oct 2003
Posts: 108
Kain
eet_1024 wrote:
No. $ is the current address pointer. To calculate size, you must create a numeric constant (using =, not equ) after the string, but before anything else advances the pointer.

Code:
push $   ; These place two different values onto the stack
push $
    


i see. thanks for the correction.

while reviewing the fasmw docs, i found an example struc similar to scientica's macro.

Code:
struc db [data]
{
common
label .data byte
db data
.size = $-.data
}
    


page 63
Quote:
With such definition for example msg db ’Hello!’,13,10 will define also
msg.size constant, equal to the size of defined data in bytes and also addi-tional
label msg.data, which will be recognized as a label for data of byte
size.
Post 27 Oct 2003, 23:56
View user's profile Send private message Reply with quote
Todd



Joined: 05 Oct 2003
Posts: 10
Location: US
Todd
Thanks for the replies, thats exactly what I was looking for. I actually ended up using 'strlen' from crtdll.dll, but I may give these other suggestions a try. I still don't quite understand macros, but they seem like they could be a very handy thing to know.
Post 28 Oct 2003, 02:30
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 YouTube, Twitter.

Website powered by rwasa.