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

preview_player
Показать описание
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:

Minimal CPU System:
Рекомендации по теме
Комментарии
Автор

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..

johnjosephlonergan
Автор

Another solid video, clear, coscise and to the point.
Thank you for sharing Slu4.

AlanMedina
Автор

This was very helpful video. My CPU was waiting for an assembler until I found this video.

pharos
Автор

Another beautifully minimalistic tool for the Minimal CPU. Way to go @Slu4 !

NilsKullberg
Автор

This channel deserves more subscribers, likes and views

windows.
Автор

Well done, I'm surprised yet another time. This minimalizm idea is so addictive.

daryo_pl
Автор

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!

colonelbarker
Автор

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!

stupossibleify
Автор

Thanks mate, your videos help me a ton!

MarcellDAvis
Автор

damn, that's an incredible video; just asking, do you have a discord server?

DaleDev
Автор

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.

execute
Автор

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).

CallousCoder
Автор

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... ;-)

IBITZEE
Автор

can someone give list of syntax so I can understand what these mnemonics stand for?

harshrawat
Автор

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.

johnfuller
Автор

Thanks a lot. I want to write my own assembler to JVM bytecode compiler.

replikvltyoutube
Автор

That was very interesting. So now you can write you assembler in assembler and not need python, then after that Forth or C ?

DanielSMatthews
Автор

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..

italia
Автор

deutsch?

edit:
hab gesehen in kanalinfo das der standort in deutschland ist

Klungklung
Автор

nice, but since you wrote this in python how was the first assembler written?

drtrouser
welcome to shbcf.ru