1

I was compiling some code that had this piece of code:

__asm__ __volatile__ ("
    pushw %%es
    movw %%ds, %%ax
    movw %%ax, %%es
    xorl %%eax, %%eax
    movl SurfBufD, %%edi
    xorl %%ebx, %%ebx
Blank2:
    movl SurfaceX, %%ecx
    rep
    stosw
    addl Temp1, %%edi
    subl SurfaceX, %%edi
    subl SurfaceX, %%edi
    addl $1, %%ebx
    cmpl SurfaceY, %%ebx
    jne Blank2
    popw %%es
" : : : "cc", "memory", "eax", "ebx", "ecx", "edi");

and when I tried to compile it, I got:

linux/sdllink.c:948:24: warning: missing terminating " character asm volatile (" ^ linux/sdllink.c:948:2: error: missing terminating " character asm volatile (" ^ linux/sdllink.c:949:3: error: expected string literal before ‘pushw’ pushw %%es ^ linux/sdllink.c:966:51: warning: missing terminating " character " : : : "cc", "memory", "eax", "ebx", "ecx", "edi"); ^ linux/sdllink.c:966:2: error: missing terminating " character " : : : "cc", "memory", "eax", "ebx", "ecx", "edi");

I tried to solve it changing this code to:

    __asm__ __volatile__ ( 
    "pushw %%es"
    "movw %%ds, %%ax"
    "movw %%ax, %%es"
    "xorl %%eax, %%eax"
    "movl SurfBufD, %%edi"
    "xorl %%ebx, %%ebx"
"Blank2:"
    "movl SurfaceX, %%ecx"
    "rep"
    "stosw"
    "addl Temp1, %%edi"
    "subl SurfaceX, %%edi"
    "subl SurfaceX, %%edi"
    "addl $1, %%ebx"
    "cmpl SurfaceY, %%ebx"
    "jne Blank2"
    "popw %%es"
" : : : cc, memory, eax, ebx, ecx, edi");

Basically, I assumed this function wanted every line to be a string literal, but it didn't change anything. So, what I have to do?

zx485
  • 28,498
  • 28
  • 50
  • 59
user2752471
  • 444
  • 1
  • 6
  • 14
  • It did not change **anything**? You got **exactly** the same error message? – Eric Postpischil Jan 02 '21 at 23:26
  • 1
    That must be some very old code. gcc [used to support multi-line string literals](https://gcc.gnu.org/onlinedocs/gcc-3.2.2/gcc/Multi-line-Strings.html) as an extension to standard C, but this feature was [removed in gcc 3.3](https://gcc.gnu.org/gcc-3.3/changes.html), circa May of 2003. – Nate Eldredge Jan 02 '21 at 23:40
  • @NateEldredge Well, he's working with `es` and `ds`, so DOS? – David Wohlferd Jan 03 '21 at 01:37
  • @DavidWohlferd: Well real-mode at least, could also be freestanding or depending only on BIOS, not DOS. (e.g. a bootloader or a 16-bit "OS" (toy or otherwise).) – Peter Cordes Jan 03 '21 at 10:14

1 Answers1

3
  • One string literal in C cannot written in multiple lines, but consecutive string literals are merged.
  • Also \ in the line end means that the line should be concatenated with the next line and treated as one line, so you can use this.
  • There should be newlines in the string. Newlines can be expressed as \n.

Consecutive string literals:

    __asm__ __volatile__ ( 
    "pushw %%es\n"
    "movw %%ds, %%ax\n"
    "movw %%ax, %%es\n"
    "xorl %%eax, %%eax\n"
    "movl SurfBufD, %%edi\n"
    "xorl %%ebx, %%ebx\n"
"Blank2:\n"
    "movl SurfaceX, %%ecx\n"
    "rep\n"
    "stosw\n"
    "addl Temp1, %%edi\n"
    "subl SurfaceX, %%edi\n"
    "subl SurfaceX, %%edi\n"
    "addl $1, %%ebx\n"
    "cmpl SurfaceY, %%ebx\n"
    "jne Blank2\n"
    "popw %%es\n"
: : : "cc", "memory", "eax", "ebx", "ecx", "edi");

Lines connected via \:

    __asm__ __volatile__ ( 
    "pushw %%es\n\
    movw %%ds, %%ax\n\
    movw %%ax, %%es\n\
    xorl %%eax, %%eax\n\
    movl SurfBufD, %%edi\n\
    xorl %%ebx, %%ebx\n\
Blank2:\n\
    movl SurfaceX, %%ecx\n\
    rep\n\
    stosw\n\
    addl Temp1, %%edi\n\
    subl SurfaceX, %%edi\n\
    subl SurfaceX, %%edi\n\
    addl $1, %%ebx\n\
    cmpl SurfaceY, %%ebx\n\
    jne Blank2\n\
    popw %%es\n"
: : : "cc", "memory", "eax", "ebx", "ecx", "edi");
MikeCAT
  • 73,922
  • 11
  • 45
  • 70
  • If you're going to answer this instead of looking for a duplicate, worth pointing out that the resulting string literal gets fed to the assembler as-is (after substituting any `%[operand]` strings), which is why it has to be a string literal containing multiple lines for each instruction. (Or separated by `;`, the GAS "statement" separator for its x86 syntaxes.) – Peter Cordes Jan 03 '21 at 10:13