TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Understanding C by learning assembly

188 pointsby davidbalbertover 12 years ago

11 comments

nullcover 12 years ago
Mixed feelings here:<p>* Knowing what the machine is doing is useful and important, especially while debugging. I think every really good C coder I know has been comfortable with assembly at least on some platform.<p>But…<p>* C is not a fancy macro assembler. C's behavior drives an abstract machine, and any machine code that achieves the same output assuming that all the C behavior is defined is equally valid. The believe that compiler is just transliterating your code to ASM is responsible for many serious bugs. C Compilers haven't been like that for 20 years (or more). E.g. aliasing rule violations. The fact that it isn't is utterly essential for performance, especially as things like good SIMD use become more critical for performance.<p>Even when the compiler is mostly transliterating the expectations from the simplified mental machine model can be misleading, e.g. alignment requirements on load on some architectures.
dude_abidesover 12 years ago
<p><pre><code> $ CFLAGS="-g -O0" make simple cc -g -O0 simple.c -o simple $ </code></pre> This is so handy. I never knew that you could call make without writing a default Makefile. Thanks!
评论 #4514332 未加载
评论 #4513715 未加载
评论 #4513808 未加载
评论 #4513782 未加载
评论 #4514312 未加载
erichoceanover 12 years ago
A thousand times yes.<p>If you are going to use C, then at least know what it's doing!
评论 #4513798 未加载
nigglerover 12 years ago
You can run gcc with the -S flag, which will dump the assembler output (so you dont have to go through gdb)<p>You can also use `objdump` from binutils
评论 #4515039 未加载
ginkoover 12 years ago
I sometimes think that an ideal approach to learn programming might be to learn it on several abstraction levels at once to see how things interact.<p>One good combination would be Assembly + C + Python for instance. Assembly helps understanding C and C helps with understanding Python.
habosaover 12 years ago
I'm not sure how long this has been the case, but this is how C is taught at my school (Penn) and I'm sure many others.<p>In my CIS240 class (currently enrolled) we learn computers from the ground up and eventually learn C. First we do binary arithmetic by hand to get a feel for it, then we design basic circuits (and some complicated) that can perform the basic computer instructions (ADD. MULT, SHIFT, AND, XOR, etc.) then we keep building up off of these basics until we are finally writing C, at which point we will (hopefully) have a good grasp at what is going on and appreciate our programming language of choice a whole lot more.
b3b0pover 12 years ago
Assembly was always daunting to me. Then I took Computer Systems at the University. It ended up being seriously fun. The way it made me think and try to solve problems were engaging and different it seemed. It required a new way of thinking and made me think about things I never thought about. Although we only wrote smaller programs for the class, I found them fun and I still remember the class nearly 10 years later.<p>In regards to the original post, I'm not sure I would be putting C with assembly or learn one over or for the other. They both have their uses and reasons for knowing. Forcing yourself to learn one before the other does not seem like a logical way to go. I think it's best to start with what makes the most sense for your end goal and / or you are most interested and motivated to begin and get most deeply into.
pacman128over 12 years ago
I used to teach Assembly and I spend a lot of time talking about how it connected with C since assembly is almost always used in conjunction with C. I have a free text on the web that was used in the class. It only covers 32-bit x86 since that's all there was back then. <a href="http://www.drpaulcarter.com/pcasm" rel="nofollow">http://www.drpaulcarter.com/pcasm</a>
novalisover 12 years ago
Fascinating, reading it made me remember how fun it was to use Softice.
评论 #4514729 未加载
jstrayerover 12 years ago
It's been more than a decade since I've worked in C, but don't C compilers have an option to emit assembly directly?
naavinmover 12 years ago
Hmm, interesting..