5 ms·
> C will teach you how computers think. It will teach you how a PDP-11 thinks, at best. The cache hierarchy and speculative execution are completely hidden at
by Twisol 4y ago
> C will teach you how computers think.
It will teach you how a PDP-11 thinks, at best. The cache hierarchy and speculative execution are completely hidden at the level of C, to start with.
You want to learn how computers think, pick up an assembly language. (Any one will do.) You want to build portable low-level software, learn Rust, Zig, C, or C++ (in my personal order of preference).
- antegamisou 4y ago> You want to learn how computers think, pick up an assembly language. For which you'd need to be familiar with a low-level language like C.
- Filligree 4y agoAssembly was my first language. I had no trouble picking that up, and in fact didn't meet a compiler until ten years later. They were much too expensive at the time.
- ImprobableTruth 4y ago... no? In fact I think learning assembly before C makes a lot more sense than the other way around.
- orobinson 4y agoThis. The computer science degree I did started off in the first term with us building computers on an FPGA by mapping out the logic gates, then programming it in assembly. Learning how to program in C followed this. It's a good way of helping people with no programming knowledge get past the stage of "what are those magic colourful words you type that somehow make the computer do things?".
- stjohnswarts 4y agoI think this is an awful way of learning for beginning CS students. It will scare off too many good kids who think this is all that CS will ever be. Top down is better. Bottom up is only going to be good for people who adore computer architecture guts and want to start at the bottom from first principals. Most kids want to use computers as a tool and not learn it's atomic structure.
- stjohnswarts 4y agoUnless you're experienced well in some other language then assembly is going to scare you off. I learned assembly by looking at -O0 output from c compiler code. Then I went ahead and dived in. Just doing bare assembly is not somewhere a beginner should start unless they are just absolutely in love with low level programming.
- jcranmer 4y agoNo, you don't. In the curriculum I've taught, assembly was taught before C. As long as you have any programming language experience, you should be fine with assembly--I've explained it in terms of even MATLAB before.
- HideousKojima 4y agoI learned CHIP-8 asm and Gameboy asm before ever touching C
- pwpw 4y agoI want to learn how to build emulators for CHIP-8 and Gameboy and am having the person tug-of-war over assembly, C, or Rust. With hindsight, do you recommend doing them in assembly? And what resources did you use to get started?
- HideousKojima 4y agoI wrote my CHIP-8 emulator in C#, actually. I used the Godot game engine for rendering and sound (though I never actually got around to implementing sound). The language you write it in really doesn't matter too much unless you really care about performance, or if you want to do something fancier than an interpreter (like a JIT recompiler). I used this guide: https://tobiasvl.github.io/blog/write-a-chip-8-emulator/ https://tobiasvl.github.io/blog/write-a-chip-8-emulator/ I haven't made a Gameboy emulator, just learned the assembly so I could modify some roms.
- gotlou 4y agoI wrote a CHIP-8 emulator[0] a while back in C using SDL2 for rendering everything. It still has a couple issues with the timers and taking input. I was new to C back then so I did this project to become more familiar with it. You can check out my blog post[1] if you're interested how I went about it (there are a couple resources at the bottom I used to build it, including the one that HideousKojima recommended). As for language, in hindsight, C was fine. CHIP-8 is so basic that you don't really need to worry about performance or to implement a JIT compiler unless you want to learn how to do those things specifically. Just pick any one out of the three (assembly is a bit of a weird choice though, why not write a CHIP-8 emulator and then a brand new program to run on that emulator in CHIP-8 assembly if you want to learn assembly?) As for Gameboy, it would have more instructions, a different graphics system, sound etc. and overall be more complicated than CHIP-8. Try it out if you either feel a bit more adventurous or have implemented CHIP-8. [0](https://sr.ht/~gotlou/chip8-emulator https://sr.ht/~gotlou/chip8-emulator) [1](https://gotlou.srht.site/chip8-emulator.html https://gotlou.srht.site/chip8-emulator.html)
- kjeetgill 4y agoThe cache hierarchy and speculative execution are completely hidden at the level of assembly too, so I'm not sure what you're getting at.
- packetlost 4y agoYou're much more likely to get bitten by those 2 things at the ASM level... I guess.
- kjeetgill 4y agoSo I don't work at that level, I'd love to hear more. What situations do they leak through in?
- packetlost 4y agoyou'll mostly notice performance problems if you're not aware of cache lines when writing concurrent software, though it's relevant whenever you read from main memory. As for speculative execution, you probably won't really encounter issues related to that unless you go out of your way to. I don't believe it can actually cause problems in programs (though it is helpful for exfiltrating otherwise secret data).
- cbm-vic-20 4y agoThis is true even on later PDP-11 models with memory caches.
- Twisol 4y ago> The cache hierarchy [...] are completely hidden at the level of assembly too A quick glance at Intel's Software Developer's Manuals [0] falsifies this: >> TLB and Cacheability control: CLFLUSH, CLFLUSHOPT, CLWB, INVD, WBINVD, INVLPG, INVPCID, and memory instructions with a non-temporal hint (V/MOVNTDQA, V/MOVNTDQ, V/MOVNTI, V/MOVNTPD, V/MOVNTPS, V/MOVNTQ, V/MASKMOVQ, and V/MASKMOVDQU). > [..] speculative execution are completely hidden at the level of assembly too Section 18.1.13 specifically mentions side-channels for speculative execution, and there are more than 100 other matches for "speculative" across the document (some of which also refer to load barriers). So no, these things are not completely hidden at the assembly level, and at least in the case of the (or one of the?) most popular consumer CPU architecture in the world, they are actively documented in the primary reference for an assembly programmer. [0] https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html https://www.intel.com/content/www/us/en/developer/articles/t...
- rob74 4y agoCache hierarchy, branch prediction, speculative execution and all of the other performance enhancements of modern CPUs are hidden from assembly too. If you are a real whiz, you may be able to hand-tune your assembly code so that it takes better advantage of one of these features and runs 0.1% faster, but otherwise these features are transparent even to assembly programmers.
- Twisol 4y agoJust to mention it here, too (I wrote more in a cousin comment), Intel's own Software Development Manuals [0] explicitly talks about all three of these things. I don't consider these features hidden when the primary reference for programming this platform clearly documents and provides advice on them. [0] https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html https://www.intel.com/content/www/us/en/developer/articles/t...
- nextaccountic 4y ago> 0.1% faster, The performance gains of fine-tuned code is typically two orders of magnitude higher
- marcosdumay 4y ago> It will teach you how a PDP-11 thinks, at best. The cache hierarchy and speculative execution are completely hidden at the level of C, to start with. And error recovery (that is fucking crazy on x86), and wide instructions, and I/O, and stack management, and... I am not sure C is even a good approximation for the PDP-11.
- dboreham 4y agoAll computers are pdp-11s.