Arm/memenable2
From ASMBits
arm/memenablePrevious
NextIndex
You have a 4 KB (kilobyte) memory that is mapped to the address range 0xff3000 – 0xff3fff. In reality, this 4 KB memory is built out of 16 256-byte devices. When a memory access to the 4 KB range occurs, only one of the 256-byte devices should be enabled.
Write a function that returns which device should be enabled when an access to the given address occurs. If the access is outside the 4 KB range, return -1. You should not use any add, sub, mul, or greater/less-than conditional instructions (equal or not-equal comparisons are allowed).
- 0xfff3000 – 0xfff30ff: Return 0
- 0xfff3100 – 0xfff31ff: Return 1
- 0xfff3200 – 0xfff32ff: Return 2
- ...etc
- 0xfff3f00 – 0xfff3fff: Return 15
- Outside 0xfff3000 – 0xfff3fff: Return -1
unsigned int memenable(unsigned int address);
Expected solution length: Around 10 lines.
Sample Input
memenable(0xff3100)
Sample Output
r0=1
arm/memenablePrevious
NextIndex