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

  Рет қаралды 1,728

Fabian Schuiki

Fabian Schuiki

Күн бұрын

The assembler I wrote from scratch is a pretty convenient tool to build programs for my homebrew CPU. Manually computing address offsets for jump instructions isn't fun though. In this video, I extend my assembler to support the usual syntax for declaring jump labels and using them in actual jump instructions.
This video series explores the concepts and techniques that make modern computer processors so incredibly fast and powerful. I build my very own 8-bit processor from individual logic gates and gradually evolve it to become a superscalar out-of-order machine. Along the way, we take a deep dive into contemporary computer architecture in a hands-on fashion and rediscover some of the foundations of modern computing.
Previous Video: • Adding Conditional Mov...
Series Playlist: • Build a Superscalar CPU
Assembler Playlist: • Assembler from Scratch
GitHub Repository: github.com/fabianschuiki/supe...
- Assembly Language: en.wikipedia.org/wiki/Assembl...
00:00 - Intro
02:16 - Label Declarations
05:56 - Labels As Operands
10:10 - Encoding Labels as Jump Offset
12:42 - Computing Label Offsets
14:39 - Resolving Label Names
22:58 - Using Labels in Programs
24:41 - Outro
#assembler #compiler #homebrew #computer

Пікірлер: 23
@OscarSommerbo
@OscarSommerbo 10 күн бұрын
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 10 күн бұрын
Yeah, it was about time to add those 😁
@mekafinchi
@mekafinchi 10 күн бұрын
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 10 күн бұрын
That is a fantastic suggestion, thanks a lot! Will definitely add those 🙂👍
@DavidLatham-productiondave
@DavidLatham-productiondave 10 күн бұрын
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 10 күн бұрын
@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 10 күн бұрын
Very nice and tight video. Pacing was just right.
@fabianschuiki
@fabianschuiki 10 күн бұрын
Thanks! 😃 Trying to be a bit more on-point 😉
@anon_y_mousse
@anon_y_mousse 18 сағат бұрын
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 14 сағат бұрын
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.
@milesrout
@milesrout 8 күн бұрын
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 8 күн бұрын
😃 I'll definitely go and fix the syntax highlighting at some point!
@perkyelixir2254
@perkyelixir2254 10 күн бұрын
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 10 күн бұрын
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 😃
@fab4key
@fab4key 10 күн бұрын
You can ass more things into assember as .align, .text and .data
@fabianschuiki
@fabianschuiki 10 күн бұрын
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.
@lawrencemanning
@lawrencemanning 10 күн бұрын
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 10 күн бұрын
I haven't really played around with it. The prospect of writing an assembler totally from scratch was too exciting 😅
@lawrencemanning
@lawrencemanning 10 күн бұрын
@@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!
@fab4key
@fab4key 10 күн бұрын
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 10 күн бұрын
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 10 күн бұрын
It's called the walrus operator. Which is kinda cute.
@fabianschuiki
@fabianschuiki 10 күн бұрын
@DavidLatham-productiondave Haha, I love that name 😂
Adding Conditional Moves to My CPU - Superscalar 8-Bit CPU #38
59:23
Fabian Schuiki
Рет қаралды 1,4 М.
How Computers Fake Negative Numbers - Superscalar 8-Bit CPU #29
48:57
3 wheeler new bike fitting
00:19
Ruhul Shorts
Рет қаралды 48 МЛН
버블티로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 56 МЛН
Always be more smart #shorts
00:32
Jin and Hattie
Рет қаралды 30 МЛН
The day of the sea 🌊 🤣❤️ #demariki
00:22
Demariki
Рет қаралды 79 МЛН
My Brain after 569 Leetcode Problems
7:50
NeetCode
Рет қаралды 2,4 МЛН
Git MERGE vs REBASE: The Definitive Guide
9:39
The Modern Coder
Рет қаралды 85 М.
Radix Sort - Made EASY!
2:15
Deltaverse
Рет қаралды 101
I built my own 16-Bit CPU in Excel
16:28
Inkbox
Рет қаралды 1,4 МЛН
Understanding B-Trees: The Data Structure Behind Modern Databases
12:39
Encode Instructions in My Assembler - Superscalar 8-Bit CPU #25
21:53
Fabian Schuiki
Рет қаралды 1,3 М.
Why Do Computers Use 1s and 0s? Binary and Transistors Explained.
7:00
Basics Explained, H3Vtux
Рет қаралды 4,2 МЛН
Learn To Code Like a GENIUS and Not Waste Time
9:41
The Coding Sloth
Рет қаралды 1,2 МЛН
I Designed A CPU (And So Can You)
19:14
Owen Gibson
Рет қаралды 9 М.
How do computers read code?
12:01
Frame of Essence
Рет қаралды 3 МЛН
#miniphone
0:16
Miniphone
Рет қаралды 3,5 МЛН
APPLE совершила РЕВОЛЮЦИЮ!
0:39
ÉЖИ АКСЁНОВ
Рет қаралды 3,7 МЛН
WWDC 2024 Recap: Is Apple Intelligence Legit?
18:23
Marques Brownlee
Рет қаралды 6 МЛН
Хотела заскамить на Айфон!😱📱(@gertieinar)
0:21
Взрывная История
Рет қаралды 3,7 МЛН
Секретный смартфон Apple без камеры для работы на АЭС
0:22