Adding Labels to My Assembler - Superscalar 8-Bit CPU #39

Поділитися
Вставка

КОМЕНТАРІ • 23

  • @OscarSommerbo
    @OscarSommerbo 3 місяці тому +8

    YES!! Labels! Finally, something I would have added way earlier. But then I come from a C background and I learned assembler backwards by looking at the compiled byte code, and labels are essential. Of course, you can do what Fabian have been doing so far calculating his own jump offsets, but when you have an incredibly powerful calculator why not use it. 😊
    This will be a fun episode I bet.

    • @fabianschuiki
      @fabianschuiki  3 місяці тому +1

      Yeah, it was about time to add those 😁

  • @mekafinchi
    @mekafinchi 3 місяці тому +8

    One feature I'd strongly recommend are local labels - where using a prefix (usually '.') prepends the most recent normal label to the logical name of a label. This lets you have descriptive names without global scope rather than being limited to globals or numbers. Local labels could also be accessible from any context by using the full logical name e.g. "normal.local" referring to ".local" in "normal" even outside normal's block

    • @fabianschuiki
      @fabianschuiki  3 місяці тому +5

      That is a fantastic suggestion, thanks a lot! Will definitely add those 🙂👍

    • @DavidLatham-productiondave
      @DavidLatham-productiondave 3 місяці тому +1

      I also use unnamed labels in ca65.
      An unnamed label is a : by itself. Then you can branch to a count of unnamed labels in forwards or backwards direction. Unnamed labels are scoped from the previous normal label until immediately before the next normal label.
      Eg.(6502)
      ```
      count_to_65536:
      ; here unnamed labels are scoped to count_to_65536
      ldx 0
      : ldy 0
      : iny
      beq :-
      inx
      beq :--
      next_lable:
      ; here unnamed labels are scoped to next_label
      ```

    • @fabianschuiki
      @fabianschuiki  3 місяці тому +1

      @DavidLatham-productiondave That's a pretty neat approach! I like how this doesn't clutter the text at all. The relative labels I have implemented tend to be just `1:` and `2:` in practice... Makes sense to leverage that and provide more compact syntax! 👍

  • @OscarSommerbo
    @OscarSommerbo 3 місяці тому +2

    Very nice and tight video. Pacing was just right.

    • @fabianschuiki
      @fabianschuiki  3 місяці тому

      Thanks! 😃 Trying to be a bit more on-point 😉

  • @milesrout
    @milesrout 3 місяці тому +1

    Good stuff. Pity the syntax highlighting of '1f' and '1b' isn't the same in your text editor though. Custom syntax highlighting is tedious but so nice once you do it. It's pretty easy in Sublime Text too if I remember correctly (I haven't used Sublime in over 10 years!). Just a few regular expressions. I wrote an assembler and emulator during the 0x10c/DCPU-16 craze. I pretty sure more assemblers were written and published online as free software in the space of a month than have ever been written in any other calendar month in history.

    • @fabianschuiki
      @fabianschuiki  3 місяці тому

      😃 I'll definitely go and fix the syntax highlighting at some point!

  • @anon_y_mousse
    @anon_y_mousse 3 місяці тому +1

    You might want to consider '.' as a valid label character as well. Not that prior examples really matter here, but `gcc` does use '.L' as a label prefix, and I'm not sure if it has the same semantics as it does for `nasm`, but in `nasm` it's used for local labels so you could have a .L1 in each function and it would still work. Just 0xf00d for thought.

    • @fabianschuiki
      @fabianschuiki  3 місяці тому +1

      That's an excellent point! I like the idea of giving special meaning to labels starting with a `.` and treating them as relative/scoped to the previous label that did not have a leading `.`. Very elegant.

  • @perkyelixir2254
    @perkyelixir2254 3 місяці тому +2

    i realize this might be a bit much to ask, but if you would make a video on writing an llvm backend (or some other high level language thing) at some point in the future, that would be great

    • @fabianschuiki
      @fabianschuiki  3 місяці тому +1

      That's a great idea! I've been toying with the thought of taking the assembler and building out a simple IR and register allocation, to conceptually explore what LLVM and other compiler backends do. Adapting LLVM for my CPU would be a very nice thing to do 😃

  • @sysfab
    @sysfab 3 місяці тому +1

    Cool video! Your channel actualy very helped me with my own assembler written in Lua. Can i ask what ':=' in if statement means?

    • @fabianschuiki
      @fabianschuiki  3 місяці тому

      Thanks! 🙂 `:=` assigns the value on the right to the variable on the left, and also returns the value on the right. It's a nice way to check if a value is not none in an if, and then have the value available in a variable inside the if block.

    • @DavidLatham-productiondave
      @DavidLatham-productiondave 3 місяці тому +1

      It's called the walrus operator. Which is kinda cute.

    • @fabianschuiki
      @fabianschuiki  3 місяці тому

      @DavidLatham-productiondave Haha, I love that name 😂

  • @lawrencemanning
    @lawrencemanning 3 місяці тому +1

    I use CustomASM for my softcore. It’s far from perfect, but it’s pretty good. Have you played with it? Not that there’s anything wrong with doing it yourself, even if CustomASM meets all your needs. 😊

    • @fabianschuiki
      @fabianschuiki  3 місяці тому +1

      I haven't really played around with it. The prospect of writing an assembler totally from scratch was too exciting 😅

    • @lawrencemanning
      @lawrencemanning 3 місяці тому +1

      @@fabianschuikiyes indeed! I will probably look at it eventually. One of the thing CustomASM can’t do (AFAIK) is generate linkable objects, so you end up with includes to bring in your “modules”. It works, but it’s not nice. I shall have a look at your other videos later; I’ve never been brave enough to build a processor on breadboard and have massive respect for folks who take this on!

  • @sysfab
    @sysfab 3 місяці тому +1

    You can ass more things into assember as .align, .text and .data

    • @fabianschuiki
      @fabianschuiki  3 місяці тому

      Absolutely! Once the assembler supports expression evaluation, a lot of cool other features get unlocked in a sense. I like the idea of having segments like `text` and `data`, and allowing the user to lay those out in memory. Also, having the ability to plop down data and strings would be really handy.