6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 24, 2024 9:14 am

All times are UTC




Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
PostPosted: Mon Apr 22, 2002 5:08 pm 
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 ;)


Report this post
Top
  
Reply with quote  
PostPosted: Wed Apr 24, 2002 2:22 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
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

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: