Author Topic: Terminate constant string in NASM source?  (Read 7396 times)

jimcpl

  • Guest
Terminate constant string in NASM source?
« on: June 05, 2009, 02:24:00 AM »
Hi,

I am trying to push a constant "string" (4 bytes), onto the stack, but I need to "terminate" the string with bytes containing 0x00.

The string is something like "e!", and the assembled code should look like:

6865210000

I've tried:

PUSH 'e!\0\0'

but that doesn't seem to work (I get a warning from NASM, and it appears to be interpreting the "\0" literally, i.e., as two bytes).

Does anyone know how I can do this in NASM?

Thanks,
Jim

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Terminate constant string in NASM source?
« Reply #1 on: June 05, 2009, 10:16:25 AM »
Just:

push 'e!'

Should do what you want. Nasm will do stuff like:

push 'e!'<<16 |  0

but that'll "pre-terminate" your string, since it goes into memory little-endian.

Nasm only accepts C-style `/n`, `/t`, `/0`, etc. between "back apostrophes"... and it doesn't seem to work in this case... I guess just with "db"...?

Since you seem to be trying to match "other assemblers", note that Nasm treats "mov eax, 'abcd'" as other assemblers would treat "mov eax, 'dcba'". I'm not sure which assemblers do it which way. Some controversy which is "right"...

Best,
Frank

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Terminate constant string in NASM source?
« Reply #2 on: June 05, 2009, 01:24:57 PM »
> Nasm only accepts C-style `/n`, `/t`, `/0`, etc. between "back apostrophes"...
> and it doesn't seem to work in this case... I guess just with "db"...?

Brain-cramp/typo there... with BACKslashes and BACKapostrophes, it *does* work as you had it:

push `e!\0\0`

Tseb,
Frank

jimcpl

  • Guest
Re: Terminate constant string in NASM source?
« Reply #3 on: June 07, 2009, 03:54:42 AM »
Frank,

Thanks!  That (reverse apostrophe) worked perfectly!

Jim