Can't seem to add %ES to the clobberlist (inline assembly, GCC)

I'm going through Micheal Abrash's Graphics Programming Black Book (which by the way, I am really enjoying, I strongly recommend it), so the example code I'm working with is quite old. Nonetheless, I don't see what the problem is:

__asm__(
    //Some setup code here
    "movl %%esi, %%edi;"
    "movw %%ds, %%es;"
    //A whole bunch more assembly code in between
    "divloop:"
    "lodsw;"
    "divl %%ebx;"
    "stosw;"
    "loop divloop;"
    //And a little more code here
    : "=r" (ret)
    : "0" (ret) /*Have to do this for some reason*/, "b" (div), "c" (l), "S" (p)
    : "%edi", "%es"
);
  • The l variable is an unsigned int, the p variable is a char*. l is a byte count for the length of the string pointed at by p . div is the divisor and is an unsigned int. ret is the return value (an unsigned int) of the function and is set inside to assembly block to be the remainder of the division.
  • The error message I am getting is "error: unknown register name '%es' in 'asm'" (This is the only error message). My best guess is that it goes by another name in GAS syntax. I know I'm working with old code, but as far as I know, on my fairly new intel i3 there is still an ES register that gets used by stos*

    Secondly, there's a question that's been bugging me. I've basically had no choice but to just assume that DS was already set to the right memory location for use with lods*. Since I am reading from, modifying, and writing to the same memory location (using stos* and lods*) I'm setting ES equal to DS. However, it's really scaring me that my DS could be anything and I don't know what else to set it to. What's more is that ESI and EDI are already 32 bit registers and should be enough on their own to access memory.

    In my experience, two strange problems at once are usually related and caused by a more fundamental problem (and usually a PEBKAC). However, I'm stumped at this point. Does anyone know what's going on?

    Thanks a bunch

    PS I'm trying to recreate the code from Chapter 9 (Hints My Readers Gave Me, Listing 9.5, page 182) that divides a large number stored in contiguous memory by EBX. There is no other reason for doing this than my own personal growth and amusement.


    If you're running in a flat 32-bit protected mode environment (like a Linux or Windows user-mode process), there's no need to set es.

    The segment registers are set for you by the OS, and es and ds both allow you to access a flat 32-bit address space.

    GCC won't generate code to save/restore segment registers, so it's not surprising that it won't allow you to add them to the clobber list.

    链接地址: http://www.djcxy.com/p/59754.html

    上一篇: 单独的MVC项目进入不同的项目?

    下一篇: 似乎无法将%ES添加到clobberlist(内联汇编,GCC)