Anyone know of programs for visualizing and unders...
# thinking-together
y
Anyone know of programs for visualizing and understanding assembly and/or CPUs? Thinking kind of what Bret Victor does with Learnable Programming and Inventing On Principle but applied to lower level code. I am guessing thereโ€™s industrial software in this general category but am especially interested in programs with a pedagogical angle.
๐Ÿ‘ 2
k
Are you thinking real-world processors? There's a long tradition from SPIM to TIS-100 of designing simple make-believe processors for pedagogical purposes, but I'm sure you know all that..
๐Ÿ‘ 2
e
I haven't seen an assembly language simulator in a long time but i know they exist somewhere. There are simpler processors than the Intel architecture (which is a pretty messy thing), like Z80, etc. The Motorola 68000 was a very regular instruction set, and there is probably some wonderful old stuff out there. Highly instructive to learn assembly language, well worth doing.
๐Ÿ‘ 1
n
There's a HUGE difference between assembly languages and CPU hardware. They're only weakly linked: one encodes computations and the other executes computations. Intel and AMD CPUs haven't executed x86 directly for decades; they compile it into microcode on-the-fly. And CPUs do insanely complex things with scheduling, memories and caches. I would LOVE a good, modern (abstract) CPU emulator that could execute a Wasm program and show me what was happening with scheduling and caches. People have tried this kind of stuff before but I don't know of any nice tools. I've been thinking I will have to make my own (simplistic) simulator at some point if I'm ever going to make a "great" compiler. Otherwise I'll just be applying/benchmarking heuristics "black box"-style and hoping they work well.
s
Maybe a disassembler like binary ninja or Ida pro?
v
http://visual6502.org/ has live JS simulations of a few chips
m
e
wow those chip simulations are incredibly detailed. I would think for most people just learning about opcodes, registers, and the difference in speed between register-register operations vs. register memory would be highly instructive. Given that a memory access can take 100 clocks, we are now in an era where it is crucial to use as many registers as possible.
e
https://www.nand2tetris.org/software is a bit rudimentary but the book is amazing. Would be great if there was a web version of Nand2Tetris
y
@Kartik Agaram would love to hear more! I'm not super familiar with processors! @Nick Smith sure. I should clarify that I'm interested in visualizations that elucidates that bridge between machine code and transistors. @Scott Anderson Thanks for the link, that is really cool! I've seen those box-and-arrow visualizations of jumping before, is that a pretty common feature in disassemblers?
@vitorio that 6502 visualizer is so cool. But I wonder if the physical circuit diagram alone is really that useful for building an understanding from scratch. I wonder if we could provide different levels of perspective and views over it, sort of a logical analogue to what Bret does for circuit diagrams in Media For Thinking The Unthinkable:
๐Ÿ‘ 1
@Emmanuel Oga I love nand2tetris. Did the hardware + VM half of it myself(the compiler part wasn't quite as well-done imo). But the software they provide could be so much more. Would love to see an integrated curriculum where the software seamlessly blends with the learning material.
๐Ÿ‘ 1
s
Not sure if thatโ€™s what youโ€™re looking for, but there is this: http://www.visual6502.org/ Fun fact: it seems still impossible to simulate a 1 Mhz 6502 like this in real-time on contemporary hardware; see https://github.com/mist64/perfect6502/blob/master/README.md
For learning 6502 assembly I quite enjoyed this one: https://skilldrick.github.io/easy6502/
n
I've had ideas about creating something for the purpose of teaching low level concepts all the way up to how they connect to the higher level (languages and programs we use every day). It would have many layers, each layers one concept, and it would show just one concept at a time, but in a zoomable map. It would start by showing the highest level layer - a game running. Then it would zoom in super fast until it reaches the lowest layer - how registers and caches work. Now the user has to go through every layer until they reach the highest layer again. All layers are explained visually. From how the CPU executes instructions, to how it fetches them from registers, to caches, to how the MESI protocol works to keep caches coherent, to how data is fetched from RAM when it isn't in the cache and how slow this is, to how data needs to be fetched from disk, how the CPU feeds data to the GPU, to how all of these systems intertwine together through buses. From this level we should have a pretty good architectural view of how all the systems work together at a low level. From here we zoom out into a higher level to driver land and then to OS land and to how a runtime works to load a PE/ELF into memory. Then we go on to show what is inside an executable and how the data got there - from assembler to compiling and linking to tokenizing and parsing to actual code. At this point there should be a good view of how code actually gets executed. Then we zoom out again to show how code is structured into platform independent layers to abstract networking protocols, file systems, multi-threading, etc. Then how this is used to build core systems for memory allocation, maths, debugging and profiling, etc. Then on to resource systems for textures, materials, 3D models, etc, to the low level renderer where the rendering commands are being dispatched, how data is fetched from the different resources to achieve this. On to the above layers of scene graph management, animation, post processing, HUD, and finally gameplay. This gets us all the way back to the highest layer where the game is running. From this point forward the user is free to go to any layer and play around with some parameters to see how the layers above and below are affected.
๐Ÿ‘ 2
b
The closest thing I can think of today in this vein is https://8bitworkshop.com/ but that is coming at it more from the game programming / content creation side of things. I think the platform might support the observability you are looking for though. I have written a few NES emulators myself (one in CL, one in Reason) with a goal of tracing the running application and visualizing it in a useful way โ€ฆ but they are nowhere near finished ๐Ÿ™ƒ Still, I think the notion of using runtime tracing to build-up a CFG for a game or ROM and allowing the user to inspect the graph/code rather than just sprites or nametables as most emulators do is promising.
๐Ÿ‘ 3
c
Came across this the other day which is quite neat http://thlorenz.com/visulator/
Would be great if there was a web version of Nand2Tetris
Absolutely. It's been on my fantasy todo list since I took that course
๐Ÿ‘ 1
y
@Nuno Leiria I love this vision. It's something I've wanted for a while too: a comprehensive description of a whole stack, simulated in media, approachable from very basic knowledge with a smooth path to global understanding.
โœ”๏ธ 3