3 ms·
Sounds to me like if I want to know "how computers think" I should learn assembly.
by TrickardRixx 4y ago
Sounds to me like if I want to know "how computers think" I should learn assembly.
- dijit 4y agoI know you're trying to be a smart-arse; but by virtue of using C you will learn Assembly. The issue with Assembly directly is that it's absurdly non-portable, too low level and too unstructured to do anything reasonable with it. There's a reason that Linux is written in C and not ASM Directly.
- UncleMeat 4y ago> by virtue of using C you will learn Assembly. I don't believe this at all. You won't learn how to deal with limited numbers of registers. You won't learn about method prologues and epilogues. You won't learn about oodles of stuff.
- Jensson 4y ago> You won't learn how to deal with limited numbers of registers. You won't learn about method prologues and epilogues. Those things takes like an hour to learn, translating C to assembly is trivial, it takes time and will be verbose but it isn't hard at all. So even though you don't learn all the details you still learn all the higher level stuff related to assembly programming when you program in C. This isn't true for other languages, translating arbitrary C++ or Java or Javascript to assembly is really hard, so they don't teach you to think like an assembly programmer.
- dijit 4y ago> deal with limited numbers of registers I mean; you will likely end up stepping through debuggers where you will see registers being used. At least if you learned C like I learned C. Similarly for Prologue and Epilogue. "why does a function call have a cost" is a common question and it's solved forever after an hour googling.
- jcranmer 4y ago> by virtue of using C you will learn Assembly. Even interpreting this as charitably as possible--that you don't mean literally learning assembly but rather learning everything besides specific assembly syntax that you would have picked up from learning assembly--this claim doesn't hold water. For starters, C isn't that much closer to hardware than, say, Java. The main differences you have with C are that a) C has a pointers-are-almost-integers model [1] and b) C has a more limited runtime than other languages. C is still a fundamentally based on an abstract machine semantics model, and that abstract machine doesn't have a close bearing on modern hardware. In particular, C does not distinguish between registers and memory, and if I had to pick the single most salient feature of modern hardware you need to understand well to be able to say you understand how computers work, it's the register/memory distinction. If you think processors are mostly like they were in the 1970s--when you could say "add 1 to this memory location"--then C's shrugging off the register/memory distinction makes sense, but this is a situation that hasn't been true for several decades. Another failure of C is that it's far less expressive than assembly. There are features in other languages that are impossible to express in C. How do you write a function with multiple entry points, as you can in Fortran? Or a coroutine, as you can in Algol? Or nested functions, as in Pascal? Or try-catch, as in C++? Or functions with multiple return values, as in Matlab? Indeed, how do you write something like JMP *reg in C, a useful primitive for state machines? No, C does not come close to being a good description of modern processors, where "modern" means "anything that came out since I was born." [1] Not going to open up the can of worms that is pointer provenance.
- cesarb 4y ago> C does not distinguish between registers and memory Just nitpicking, but doesn't C have the register keyword? (I know it does nothing at all nowadays, but AFAIK it did make a slight difference back in the dark ages.)
- jcranmer 4y agoConsidering that `volatile register _Atomic int x;` is a totally legal statement, and two [1] of those keywords have semantics that are only relevant for memory operations, I'd say that the "register" keyword isn't sufficient to distinguish register from memory. [1] Okay, the official semantics of "volatile" strictly speaking are completely orthogonal to memory, but the practical effect that everyone agrees on (don't optimize this memory access) is inherently oriented towards memory, and the fact that the semantics are so vague about what it actually does is partially a reflection of the fact the semantics themselves don't distinguish between register and memory.