Closed Thread
Results 1 to 2 of 2

Thread: AoA question

  1. #1
    Osnarf's Avatar
    Osnarf is offline Learning Programmer
    Join Date
    Mar 2010
    Posts
    31
    Rep Power
    0

    AoA question

    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.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    BuckAMayzing is offline Learning Programmer
    Join Date
    Apr 2010
    Posts
    39
    Rep Power
    0

    Re: AoA question

    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.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Question:technical question answering system algorithm?
    By vbehzadan in forum General Programming
    Replies: 1
    Last Post: 04-28-2010, 12:41 PM
  2. Replies: 4
    Last Post: 03-27-2010, 08:27 PM
  3. C# noob question 3, list question
    By Siten0308 in forum C# Programming
    Replies: 3
    Last Post: 01-21-2010, 07:41 AM
  4. QUESTION Strcat/Strstr/strcpy Question
    By wgre0111 in forum C and C++
    Replies: 1
    Last Post: 10-19-2008, 03:12 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts