6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 23, 2024 2:26 pm

All times are UTC




Post new topic Reply to topic  [ 15 posts ] 
Author Message
PostPosted: Sat Mar 02, 2019 2:02 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
This idea came up nearby: what kind of relatively simple programming exercises might be useful to someone new to the 6502, unfamiliar with the addressing modes, unsure how to use the registers, perhaps used to a CPU with rather different facilities?

My first thought was this:
Quote:
here's an idea: write a routine to clear a 1000 byte block of memory, the address being known at assembly time. You can probably write it three or four ways, and doing so might itself be a good exercise.


(I think people who speak of a coding dojo would call these exercises kata. But I'm not thinking about general coding competence, more at targeting competence in making best use of the 6502.)

(Edit: I think it's best not to discuss or attempt solutions on this thread, so here's one for that.)


Last edited by BigEd on Sun Mar 03, 2019 10:14 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 02, 2019 2:33 pm 
Offline
User avatar

Joined: Tue Nov 16, 2010 8:00 am
Posts: 2353
Location: Gouda, The Netherlands
Assuming a UART "PutChar" routine, write a routine to output a hexadecimal nibble, and then a routine to output a hexadecimal byte.


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 02, 2019 3:02 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Nice one, thanks!


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 02, 2019 3:50 pm 
Offline

Joined: Mon May 21, 2018 8:09 pm
Posts: 1462
Given two arrays of 1000 byte values, addresses known at assembly time, calculate the SAD (sum of absolute differences). You'll need 3 bytes to store the result.
Code:
for(i=0; i<1000; i++)
    sum += (A[i] > B[i]) ? A[i] - B[i] : B[i] - A[i];
Do this twice, first assuming the bytes are unsigned values, and then assuming they are two's-complement signed values; the result will be unsigned in both cases.

For extra credit, a third repetition should assume one array is signed and the other unsigned.


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 02, 2019 8:58 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1488
Location: Scotland
Leading on from hex print, how about simply (!) print a 16-bit value in fixed field decimal. (unsigned) so given $1234 stored in zp $10, $11, low bye first, output ^4660 (where ^ is a space)

This was a programming task I was given as part of a job "interview" a very long time back. However CPU was an 8080 (using z80 mnemonics) which I'd never used before but a couple of years of 6502 stood me in good standing... I got the job, but didn't quite complete it in the hour or so I had - mostly due to 100% unfamiliarity with everything - including the computer (Northstar Horizon running N* DOS) and how to download the code into the target 8080 system to even test it.

I then spent the next year as a PhD research assistant writing 8080 code for the system which was a real-time blood analysis machine, while designing 6502 SBCs for other automation, but that's another story.

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 02, 2019 9:19 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1949
Location: Sacramento, CA, USA
Given a PASCAL-style "counted" ASCII string at a fixed address, find and convert all lower-case alphabetic characters to UPPER-case, leaving control characters and punctuation as-is.

_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 02, 2019 9:24 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Nice exercises, thanks!


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 02, 2019 10:17 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1488
Location: Scotland
Maybe we ought to start to provide solutions ;-)

Lets also not concern ourselves over the fact that from 10 programmers, you'll get (at least) 11 solutions too... e.g. hex print - I have 2 solutions.. And then where do you draw the line when it comes to handling 16-bit numbers - like clearing 1000 bytes - having done a bit of Sweet-16 recently (including a re-implementation of sweet-16), would writing it in sweet16 be acceptable?

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 02, 2019 10:28 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Hmm, I think this thread will stand much better if it doesn't have solutions. Feel free though, to start a new thread with some solutions. I can link to it from the head post here.


Top
 Profile  
Reply with quote  
PostPosted: Sun Mar 03, 2019 1:21 am 
Offline
User avatar

Joined: Mon May 12, 2014 6:18 pm
Posts: 365
Project Euler has a lot of fun problems you can solve in any language. The site keeps track of your progress if you log in, and you can sort the problem list by difficulty. You could reasonably do some of the easier ones in 6502 assembly for practice. For example:

Problem 9:
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,

a^2 + b^2 = c^2
For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.

There exists exactly one Pythagorean triplet for which a + b + c = 1000.

Find the product abc.


Top
 Profile  
Reply with quote  
PostPosted: Sun Mar 03, 2019 3:32 am 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1949
Location: Sacramento, CA, USA
Project Euler looks cool, Druzyek. I have had a nice experience participating in the Rosetta Code wiki as well. Be aware that a bit of petty bickering can pop up from time to time over the edits, though ...

_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)


Top
 Profile  
Reply with quote  
PostPosted: Sun Mar 03, 2019 10:16 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
drogon wrote:
Maybe we ought to start to provide solutions ;-)
-Gordon

I've started a new thread for anyone who'd like to do that. I think it's best for this thread only to be for the sharing of suitable exercises - and I also think it's best to tackle the problems yourself, maybe creating several solutions, before seeing how other people did it. I'm afraid I can resist everything except temptation, and I always look in the back of the book. Don't be me!


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 20, 2019 8:54 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Just turned up nearby, could well be a good exercise: base64-encode a string

And a related problem: write an srecord loader

And even: write a command line interpreter. The prompt should be '*' and the first command to implement is 'help'. The second command to implement is 'go' which has an address as argument, in hex.


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 20, 2019 9:04 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1488
Location: Scotland
BigEd wrote:
Just turned up nearby, could well be a good exercise: base64-encode a string

And a related problem: write an srecord loader

And even: write a command line interpreter. The prompt should be '*' and the first command to implement is 'help'. The second command to implement is 'go' which has an address as argument, in hex.


And would dots be used to shorten commands?

If-so, then I have 90% of that written... ;-)

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 20, 2019 9:07 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
It still might be a good exercise to write it from scratch! (Note that this thread isn't about accumulating a library, it's about learning the idioms of the 6502.)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 14 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: