View Full Version : Bit Testing
aravan
July 25th, 2006, 20:50
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
July 25th, 2006, 22:47
Most of the time bit testing occurs by ANDing a "mask" against a value, if I am understanding you properly.
#define value 0x0F
#define mask 0x01
if(value & mask) {
// the mask bit is set in the variable 'value'
// do stuff here
}
bcrew1375
July 26th, 2006, 07:03
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.
aravan
July 26th, 2006, 14:43
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
bcrew1375
July 27th, 2006, 11:24
Sure, anytime. :)
Cyberman
July 27th, 2006, 17:17
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
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.