The codes in C++ but its an assembly question...
Code:unsigned SetBit(unsigned BitMap, unsigned position) { return BitMap | (1 << position); } unsigned ClrBit(unsigned BitMap, unsigned position) { return BitMap & ~(1 << position); }
54)In code appearing in the questions above, explain what happens if the position parameter contains a value greater than or equal to the number of bits in an unsigned integer.
Unless I'm confused... in assembly you would need to put the one in a register, then shift it to the left n times, where n is the number of bits in the unsigned variable, then take the smallest register containing the set bit that you shifted, and OR it with the unsigned variable. But this would return a compile error because the operands must be the same size.
Would the compiler just extend the memory location? Or would it return a value out of range exception or a conversion error exception? Thanks for your help.
EDITED A FEW THINGS
Last edited by Osnarf; 03-21-2010 at 12:16 PM.
Ok, let's say for example that you're putting the 1 into ax, a 16 bit register.
If you shifted it left 16 times, it wouldn't move on into eax, it would just drop out of the end of the ax. I'm fairly sure it wouldn't even set any flags. So put the 1 in a register that is the same size as the data type you are working with.
Is that what you were asking? It's kind of tough for me to tell.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks