4 typedef unsigned int UInt
;
5 typedef unsigned short UShort
;
7 UInt
read16le ( void* a
)
11 " lhbrx %0,0,%1 \n" // Get half word and reverse the bytes
12 : "=b" (res
) // %0 - Output operand
13 : "b" (a
) // %1 - Input operand
14 : "memory" // Consider memory clobberred for aliasing
19 UInt
read16be ( void* a
)
23 " lhzx %0,0,%1 \n" // Get half word and reverse the bytes
24 : "=b" (res
) // %0 - Output operand
25 : "b" (a
) // %1 - Input operand
26 : "memory" // Consider memory clobberred for aliasing
31 UInt
read32le ( void* a
)
35 " lwbrx %0,0,%1 \n" // Get half word and reverse the bytes
36 : "=b" (res
) // %0 - Output operand
37 : "b" (a
) // %1 - Input operand
38 : "memory" // Consider memory clobberred for aliasing
43 UInt
read32be ( void* a
)
47 " lwzx %0,0,%1 \n" // Get half word and reverse the bytes
48 : "=b" (res
) // %0 - Output operand
49 : "b" (a
) // %1 - Input operand
50 : "memory" // Consider memory clobberred for aliasing
55 void write16be ( void* a
, UInt data
)
65 void write16le ( void* a
, UInt data
)
75 void write32be ( void* a
, UInt data
)
85 void write32le ( void* a
, UInt data
)
97 UInt foo
= 0x12345678;
98 printf("ld be16 0x%08x\n", read16be( &foo
));
99 printf("ld le16 0x%08x\n", read16le( &foo
));
100 printf("ld be32 0x%08x\n", read32be( &foo
));
101 printf("ld le32 0x%08x\n", read32le( &foo
));
103 foo
= 0x12345678; write16be( &foo
, 0xABCD );
104 printf("st be16 0x%08x\n", foo
);
106 foo
= 0x12345678; write16le( &foo
, 0xABCD );
107 printf("st le16 0x%08x\n", foo
);
109 foo
= 0x12345678; write32be( &foo
, 0xABCD1425 );
110 printf("st be32 0x%08x\n", foo
);
112 foo
= 0x12345678; write32le( &foo
, 0xABCD1425 );
113 printf("st le32 0x%08x\n", foo
);