ld r1,[pc+20] #get pointer to register's address 20 is just fictional
ld r2,[r1] #read value
or r2,r2,bit_value #modify
st [r1],r2 #write value
That is 8 bytes worth of instructions.
The "or" instruction is 4 bytes, and the first load has a 4-byte constant (in program space), so I'd call it 14 bytes...
And it's almost exactly why I had in my first message about this, except it doesn't do any atomicity handling.
real code (with real peripherals) is more likely to look like (10-12bytes):
ldr r3, [pc, #8] ; 32-bit constant gpio base.
mov r2, #bitvalue ; could be 2 or 4 bytes.
str r2, [r3, GPIO_BITSET] ; store to bitset reg.
4 bytes is a small price to pay for the flexibility and namespace hygiene it offers.
A decent ARM chip is so fast and has so much memory that the 'inefficiency' isn't an issue.
the whole point of a compiler is to get away from that sort of thing.
Yes, to all of those. And my point (if I have one) is not to complain about the ARM architecture or 32 bit efficiency; I'm just pointing out that the 32bit address space does have pretty direct consequences on "code density." It's the sort of thing that makes an 8-bit programmer shake their head, and it becomes a bit worrisome when ARM manufacturers start offering really cheap "8-bit replacements" that DON'T have "so much memory", and whose libraries still assume you do. And it's a bit annoying to have an assembly language that is so ... difficult to predict, in what is supposed to be a RISC environment (admittedly, things get cleaner if you use a real 32-bit ARM instructions, and not thumb/thumb2 "compressed" instructions.)
The other interesting thing is ... you have to think about how you actually DO GPIO/etc. That single-instruction bitset in AVR is just fine for a constant bitvalue on a constant pin. But it doesn't work if either one is a variable. By the time you get to an arduino-like digitalWrite(pin, val) function where everything is variable and there's some mapping involved, the AVR code has gotten "bloated and slow" and complicated, while the ARM code is ... about the same (and it's now smaller than the AVR code.)