
Programming from the Ground Up [pdf] - luu
http://download-mirror.savannah.gnu.org/releases/pgubook/ProgrammingGroundUp-1-0-booksize.pdf
======
wyldfire
I think many of us learned the other way 'round.

(1) Start off by making changes to a program that someone/some book gave us as
a basis and blindly stumble through some changes and
compiler/interpreter/runtime errors.

(2) Take a step back, absorb what we've learned from the errors.

(3) Read more about the principles of the programming
language/OS/API/operating environment.

(4) Internalize concepts behind the language/OS/API/operating environment.

(5) Goto (1).

It's only after many iterations through this process that I can now see
similarities among different processors (CPU/DSP/GPU/etc), operating systems,
APIs, programming languages. So many classes of problems can be solved
effectively without ever understanding these details, so it makes sense for
those new programmers not to learn the details at first. IMO, this is _at
least_ an intermediate-level text.

------
koloron
Hah, just today I started to read "Haskell programming from first
principles"[1] which also targets non-programmers but builds on lambda
calculus instead of assembly.

Would anyone actually recommend to a beginner to start learn assembly first?

[1][http://haskellbook.com/](http://haskellbook.com/)

~~~
ktRolster
>Would anyone actually recommend to a beginner to start learn assembly first?

Yes, if you can find a good book about it. Assembler isn't particularly
difficult, but the information teaching it is rather hard.

Right now, the lowest-level language I know of with a really good beginner
book is C, and it's this book: [http://smile.amazon.com/Absolute-Beginners-
Guide-C-2nd/dp/06...](http://smile.amazon.com/Absolute-Beginners-
Guide-C-2nd/dp/0672305100/ref=sr_1_2?s=books&ie=UTF8&qid=1463344131&sr=1-2&keywords=absolute+beginners+guide+to+c)

~~~
e12e
Out of curiosity, have you looked at the 3rd edition?

[http://www.amazon.com/Programming-Absolute-Beginners-
Guide-3...](http://www.amazon.com/Programming-Absolute-Beginners-
Guide-3rd/dp/0789751984/ref=sr_1_1?s=books&ie=UTF8&qid=1463368165&sr=1-1)

~~~
_kst_
I just took a look at the "LOOK INSIDE!" sample available on amazon.com. A few
observations:

The front cover says it's been "Updated for C11", but all the sample programs
use "main()" rather than "int main(void)". The form without an explicit return
type has been invalid since C99.

Page 11:

"In 1983, ANSI created the X3J11 committee to set a standard version of C.
This became known as ANSI C. The most recent version of ANSI C, C11, was
formally adopted in 2011."

That's _loosely_ correct, but in fact the 1990, 1999, and 2011 editions of the
C standard were published by ISO, not by ANSI (and later adopted by ANSI).
Furthermore, it ignores the fact that the phrase "ANSI C" is commonly but
incorrectly used to refer to the 1989/1990 version of the language (see gcc's
"-ansi" option, for example).

Page 16:

"These are functions:

main() calcIt() printf() strlen()

and these are commands:

return while int if float"

No, those aren't "commands", they're keywords. I can't think of any reasonable
meaning of the word "command" that would include "int".

Page 26:

The sample program listing is not properly indented.

Page 36:

"\b moves the cursor back a line".

No, it moves the cursor back a _column_.

A book for beginning C programmers should not have these kinds of errors after
three editions.

------
rashkov
I've read a few chapters of this and have found it be well written and a great
introduction to assembly programming. It was written for 32-bit but so far
everything works just fine on my 64 bit linux system. Also it was interesting
to learn alongside C. It helped to see the workings of a machine from those
two vantage points.

Also of note is the author's story of writing the book and giving it away as a
labor of love. Very nice

------
TheAceOfHearts
Learning assembly was probably the biggest thing that made computers click in
my head. Since then, I've always thought that learning assembly as your first
programming language would be a great place to start. Of course, I'm sure this
doesn't apply to everyone.

In CS you're usually started off with something like C, Java, or Python. But
those languages are so HUGE (in comparison) that it can be really
overwhelming. Meanwhile, with assembly, you have far fewer items in your
toolbox and you have no abstractions between what you write and what's being
executed.

After googling, I found emu8086 [0], which I think is what I used to debug the
tiny apps I was writing. It was great! You could step back and forward in
time, and you could inspect every detail.

[0] [http://www.emu8086.com/](http://www.emu8086.com/)

~~~
sanderjd
I think this is tricky. I was exposed to 8086 assembly having only previously
seen a couple flavors of BASIC, and I have to say that it mostly went over my
head. It was hard for me to see the bigger picture, the useful functionality
that we were painstakingly working toward with our little instructions moving
bytes around and taking different paths based on flags. I remember system
calls (which are covered early on in the OP) seeming _especially_ confusing
and magical. On the other hand, when I dove deeper into (m68k) assembly a few
years later, after getting some C and C++ under my belt, it was an amazing
eureka moment that made both the earlier assembly exposure and what I had
learned of higher level languages click into place. So I do think learning
assembly early on is great, but I'm not sure it's such a panacea to learn it
_first_.

~~~
spc476
Assembly was my second language (BASIC being my first), but it was _not_ the
x86 line I learned first (it was my second assembly language). I can name half
a dozen architectures that are probably better for learning than the x86, some
of them relevant today.

Probably in order: 6502---not my favorite, but _tons_ of material and
emulators exist. The most popular 8 bit CPU and one of the most simple ones.

6809---my favorite 8-bit and it lends itself fairly well towards higher level
languages. A nice register set (2 8bit general purpose registers, four 16bit
index registers) and a regular instruction set makes it easy to program.

8080 (or Z80)---if you are going to start down the dark side of x86 line, it's
probably best to start at the beginning. A mess of registers, most of which
are somewhat general purpose but each has a specific use.

68000---a very nice 32-bit architecture with enough regularity to make it easy
to write compilers for, with enough instructions to make it fun to write
assembly code. 8 32bit data registers, 8 32bit index registers.

VAX---another nice 32-bit architecture with a very regular instruction set. 16
32bit general purpose registers.

MIPS---one of the original RISC architectures that's still in use. Perhaps a
bit too spare on instructions. 32 32bit registers.

ARM---Kind of reminds me of a RISCish 68000 with unique features that make it,
again, fun to program at the assembly level.

The x86 line is ... baroque due to its history (you can think of it as an
overglorified 8080 that gained power over time, much like the MCP in TRON if
you think about it) of ossified layers. It's hard to learn because it's almost
all exceptions to a non-regular instruction format.

~~~
clishem
I've been looking to buy "Introduction to 64 Bit Assembly Programming for
Linux and OS X: Third Edition - for Linux and OS X". It's an introduction to
x84-64 assembly, which I thought makes sense for me to learn, because it is
the architecture all my computers use.

You say x86 is not a good choice to learn, but this book purports to make
assembly for this architecture accessible. If you stand by your opinion, are
there even CPUs readily available that support the alternative architectures
you mention?

Also, can anyone recommend this or any other book or learning resource?

~~~
spc476
As a first language, or even as a first assembly language. Once can certainly
learn it, and it may even come across as half decent if you skip some of the
less used instructions (like LOOP, REP, LODS, STOS, AAD, AAS---basically, the
really archaic instructions that aren't really used or optimized). But with
nearly 40 years of backwards compatibility, it's a monster of an architecture.

------
aap_
This is another nice book about x86 assembly:
[http://www.drpaulcarter.com/pcasm/](http://www.drpaulcarter.com/pcasm/)

~~~
yyin
One of his two nameservers, ns2.missoulaweb.com (66.235.178.171), is non-
responsive. The other one works but it's listed second. No round-robin. That
can slow down the DNS lookup, as the first listed nameserver will likely be
tried first, adding to the "slowness" of a website.

Dead nameservers are relatively rare among sites that get posted to HN, since
many are high traffic and use CDNs (that rely on DNS kludges). But it is still
a regular occurrence. No one ever talks about it. But it's one of the DNS
kludges that's continually slowing things down behind the scenes.

There is that term "link rot" for URL's that do not work anymore. And "bit
rot" for source code. I propose a new one: "NS rot".

------
_nedR
Yet another free book on assembly and computers is _The art of assembly
language_ : [http://www.plantation-
productions.com/Webster/www.artofasm.c...](http://www.plantation-
productions.com/Webster/www.artofasm.com/index.html)

This one is quite expansive in coverage of topics.

------
chubot
Does it make sense to learn x86 assembly now, or is x64 assembly simpler? All
the machines I use are x64 and the binaries I generate are 64-bit. (I realize
it's a superset, but I suppose I want to learn the smallest useful subset,
since it's a big topic...)

~~~
MichaelBurge
Use x64 - the calling convention is simpler and you get more registers. Avoid
the exotic instructions.

~~~
chubot
Can anyone recommend the best resource for learning x64 then? I did computer
architecture and assembly language 15+ years ago in school but haven't really
needed to touch assembly language as a professional programmer.

So I know the basic idea of registers and addressing modes and pipelines and
stuff, but nothing specific to any architecture. My goal is basically to be
able to write faster C and C++ programs and analyze constructs like the cost
of things like smart pointers, virtual dispatch, templates, etc.

~~~
lorenzhs
I'd be very interested in such a resource as well. At the moment I'm just
staring at the output of 'objdump -S', trying to make sense of things and find
what's different between two versions. For smaller things, Matt Godbolt's
compiler explorer is very helpful as well. But I'm still having trouble
figuring out what exactly is happening and why some things are required, etc.

------
MIKarlsen
Terrible, terrible information architecture. Love the idea, but it's sooo hard
to find your way around that site.

~~~
gwu78
Blogger.com blogs such as this one ("programminggroundup") can be obtained in
a single file containing all posts. Text or minimal HTML file. No gratuitous
Javascript and no comment spam.

See
[http://news.ycombinator.com/item?id=6845367](http://news.ycombinator.com/item?id=6845367)

Simple, portable shell script. Not perfect, but it still works. ^M means
Ctrl-V,Ctrl-M in ed/ex/vi

    
    
       #!/bin/sh
    
       # requirements:
       # netcat
       # openssl 
       # sed
       # optional: strings
       # optional: addcr
    
       type strings 2>&1 >/dev/null ||
       strings(){ sed ;}
       type addcr 2>&1 >/dev/null ||
       addcr(){ sed ;}
    
       [ $# -gt 0 ]||exec echo usage: $0 nameofblog
    
       {
       printf "GET / HTTP/1.0\r\n"; 
       printf "Host: $1.blogspot.com\r\n";
       printf "Connection: Close\r\n";
       printf "\r\n";
       } \
       |exec nc -vv www.blogger.com 80 \
       |exec sed '
       s/\\046/\&/g;
       s/\\46/\&/g;
       s/\\075/=/g;
       s/\\75/=/g;
       /targetBlogID/!d;
       s/.*targetBlogID=//;
       s/&.*//;
       ' |exec sed 1q \
       |while read a
       do
       {
       printf "%b" "GET /feeds/$a/posts/default HTTP/1.1\r\n"; 
       printf "Host: www.blogger.com\r\n";
       printf "Connection: Close\r\n";
       printf "\r\n";
       } 
       done \
       |openssl s_client -ign_eof -connect \
       www.blogger.com:443 -verify 9 \
       |exec addcr  \
       |{
       echo
       sed '
       s/&lt;/</g;
       s/&gt;/>/g;
       s/&amp;/\&/g;
       s/&quot;/\"/g;
       1i\
       <br><br>
    
       s/<name>/<br><br>name &/g;
       s/<uri>/<br>uri &/g;
       s/<generator>/<br>generator &/g;
       s/Blogger//;
       s/<id>/<br>id &/g;
       s/<published>/<br>published &/g;
       s/<email>/<br>email &/g;
       s/<title type=.text.>/<br><br>&/g;
       s/<openSearch:totalResults>/<br>total results &/g;
       s/<openSearch:startIndex>/<br>start index &/g;
       s/<openSearch:itemsPerPage>/<br>items per page &/g;
       s/<updated>/<br>updated &/g;
       s/<thr:total>/<br>thr:total &/g;
       s/<\/feed>/&<br><br><br>/;
    
       s/^M*/<br>/;
       '  \
       |strings
       }

------
amelius
Shouldn't this start by explaining the binary number system? (Now they explain
it somewhere near page 180).

------
wskinner
Top of HN with 4 upvotes and no comments?

~~~
sbierwagen
Books generally collect lots of upvotes, but few comments, since you generally
have to read the book first before commenting.

Controversial news articles, whose entire content can be summed up in the
headline, collect both upvotes and comments. The ranking algorithm punishes
submissions with many comments, to push those submissions off the front page.

~~~
xiaoma
Is 4 lots?

------
FlorianMettetal
Working Link: [http://download-
mirror.savannah.gnu.org/releases/pgubook/Pro...](http://download-
mirror.savannah.gnu.org/releases/pgubook/ProgrammingGroundUp-1-0-booksize.pdf)

~~~
dang
OK, we changed to that from
[http://savannah.nongnu.org/projects/pgubook/](http://savannah.nongnu.org/projects/pgubook/).

