6502.org http://forum.6502.org/ |
|
[158] Alert.. newbie question.. eh.. http://forum.6502.org/viewtopic.php?f=7&t=413 |
Page 1 of 1 |
Author: | stoopidnewbe [ Mon Apr 22, 2002 5:08 pm ] |
Post subject: | [158.1] Alert.. newbie question.. eh.. |
Hi everybody. I've just begun programing the 6502, and heh.. maan this is hard.. so I'd like some help.. My teacher gave me this supposedly "easy" task to write a code for. I have 1 Byte stored at adress 1 and another one at adress 2, now I must compare these two bytes bit for bit and write to different adresses depending on how they compare. Let's say that the first bit of adress one is "1" and the first bit of adress two is "1" then I should write a "1" to the first bit of adress 3, and a "0" to adress 4,5 But if bit one of adress one is "1" and bit one of adress 2 is "0" then I should write a "1" to the first bit of adress 4, and a "0" to adress 3,5 Or if bit one of adress one is "0" and bit one of adress two is "1" then I should write a "1" to the first bit of the byte at adress 5, and a "0" to adress 3,4 and finally if first bit of both adress 1 and 2 contains a "0" I should write a "0" to all 3 adresses (adress 3,4,5). This I should do for all the bits of the bytes from the 2 adresses. ex. Adress 1 first byte : 00100010 Adress 2 second byte: 00100000 First bit of the two adresses is "0" so I should write 0 to adress 3,4,5. Second bit of the two ardesses is "1" and "0" so I should write a "1" to 4 and "0" to adress 3,5 third bit (see first bit) forth bit (see first bit) fifth bit (see first bit) sixth bit of the two adresses is "1" and "1" so I should write a "1" to adress 3 and "0" to adress 4,5 seventh bit (see first bit) eight bit (see first bit) Can anybody be kind and give me an example code to study? Thanks and I hope you won't mind the bad english of a lame newbie |
Author: | GARTHWILSON [ Wed Apr 24, 2002 2:22 am ] |
Post subject: | [158.2] Alert.. newbie question.. eh.. |
It would have been much easier to communicate the criteria by way of a truth table. I called the five addresses A through E to avoid confusing logic operations with numbers because of the possibility of confusing immediate and absolute (or ZP). After making a truth table, I come up with (if I correctly understand what you're after): C = A AND B D = A AND NOT B E = NOT A AND B You can get there with: LDA A AND B STA C LDA B EOR #$FF AND A STA D LDA A EOR #$FF AND B STA E This does all bytes, all 8 bits at once. If all five variable bytes are in page 0 as you indicate, it will take 31 clocks, or 31 microseconds at 1MHz. (The slowest 6502's are 1MHz.) The EOR (Exclusive OR) with $FF inverts the state of all 8 bits. Garth |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |