GCC inline assembler, mixing register sizes (x86)

后端 未结 5 930
离开以前
离开以前 2020-12-10 14:14

Does anyone know how I can get rid of the following assembler warning?

Code is x86, 32 bit:

int test (int x)
{
  int y;
  // do a bit-rotate by 8 on          


        
5条回答
  •  醉酒成梦
    2020-12-10 14:26

    While I'm thinking about it ... you should replace the "q" constraint with a capital "Q" constraint in Chris's second solution:

    int
    test(int x)
    {
        int y;
        asm ("xchg %b0, %h0" : "=Q" (y) : "0" (x));
        return y;
    }
    

    "q" and "Q" are slightly different in 64-bit mode, where you can get the lowest byte for all of the integer registers (ax, bx, cx, dx, si, di, sp, bp, r8-r15). But you can only get the second-lowest byte (e.g. ah) for the four original 386 registers (ax, bx, cx, dx).

提交回复
热议问题