4 ms·
I love Advent of Code. If you like programming, Advent of Code probably has something for you. It's a great source of practice problems for learning a new langu
by jstanley 5y ago
I love Advent of Code. If you like programming, Advent of Code probably has something for you. It's a great source of practice problems for learning a new language or style. There's a "competitive" aspect for people who like programming competitions, and you can even make private leaderboards so you can compete against your friends even if you can't make it on to the global leaderboard.
Last year I was earnestly trying to compete on the global leaderboard, and scored points a few times, ending up 103rd overall (slightly frustrating as the displayed leaderboard only goes down to 100th place!), but it's too stressful for me to want to do that again, and in my timezone it requires getting awake in time for the puzzles to be released at 5am.
This year I've been building a homebrew 16-bit CPU from 74xx logic, and have written an operating system and development environment for it, and I plan to do as much as possible of Advent of Code 2021 on my homemade computer.
There are 2 big hurdles to this. The first is that my computer is very slow. It takes over a minute to compile a typical program, which makes for a very long edit-compile-test cycle, and I don't have any hardware multiplication etc., so even integer arithmetic can be quite expensive.
The other hurdle is that it only has 64K words of memory, and IIRC some Advent of Code problems in the past have required keeping track of state for dozens of thousands of separate things. In those cases I'd either fail, or come up with a way to use the disk for extra storage. I look forward to trying, regardless.
As it happens, just this morning I did kind of a "dry run" on problem 1 from 2016 on my homemade computer, and recorded my attempt, which you can watch if you want: https://www.youtube.com/watch?v=UOizI9qi6FU https://www.youtube.com/watch?v=UOizI9qi6FU
- zaarn 5y agoYou could maybe try implementing bank switching to handle more memory. This does make code more complex but it should be possible to use boilerplate to access arbitrary memory. IIRC from when I toyed with making CPUs, a bank switch is implementable as a single extra register which simply drives the upper 16bit (or less) of your address line. It will probably be fairly slow.
- jstanley 5y agoYes, that would be a good way to go. In practice I think bank-switching would be of great value even if none of the programs use it directly: currently context-switching is implemented by dumping the running process to disk and loading the new process from disk. If I had bank-switching then I could context switch much more rapidly by just giving each process its own bank(s) of memory. It's slightly more complicated than just having 1 register to drive the upper bits of the address, because if you just blindly switch on some of the upper bits of the address then suddenly all of your instructions go missing and the CPU starts executing whatever arbitrary bytes happen to be in memory. So you'd want some way to switch out just the parts you want to store data in, while leaving all your code still mapped in. I have an RC2014 with the bank-switching memory expansion. The RC2014 handles it by splitting memory into 4 (I think?) "pages" of 16K each, and allowing you to select which bank backs each page separately.
- zaarn 5y agoI believe the Apollo Guidance Computer used a hardwired lower segment that always points to Bank 0 and one for Bank 1. Then a few freely changeable segments. I also recall some systems where it works just as described, but you had to be incredibly careful about bank switching and IIRC there was a dedicated instruction to write the bank register and program counter register at the same clock cycle.
- dpflug 5y agoBuilding a Forth could tighter your edit-test cycle.
- jstanley 5y agoI am fascinated by Forth, but every time I've tried to learn it I haven't really "got it". It's always felt very unwieldy to me. But implementing Forth on my CPU, and getting proficient at using it, is definitely something I'd like to do at some point!
- thoughtFrame 5y agoI don't know if I'm not creative enough but what I've read about Forth tells you about the stack, about how to make new words, push arguments and pop to print. But that's it, and I can't figure out how to get things done with those building blocks. There's the famous washing machine example but there's not much else about doing things with it. It's something that many programming language tutorials miss: exploring the possibility space and teaching you the language's expressive power
- Jtsummers 5y agoStarting Forth: https://www.forth.com/starting-forth/ https://www.forth.com/starting-forth/ Thinking Forth: http://thinking-forth.sourceforge.net/ http://thinking-forth.sourceforge.net/ In combination, very effective introduction to programming in Forth including how to go about combining those building blocks.
- bdowling 5y ago> I am fascinated by Forth, but every time I've tried to learn it I haven't really "got it". Try reading Jonesforth, a literate Forth implementation in one x86 assembly file and one Forth file. You can read it top to bottom and it will explain how everything works step-by-step. https://rwmj.wordpress.com/2010/08/07/jonesforth-git-repository/ https://rwmj.wordpress.com/2010/08/07/jonesforth-git-reposit... Github mirror: https://github.com/nornagon/jonesforth https://github.com/nornagon/jonesforth
- rak1507 5y agoThis is seriously cool. Nice one.
- scoot 5y agoDo you have more info on your processor build? Sounds fascinating! I hoped that there might be a video on your channel, but it didn't appear so.
- jstanley 5y agoI don't have a great single resource unfortunately. I'd like to put up a web page about it at some point. This is the github repo that contains everything: https://github.com/jes/scamp-cpu/ https://github.com/jes/scamp-cpu/ - some of the stuff under "doc/" might be what you're after (but some of it is just incoherent ramblings). I have some blog posts here: https://incoherency.co.uk/blog/tags/cpu.html https://incoherency.co.uk/blog/tags/cpu.html And there is a video here, but it's not really very informative: https://www.youtube.com/watch?v=4sBB0iD6XvI https://www.youtube.com/watch?v=4sBB0iD6XvI
- templeosenjoyer 5y agoUnrelated but your automated chess board[1] is wonderful. Good work! [1] https://www.youtube.com/watch?v=8ScFtkWvHW8 https://www.youtube.com/watch?v=8ScFtkWvHW8