FOSDEM 23: Learn 8-bit machine language with the Toy CPU emulator
Вставка
- Опубліковано 3 лют 2023
- Thanks to FOSDEM for allowing me to give a remote presentation today about the Toy CPU emulator I wrote on FreeDOS.
Some additional background: I teach a university class about the history of computing. To explain how early computers worked, I created the Toy CPU emulator - a reduced instruction set computer in the style of the Altair 8800 or IMSAI 8080. In this presentation, I'll explain how I created the Toy, and how to create and enter programs into the Toy.
You enter programs into the Toy using "switches and lights" - the Toy simulates LEDs for each counter and instruction, and the accumulator value. We'll create a few simple programs and enter them into the Toy using 8-bit machine language. The Toy CPU is a great way to learn about machine language programming!
FOSDEM 23: fosdem.org/2023/schedule/even...
Toy CPU on GitHub: github.com/freedosproject/toycpu
Visit our website
www.freedos.org/
Join us on Facebook
/ freedosproject
Follow us on Mastodon
fosstodon.org/@freedosproject
Consider supporting me on Patreon
/ freedos
And don't forget to Like and Subscribe!
Standard comment rules apply. - Наука та технологія
Love this, Jim. A couple of features I think would be neat:
* single-stepping
* Save and load
* And of course, Kill the Bit
I’ve got an actual Altair 8800, but this is nice to fire up when I want to play with some ideas.
That would be neat additions! If I make another update to the ToyCPU, I'll see if I can do those. Especially save/load and single-step. Or feel free to make the changes and send me a pull request.
This was an amazing introduction to machine language,
If I understand this correctly, everything happens in the accumulator, so when we execute a LOAD instruction it loads what in specified in the address into the accumulator, and when we call ADD instruction it adds what in specified address to the accumulator, and we optionally can store the values in the accumulator to a new memory address.
I hope I got it right?
I always wanted to learn machine language as I know it executes very fast,
Thanks Jim,
You got it right. LOAD will copy a value from memory into the accumulator. And ADD will add a value from memory to the accumulator, and the accumulator is the sum. And so on for the other instructions.
@@freedosproject Finally I feel close to its Binary heart more than before 😎
Thanks Jim, more input please 😁
Hi Jim, this has nothing to do with FreeDOS, but are you aware of a game called Turing Complete? It's available on Steam and your Toy CPU emulator reminded me a bit of it. It starts on an even lower level, though: You have nothing but a NAND gate, and you have to use that to build other logic elements first, then simple bit adders, byte adders, switches, decoders, then registers, memory cells, etc. Then you have to design an ALU, a stack, a command decoder, a flow control unit, until you have everything you need for a little CPU. It ends with programming challenges: First you have to define your own assembly language for your CPU, and use that to solve a few puzzles like implementing a Towers-of-Hanoi algorithm.
It's a fascinating little game for nerds, and maybe it could be useful for your students, too.
Haven't heard of that one - I'll have to look it up
@@freedosproject I'd love to hear how you like it. When you're done with all the missions, you can continue in a sandbox and share your works online. Some crazy genius already implemented an entire Risc V CPU, booted bare metal Rust on it and ran a chess game. It's insane what people do just because they can. I mean, some even rewrite DOS and keep it alive in the 2020s :)
Turing complete goes pretty fast from "invert this signal" to now build a CPU. Not really for beginners, more like last year students.
@@TheKetsa That's true. A beginner without guidance will probably get stuck at the CPU level. But there are tutorial videos for each level, many even by the developer himself, here on UA-cam. For people who want to actively explore and re-enact the evolution from a logic gate to a CPU, it's perfect. Jim's toy CPU would be just one of the many steps in that game.
I think the lower levels, up to adding and multiplying binary numbers, are fine even for beginners, though.
Thank you Jim!
Very welcome ☺
yo this is awesome! i got my start with the z80 a couple of years ago when i saw ben eaters videos! I saw that digikey still sells the darn things and i made a small computer from one. no os or monitor, its just bare asm in rom to bang bytes to an 8255 and a serial chip to spit out hello world over serial to a terminal. this is fantastic and i love this. This is such a good way to share my passion with low level things such as this with other people. thank you so much
Reminder: Protogens go beep boop.
Thanks! I thought it was a cool project, and I'm glad others do too!
Very nice thanks.
I'm glad you like it! ☺
You can do more complicated operations too. Here's a program to multiply two numbers, stored in memory addresses 31 and 32. So you don't get lost when entering this into the Toy, I'll list each instruction with its counter (where it should appear in memory):
counter:instruction
00000000:LOAD
00000001:00011101
00000010:STORE
00000011:00100001
00000100:LOAD
00000101:00100000
00000110:IFZERO
00000111:00011010
00001000:STORE
00001001:00100010
00001010:LOAD (start of the loop)
00001011:00100001
00001100:ADD
00001101:00011111
00001110:STORE
00001111:00100001
00010000:LOAD
00010001:00100010
00010010:SUB
00010011:00011110
00010100:STORE
00010101:00100010
00010110:IFZERO
00010111:00011010
00011000:GOTO
00011001:00001010
00011010:LOAD (end of program)
00011011:00100001
00011100:STOP
00011101:00000000 (zero)
00011110:00000001 (one)
00011111:00000011 (first number = 3)
00100000:00000010 (second number = 2)
00100001:11111111 (product gets stored here)
00100010:11111111 (counter variable)
If you don't care about preserving the second number, you could do away with the counter and instead work directly on the value stored in 00100000. But I wanted to keep the original value in memory, so I made a copy.
Me podrás explicar que es esto exactamente? Saludos desde URUGUAY.