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

Поділитися
Вставка
  • Опубліковано 27 жов 2024

КОМЕНТАРІ • 59

  • @johnjosephlonergan
    @johnjosephlonergan 3 роки тому +18

    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 роки тому +8

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

  • @AlanMedina314
    @AlanMedina314 3 роки тому +10

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

    • @slu467
      @slu467  3 роки тому

      Glad you find it useful!

  • @NilsKullberg
    @NilsKullberg 3 роки тому +3

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

    • @slu467
      @slu467  3 роки тому +1

      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 роки тому +2

      @@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!

  • @pharos640
    @pharos640 2 роки тому +1

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

  • @daryo_pl
    @daryo_pl 3 роки тому +4

    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 роки тому +1

    This channel deserves more subscribers, likes and views

  • @colonelbarker
    @colonelbarker 3 роки тому +2

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

  • @DaleDev
    @DaleDev 3 роки тому +4

    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/

  • @stupossibleify
    @stupossibleify 3 роки тому +1

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

  • @MarcellDAvis1103
    @MarcellDAvis1103 3 роки тому +1

    Thanks mate, your videos help me a ton!

  • @francoisdastardly4405
    @francoisdastardly4405 3 роки тому +1

    Man !! You are incredible!!!

    • @slu467
      @slu467  3 роки тому +1

      Thanks a lot, Francois. Glad you like this stuff, too :-)

  • @adamhuk447
    @adamhuk447 3 роки тому +1

    Great content as always. Thank you!

    • @slu467
      @slu467  3 роки тому

      Thanks for tuning in, Adam!

  • @CallousCoder
    @CallousCoder 2 роки тому +1

    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 роки тому +1

      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.

  • @execute214
    @execute214 Рік тому

    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.

  • @harshrawat8162
    @harshrawat8162 Рік тому +1

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

    • @slu467
      @slu467  Рік тому +1

      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.

  • @amnesie6615
    @amnesie6615 3 роки тому

    Einfach toll! Danke!

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

  • @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 роки тому +1

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

  • @richardappow6770
    @richardappow6770 4 місяці тому

    the source code for the assembler is missing on your github link. please reupload

  • @imantssakne9486
    @imantssakne9486 Рік тому

    Amazing!!!!Cool :)

  • @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 роки тому +2

      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.

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

  • @TheGamingDinosaurRoblox
    @TheGamingDinosaurRoblox 2 місяці тому

    there is no source code on the github

  • @replikvltyoutube3727
    @replikvltyoutube3727 3 роки тому

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

    • @slu467
      @slu467  3 роки тому

      Glad you consider this helpful. Good luck ;-)

  • @Klungklung123
    @Klungklung123 Рік тому +1

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

    • @slu467
      @slu467  Рік тому

      Ja, genau 🙂

  • @drtrouser
    @drtrouser 2 роки тому +1

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

    • @slu467
      @slu467  2 роки тому +2

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

  • @philtoa334
    @philtoa334 2 роки тому

    WWhhaaao ! 😳 Great.

  • @kayezero703
    @kayezero703 3 роки тому +2

    رائعة

  • @slaquers
    @slaquers 2 роки тому

    Sub'd, thx

  • @victorianexplorer
    @victorianexplorer 3 роки тому

    nomads of mongolia!

  • @alexreg78
    @alexreg78 2 роки тому +1

    тще
    not be abAB USE ED))
    COMPILE IN QWANT))
    JORNEY YOU

  • @edgeeffect
    @edgeeffect 3 роки тому +1

    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 роки тому +1

      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 Рік тому +1

    ivea. to you. space in invaers