What's new

Bit Testing

aravan

New member
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
 

smcd

Active member
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
}
 

bcrew1375

New member
aravan said:
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.
 
OP
A

aravan

New member
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
 

Cyberman

Moderator
Moderator
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
 

Top