How to mask bytes in ARM assembly?

前端 未结 5 1005
醉酒成梦
醉酒成梦 2021-02-04 15:53

i have got an 32bit (hexadecimal)word 0xaabbccdd and have to swap the 2. and the 3. byte. in the end it should look like 0xaaccbbdd

how can i \"mask\" the 2nd and the 3r

5条回答
  •  执笔经年
    2021-02-04 16:07

    You vould just use pointers to swap two bytes

    static union {
     BYTE   BBuf[4];
     WORD   WWBuf[2];
     DWORD  DWBuf;
    }swap;
    
    unsigned char *a;
    unsigned char *b;
    swap.DWBuf = 0xaabbccdd;
    
    a = &swap.BBuf[1];
    b = &swap.BBuf[2];
    
    *a ^= *b;
    *b ^= *a;
    *a ^= *b;
    

    And now the result is

    swap.DWbuf == 0xaaccbbdd;
    

提交回复
热议问题