0

I didn't understand the difference between strings with dword, word, qword, etc. I always use byte which can hold 1 byte, but when we want to use a string and not just a char, the assembler do it like {'a', 'b', 'c'} to represent a string just like C.

So when should I use for example dword when working with strings in assembly?

  • Depending on assembler, that usually just ensures that the entire string takes up a whole number of dwords. This is useful for maintaining alignment for following things. – Jester Oct 09 '20 at 12:00
  • 1
    Usually never. If you want later stuff aligned, using an `align` directive after the string is clearer. Which assembler did you have in mind? I guess you mean x86 because most other ISAs don't have qwords. – Peter Cordes Oct 09 '20 at 12:13
  • A word is 2 bytes, a dword (double word) is 4 bytes and a qword (quad word) is 8 bytes. – fuz Oct 09 '20 at 12:14
  • In C, a string is a sequence of chars. In asm a string is a sequence of bytes, words, dwords or qwords. In asm there is nothing special about chars - they are just like integers. If you are dealing with strings of ANSI chars, use `LODSB/MOVSB/STOSB`; if you are dealing with unicode strings, use `XXXSW`; for USC32 strings, use `XXXSD`. – W. Chang Oct 09 '20 at 12:16
  • Apparently you're using NASM syntax based on a link to a book in another question – Peter Cordes Oct 09 '20 at 12:39

0 Answers0