Тёмный

Let's Code a Minimal Assembler from Scratch in Python (100 Lines) 

Slu4
Подписаться 7 тыс.
Просмотров 28 тыс.
50% 1

I am coding a small assembler that translates a human-readable source file to executable machine code. As a target machine I use my DIY CPU - it's called the 'Minimal CPU' - but the base idea of this assembler could be adapted to any CPU really. You won't need any deep understanding of the CPU's inner workings. What I am showing won't be a very sophisticated piece of software. Instead, I follow my own approach as a learning experience.
Assembler Source Code:
github.com/slu4coder/Minimal-...
Minimal CPU System:
• Minimal UART CPU Goes ...
• Simplest Usable PC?
github.com/slu4coder/Minimal-...

Наука

Опубликовано:

 

30 апр 2021

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 58   
@AlanMedina314
@AlanMedina314 3 года назад
Another solid video, clear,coscise and to the point. Thank you for sharing Slu4.
@slu467
@slu467 3 года назад
Glad you find it useful!
@johnjosephlonergan
@johnjosephlonergan 3 года назад
By building my own "TTL" homebrew cpu I've learned the hard way that whilst this video is alluring it doesn't explain the limitations and tradeoffs of the minimalistic approach. I don't have an academic compsci background and had never written an assembler or compiler before starting work on my own homebrew TTL cpu but ... as your instruction set and assembler becomes more sophisticated then a multipass assembler becomes increasingly complex and a tangle. In my experience parsing the ASM into an abstract syntax tree and then evaluating the tree, tend to lead to a more extensible and cleaner design. The benefits of the AST approach / lesson learned became more obvious as a learning exercise once one tries to build a high level language (eg something C like or whatever) for your home brew cpu - don't try it without an AST unless you love exercises in complexity. So I'd see the more scalable AST based approach for an assembler as a sensible stepping stone in learning how to build a compiler, but the multipass approach is definitely the initial approach most folk will end up with unless they have the premonition of storms ahead. AST's tend to end up using recursion as opposed to the itertive approach of multipass - but the result is worth it from a scalability point of view..
@slu467
@slu467 3 года назад
John, from a standpoint of a serious developer I am absolute with you! But since I am only interested in very basic principles and since I am well aware of the overall limitations of my hardware I won't make the mistake of trying to push things too far on this little platform. It's simply not "worth" it :-) Having that said: I have just finished math expression parsing, a text editor and will soon finish a native assembler. Another "Minimal" team member (a senior software developer) is working on a BASIC JIT compiler. He is working wonders on this architecture and has already completed a FIG Forth :-) Stay tuned...
@pharos640
@pharos640 Год назад
This was very helpful video. My CPU was waiting for an assembler until I found this video.
@DariusMikolajczyk
@DariusMikolajczyk 3 года назад
Well done, I'm surprised yet another time. This minimalizm idea is so addictive.
@slu467
@slu467 3 года назад
Hi Dariusz, you are right... once you start with it...
@windows1.0
@windows1.0 2 года назад
This channel deserves more subscribers, likes and views
@NilsKullberg
@NilsKullberg 3 года назад
Another beautifully minimalistic tool for the Minimal CPU. Way to go @Slu4 !
@slu467
@slu467 3 года назад
Thank you, Nisse :-D I've heard you're working on some amazing stuff for the Minimal CPU, too... Forth, BASIC, JIT compiler...
@NilsKullberg
@NilsKullberg 3 года назад
@@slu467 Right! The Minimal family is growing. A FORTH programming environment is available via Github. Look for "Minimal-FORTH". A modern BASIC is on its way. I hope to have it available via Github during the summer.
@slu467
@slu467 3 года назад
@@NilsKullberg Awesome, Nils! That's takin' it to the next level :-D Thanks for being part of the 'Minimal' team!
@MarcellDAvis1103
@MarcellDAvis1103 3 года назад
Thanks mate, your videos help me a ton!
@colonelbarker
@colonelbarker 3 года назад
Thanks for this, I want to write my own for my own minimal computer design and it's nice to see a method used. I need to finish up this very of the minimal soon as well!
@slu467
@slu467 3 года назад
Hi Aaron, happy to hear that you can use it or your own design :-)
@adamhuk447
@adamhuk447 3 года назад
Great content as always. Thank you!
@slu467
@slu467 3 года назад
Thanks for tuning in, Adam!
@stupossibleify
@stupossibleify 3 года назад
Perfect video for my computer architecture thirst on a Saturday morning! Fascinating explanation of assembler operation and a great in insight into some broad Python concepts. A veritable tour de force!
@slu467
@slu467 3 года назад
Thanks, glad you like the way I build my assembler. It *is* a bit off the beaten track I've heard...
@francoisdastardly4405
@francoisdastardly4405 3 года назад
Man !! You are incredible!!!
@slu467
@slu467 3 года назад
Thanks a lot, Francois. Glad you like this stuff, too :-)
@imantssakne9486
@imantssakne9486 Год назад
Amazing!!!!Cool :)
@amnesie6615
@amnesie6615 3 года назад
Einfach toll! Danke!
@slu467
@slu467 3 года назад
:-D
@execute214
@execute214 11 месяцев назад
Lovely. I'm trying to make an assembly language for a programming game. I won't quite translate it to bytecode, instead I'll transpile it to Lua. I thought it would be fun to explore youtube for some videos about assemblers.
@DaleDev
@DaleDev 3 года назад
damn, that's an incredible video; just asking, do you have a discord server?
@slu467
@slu467 3 года назад
There is a user forum available at minimal-cpu-system.boards.net/
@johnfuller1588
@johnfuller1588 3 года назад
Will the upcoming Minimal CPU 1.5 require a board revision, or just a flash chip upgrade to something like the 28SF040? Just wanting to verify before I order boards.
@slu467
@slu467 3 года назад
Hi John, I suggest you wait for the revision 1.5 to come out. I am just starting work on the release video. The hardware is long finished. It *will* require a new board - but it will we worth it promise (double speed, 512KB SSD and an expansion port to connect *anything*). Cheers!
@johnfuller1588
@johnfuller1588 3 года назад
@@slu467 Thank you. I am anxious to learn (have built Ben Eater and a couple each 6502 and Z80 SBCs, but really want to understand the real fundamentals you are teaching) and look forward to 1.5. Your explanation videos are top notch.
@harshrawat8162
@harshrawat8162 Год назад
can someone give list of syntax so I can understand what these mnemonics stand for?
@slu467
@slu467 Год назад
Hi, if you are referring to the Minimal UART 1.5 please consult the reference manual. The link is given in the video descriptions of this series or in the GitHub readme.
@DanielSMatthews
@DanielSMatthews 3 года назад
That was very interesting. So now you can write you assembler in assembler and not need python, then after that Forth or C ?
@slu467
@slu467 3 года назад
Hi Daniel, yes, now I'll port this over to the Minimal to have it run natively. But I'll need a simple editor, too. FORTH already exists! See the post of Nils Kullberg further below with the link therein. He is part of the 'Minimal' development team and is currently working wonders on a 'Minimal BASIC' using a JIT compiler - also running natively.
@richardappow6770
@richardappow6770 Месяц назад
the source code for the assembler is missing on your github link. please reupload
@IBITZEE
@IBITZEE Год назад
dude... you are a genius.... now come up with a highly optimized ISA of 255 instructions (byte size)... a 16 32bit register CPU with all registers also byte#4/word#2 addressable... a 32 bit addressable memory space... (a optional version will be 64 bit addressable) and you are in the right track for the cheap Universal-Processor that will be pervasive to all controllable devices... ;-)
@philtoa334
@philtoa334 Год назад
WWhhaaao ! 😳 Great.
@drtrouser
@drtrouser Год назад
nice, but since you wrote this in python how was the first assembler written?
@slu467
@slu467 Год назад
Hi, back in the old days a "first" assembler on a new platform had to be coded in machine language on a piece of paper and written into memory directly via front panel toggle switches (see PDP-8 for example) Very painful indeed ;-)
@replikvltyoutube3727
@replikvltyoutube3727 2 года назад
Thanks a lot. I want to write my own assembler to JVM bytecode compiler.
@slu467
@slu467 2 года назад
Glad you consider this helpful. Good luck ;-)
@CallousCoder
@CallousCoder 2 года назад
You should use regular expressions instead of these string functions. Makes your code smaller, faster and more readable (assuming you learned regex, which I advise all).
@slu467
@slu467 2 года назад
CallousCoder, this asm was meant to be portable to a *very* limited machine. Hence, I only use the very basics.
@CallousCoder
@CallousCoder 2 года назад
@@slu467 and then you code in Python? C with preg lib or even C++ with stl would’ve been just as portable.
@italia1990
@italia1990 2 года назад
osea... estas traduciendo el codigo en hexadecimal para insertarlo en texto nuevamente y executarlo.. ... no seria mas facil y menos lineas traducir el hex dentro de un buffer y despues ejecutarlo al viejo y puro estilo de un shell code ? ..porque veo que de todas maneras veo que estas compilandolo el codigo asm para ver el codigo hexadecimal de las instrucciones..
@slaquers
@slaquers 2 года назад
Sub'd, thx
@kayezero703
@kayezero703 3 года назад
رائعة
@whoblue579beta3
@whoblue579beta3 3 года назад
أنا موافق
@kayezero703
@kayezero703 3 года назад
@@whoblue579beta3 عربي لو مترجم قوقل
@whoblue579beta3
@whoblue579beta3 3 года назад
@@kayezero703 ':-D
@Klungklung123
@Klungklung123 Год назад
deutsch? edit: hab gesehen in kanalinfo das der standort in deutschland ist
@slu467
@slu467 Год назад
Ja, genau 🙂
@victorianexplorer
@victorianexplorer 3 года назад
nomads of mongolia!
@alexreg78
@alexreg78 2 года назад
тще not be abAB USE ED)) COMPILE IN QWANT)) JORNEY YOU
@edgeeffect
@edgeeffect 3 года назад
I really like what you've done here. I'd like to have an assembler where the source file actually IS the Python (well, I'd prefer Ruby - but it's all the same) that way any constants or assemble-time expressions can be prepared or calculated in a nice scripting language. (we had something like this for the 6502 in BBC BASIC back in the 1980s) I've been looking at github.com/keystone-engine/keystone but it's far too complicated... I'm thinking I might be able to do something using a more minimal approach... and you've inspired me to try this again now.
@slu467
@slu467 3 года назад
Glad to hear that it inspired you! But beware, this approach is (barely) okay for simple assembler syntax. It is way too unsophisticated to parse any "higher" language. One would need to implement expressions with BNF and stuff... and you are well over 32KB land...
@edgeeffect
@edgeeffect 3 года назад
@@slu467 most of what I do is little microcontrollers and 32k is pretty much my upper limit. :) but I am worried that my ISAs might be a bit too complex for a minimal minimal approach.... I'll have to see how it pans out.
@stephenlord8005
@stephenlord8005 Год назад
ivea. to you. space in invaers
Далее
FLASH File System on a Shoestring
5:52
Просмотров 3,6 тыс.
На фейсконтроле 💂
09:41
Просмотров 457 тыс.
БАТЯ И СОСЕД😂#shorts
00:59
Просмотров 2,2 млн
Computer Language from Scratch #2 MIN at Work
17:54
Просмотров 2,3 тыс.
Assembly Programming is Hard…
20:00
Просмотров 102 тыс.
I Designed My Own 16-bit CPU
15:46
Просмотров 1,9 млн
Comparing C to machine language
10:02
Просмотров 5 млн
Let's Write an Interpreter (in 168 Lines of Python)
17:19
The Truth About Learning Python in 2024
9:38
Просмотров 166 тыс.
8-Bit Adder built from 152 Transistors
12:25
Просмотров 641 тыс.
КРУТОЙ ТЕЛЕФОН
0:16
Просмотров 7 млн