Hi, dont laugh ,very basic questions. i have some problems with the database. i use in a function: cmp eax,"tseT" (to see if the name is found) now i like to make a database entry ,like: Test01 db "Test",0 or Test01 db "tseT",0 then i wrote : cmp eax,offset Test01 but it will not work. i understand that for text DB is used,but why is this then not working. Any ideas ? Thanks
Posted on 2001-04-01 10:08:00 by EASYCODE
Well... first of all, 'db' is not a database, it means 'define byte' (it's a very obscure definition that many asm-heads prefer, I hate obscurity and I use not 'db' but 'BYTE' for byte). So, the following: Test01 BYTE "Test",0 will define 5 bytes in memory, 4 for the characters 'T' 'e' 's' and 't', and the trailing zero. Now, when you write: cmp eax,offset Test01 you are comparing the contents of eax with the address where Test01 is stored. That's probably not what you wanted to do. If you want to work with character string, look at the API functions lstrcmp, lstrcat, lstrcpy and such, they may be slow compared to pure asm, but they are usefull. ------------------------ "Always remember that youíre representing your country. I guess what Iím saying is, donít mess up France the way you messed up your room."
Posted on 2001-04-01 10:35:00 by Ernie
The
offset
is the address of the string and not the data as Ernie said. If you want to compare the data
cmp eax, Test01
should work. Using the API to compare the string would be a more extensible method, and you wouldn't be limited to four byte comparisons. In fact you don't need the zero on the end of that string if your just using it for this comparison.
Posted on 2001-04-01 12:24:00 by bitRAKE
if the data in test01 doesnt change theres no reason you cant just do cmp eax,test jz does that help?
Posted on 2001-04-01 13:39:00 by skud
Hi, many thanks to you all ! i got it working :) but now i dont understand for what is : offset ? if i use offset test it wont work,if i use test ,it work. first i think i have to write offset if i have anything in .data section. i see,there is much basic stuff i have to learn first *g* hope i dont nerv with this questions :) have a nice day
Posted on 2001-04-02 04:11:00 by EASYCODE
skud, we can't use 'Test' because it is a reserved word. :) Change: cmp eax,test To: cmp eax,vtest luck!
Posted on 2001-04-02 06:45:00 by wolfao
Offset, and its (many?) uses: The thing to remember about ASM vs. HLL languages (and the way we as humans naturally think), is that ASM can only deal with limited data in one go. In the case of a 32bit processor, it is (rather surprisinly :P ) 32bit, or 4 bytes. Text is, or at least can be over 4 bytes in length, so doing a string comparison in one go is not a single step operation, it must be broken down.

.data
  MyString db "This is a string longer than 4 bytes",0

...
  mov esi, offset MyString
  mov edx, 
  ;Get the first 4 bytes of MyString (as pointed to by esi)
  cmp edx, "sihT"
  jnz Somewhere
  add esi, 4
  ;Increment the pointer by 4 bytes
  mov edx, 
  cmp edx, " si "
  jnz Somewhere
...
You cannot simply compare the whole string.... If all your strings are 4 characters long, your method is an easy way to compare them. By using offset, you can also reference the memory as a different type:

.data
  MyDWord DWORD 0

...

  mov eax, offset MyDWord
  inc eax
  mov BYTE PTR , "A"

...
It is also used when passing variables by reference, rather than copying them on to the stack. Mirno
Posted on 2001-04-02 07:58:00 by Mirno
WOW ! That explain a lot to me. the word TEST is 4 bytes long and it work as long as i insert a 4 bytes long word,all other i got the error i dont understand. im very happy to know this now,thanks a lot ! i like to make the reading of the database ,for the submit engine ,a bit easy then i use actual :) now it will work allmost fine i think. cu
Posted on 2001-04-02 11:22:00 by EASYCODE