ARM > Efficient C for ARM > Bools
Example
typedef unsigned int bool;
bool isEnemy(bool hasLasers,
bool hasMissiles,
bool hasBomb,
bool hasECM)
{
return hasLasers ||
hasMissiles ||
hasBomb ||
hasECM;
}
isEnemy ORR r0,r0,r1
ORR r0,r0,r2
ORRS r0,r0,r3
MOVNE r0,#1
MOV pc,lr
typedef unsigned int ShipFlags;
#define ShipFlags_HasLasers (1u << 0)
#define ShipFlags_HasMissiles (1u << 1)
#define ShipFlags_HasBomb (1u << 2)
#define ShipFlags_HasECM (1u << 3)
bool isEnemy2(ShipFlags flags)
{
ShipFlags want = ShipFlags_HasLasers |
ShipFlags_HasMissiles |
ShipFlags_HasBomb |
ShipFlags_HasECM;
return (flags & want) != 0;
}
isEnemy2 ANDS r0,r0,#0xf
MOVNE r0,#1
MOV pc,lr
Previous topic:
Unaligned Data Access
Next topic:
Bitfields