Results 1 to 6 of 6

Thread: Bit Testing

  1. #1
    EmuTalk Member aravan's Avatar
    Join Date
    Dec 2005
    Posts
    2

    Question Bit Testing

    Hi all, I have been going through some source code for a 6809 microprocessor, to learn more about programming one, but I fail to see how most of them implement testing on bits to see if a carry or mores specifically a half carry occurred so you can set the appropriate bits in the cc register. I am working with c++ to program opcodes (ADC in particular). Any help would be greatly appreciated.

    Thanks in advance



    • Advertising

      advertising
      EmuTalk.net
      has no influence
      on the ads that
      are displayed
        
       

  2. #2
    Moderator smcd's Avatar
    Join Date
    Jun 2004
    Posts
    2,503
    Most of the time bit testing occurs by ANDing a "mask" against a value, if I am understanding you properly.

    Code:
    #define value 0x0F
    #define mask 0x01
    
    if(value & mask) {
     // the mask bit is set in the variable 'value'
    // do stuff here
    }

  3. #3
    EmuTalk Member
    Join Date
    Jul 2004
    Location
    Someplace where I don't know where I am.
    Posts
    618
    Quote Originally Posted by aravan
    Hi all, I have been going through some source code for a 6809 microprocessor, to learn more about programming one, but I fail to see how most of them implement testing on bits to see if a carry or mores specifically a half carry occurred so you can set the appropriate bits in the cc register. I am working with c++ to program opcodes (ADC in particular). Any help would be greatly appreciated.

    Thanks in advance
    A carry occurs when a value overflows its memory space. So, if you have an 8-bit value and add another value to it, and their total is greater than 255(max value for 8-bits, assuming it's unsigned), you have a carry. If I'm thinking correctly, you can determine a half carry by ANDing both numbers with 15(which would leave you with bits 0-3) and adding them together. If their total is greater than 15, you have a half carry.

  4. #4
    EmuTalk Member aravan's Avatar
    Join Date
    Dec 2005
    Posts
    2

    Thumbs up Doh!!!

    Thanks bcrew, that is what I was doing, but I was writing 15 down as 0001 1111 not 0000 1111 . Man, sometimes you just need to take a step back and ask somebody.

    Thanks again for the help

  5. #5
    EmuTalk Member
    Join Date
    Jul 2004
    Location
    Someplace where I don't know where I am.
    Posts
    618
    Sure, anytime.

  6. #6
    Moderator Cyberman's Avatar
    Join Date
    Nov 2001
    Posts
    1,824
    Well I guess you were a 'bit off' on your original idea

    Glad someone helped you. As the saying goes 2 heads are better than none.

    Cyb
    Progress (n.):
    The process through which the Internet has evolved from smart people in front of dumb terminals to dumb people in front of smart terminals.
    -------------------------------------------------------------------
    Recursive (adj):
    see Recursive

Similar Threads

  1. 16 bit to 24 bit
    By Converter in forum Tutorials, Questions and General Talk
    Replies: 7
    Last Post: July 5th, 2006, 20:34
  2. slappin
    By linker in forum IRC Quotes
    Replies: 8
    Last Post: May 24th, 2006, 16:23
  3. 64 bit Optimizations in 1.0?
    By Veracity in forum 1964
    Replies: 6
    Last Post: June 2nd, 2004, 17:19
  4. 32 bit core emulation.
    By crhylove in forum 1964
    Replies: 3
    Last Post: January 8th, 2002, 20:23
  5. Project64?????
    By CJM in forum Project64
    Replies: 5
    Last Post: December 5th, 2001, 01:05

Posting Permissions

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