
The Art of Assembly Language (1996) - cleong
http://web.archive.org/web/20010903173628/http://cs.smith.edu:80/~thiebaut/ArtOfAssembly/fwd/fwd.html
======
nybblesio
I love assembly language! I stream my programming sessions Monday-Saturday
5am-10am on Twitch
([https://twitch.tv/nybblesio](https://twitch.tv/nybblesio)).

All of my previous streams are archived here:
[https://www.youtube.com/channel/UCaV77OIv89qfsnncY5J2zvg](https://www.youtube.com/channel/UCaV77OIv89qfsnncY5J2zvg)

I have around 23 videos now on YouTube covering both ARM 64-bit and x86
assembly language.

I have two projects on the schedule that are 100% assembly language:

\- Let's Make an Arcade Game in MS-DOS: 100% x86 assembly language. I use
DOSBOX and period tools for this project.

\- Arcade Kernel Kit: 100% ARM AArch64 assembly language running on Raspberry
Pi 3.

All of the code for these is available on Github:
[https://github.com/nybblesio](https://github.com/nybblesio)

I'm also working on a game engine called Ryu: The Arcade Construction Kit
where I'm writing my own assembler for classic arcade CPUs.

I'll be working on the x86 project again starting 2 April through 7 April.

~~~
thijsvandien
Cool initiative, but please don't add music to the videos. It makes me nervous
and unable to focus on you talking. Such a waste of otherwise great content.

~~~
nybblesio
Thanks for the feedback. The videos I have on my YouTube channel to-date are
all from my Twitch streams. For or better or worse, these streams capture my
working habits: when the camera isn't running, I'm doing the exact same thing
-- even talking to myself. :) For some reason, suffering from ADHD, music
helps to focus my attention. I've never been able to explain why.

However, with all that said, I am producing non-stream content that will start
airing on my YouTube channel soon (within the next 30 days). This content will
be more structured and focus on a specific topics with a set lesson plans.
These videos won't feature any background music. I hope you'll be able to
enjoy these when they're available.

~~~
jaysonelliot
Thanks for making these videos. I'm watching the "x86 assembly language
programming on reference arcade game" video right now.

Knowing that the music is there for your focus actually makes it a lot easier
for me to focus as well, somehow. Glad to know that.

Your voice is very relaxing, I'm actually working while I watch! Great
explanations also.

------
emily-c
Assembly language is really fun to write! I think that it's really important
to know the basics of modern computer architecture and their ISAs. All
abstractions are leaky and I don't think that you can be a truly proficient
systems programmer if you don't know the basics of the hardware your code runs
on.

Lately I have been writing a lot of code in x64 asm for fun. I've found that
it's impressive how much functionality you can fit in such a small amount of
space. Randall Hyde's book got me started but I think that a much better
introduction would be Paul Carter's PC Assembly Language
[https://pacman128.github.io/pcasm/](https://pacman128.github.io/pcasm/)

~~~
_sdegutis
I still don’t understand how you can use basic data structure in assembly. I
know strings are just allocating a blob of bytes and usually reserving the
last for null terminator, but what about arrays? Is it just like in C where
you allocate a blob of bytes but now you manually calculate where the index is
based on item size? What about hash tables, that seems even more confusing...
are they just not needed due to the nature of assembly?

~~~
bomb199
Well, Hash tables are much more complicated. I think the closest analog is
going to be a jump table, just with fancy math.

I feel like the hardest part of Assembly is all of the hex math required...

~~~
vram22
Just use a programmer's calculator or a software calculator (e.g. bc on Unix,
RealCalc on Android) for the hex math (and for math in other number bases and
conversions between bases too). Or even write one of your own as an exercise
and then use it.

~~~
heavenlyblue
Do you even do any of the hex math when writing actual code in assembly?

I understand when you use something along the lines of a disassembler that
requires you to actually see the addresses of the values. But even these are
sophisticated enough to give you symbolic values instead.

~~~
khedoros1
A lot of my hobby programs are emulators or parsers for old file formats
(think DOS-era games). Bitfields become important, and they're more convenient
to express in hex than in decimal.

There are times where it feels convenient to express things in decimal and
times where it seems better to use hex.

------
TheAceOfHearts
I really enjoyed learning x86 assembly in college, and I'd highly recommend
others give it a try. If you focus on the core essentials (e.g. the reduced
instruction set from the 8086), it's a small and fun toolkit.

Learning assembly and creating my own simulated processor using multiple
layers of logic gates was one of the main cornerstones of my college
education. I remember when things finally "clicked" and I finally understood
how computers worked on a fundamental level, I was positively giddy for days.

Unfortunately, our technology has become increasingly complex. For a while I
tried my hand at learning more about modern processors, but found it far too
overwhelming. Maybe I just didn't know where to look for more approachable
resources. Just taking a look at the reference manuals provided by Intel is
enough to make anyone lose hope. I seriously doubt any single human is capable
of reading and understanding that in any reasonable amount of time.

If you wanna go down into the metal, consider picking up a microcontroller and
writing your own firmware. You can ditch the OS and start squeezing every
ounce of power from the hardware. It's pretty crazy how little power a well
configured microcontroller can get by with.

I'd also suggest learning WebAssembly! The text format is quite pleasant, and
it does away with many of the issues you'd have to deal with when using real
hardware. Even better, the spec [0] is actually quite readable for regular
developers. That might let people get their feet a bit wet without having
having to go into the deep end of the pool right away.

[0]
[https://webassembly.github.io/spec/core/index.html](https://webassembly.github.io/spec/core/index.html)

~~~
armitron
“From NAND to Tetris” is the classic starting point.

~~~
profosaur
The NAND to Tetris textbook is a masterpiece. (The book is called The Elements
of Computing Systems: Building a Modern Computer from First Principles. The
authors are Nisan and Schocken).

I worked through the entire textbook by myself, doing all the projects, and
having no previous knowledge of computer architecture or compilers. It was a
challenging but smooth process. The difficulty level was just right and I
didn't get frustrated.

The computer you build is designed brilliantly. It's as simple as it can be,
while still being a real computer can be that can play video games.

------
StashOfCode
MC68000 assembly language was so much fun on the great Commodore Amiga. It
gave you the opportunity not only to code quickly nice video effects, but also
to learn a lot about what is the architecture of a computer, how the CPU works
with other coprocesseors (there were many on the Amiga, among which the
Blitter to copy data blocks / draw lines / fill shapes, and the amazing Copper
to control the video).

I recently decided to code again some stuff because I wanted to write some
articles for the retro section of a magazine, and it was so pleasant that I
coded some more and documented it (here for those interested, in french at
this time, but there are pictures:
[http://www.stashofcode.fr/category/retrocoding/](http://www.stashofcode.fr/category/retrocoding/)).

I hope people still have the opportunity to have a look at assembly language
at school. The article is interesting. It reminds me also that I always heard
that coding in assembly language was hard. Well, I would not have say that
back in 1996. x86 was a pain in the ass because of the lack of registers and
the way memory was managed, but Mx68x00 was very simple indeed. IMO, what was
a bit difficult was that if you wanted to code assembly, you had to learn
about how what was around the CPU did work.

------
nategri
I can't remember which book I read on 6502 assembly (may have been Randall
Hyde's, actually), but learning it was one of the most satisfying programming
experiences I've ever had. Strongly recommended for coders of all types and
styles, even if it's a dialect that's pretty far removed from the CPU of your
standard environment. You'll never be confused by what is meant by a pointer
or reference ever again, that's for sure!

And anyway I have this cool Apple II video codec to show for my efforts :)

[https://hackaday.com/2013/07/22/animated-gifs-on-an-apple-
ii...](https://hackaday.com/2013/07/22/animated-gifs-on-an-apple-ii/)

~~~
shpx
There's a nice interactive 6502 tutorial at
[https://skilldrick.github.io/easy6502/](https://skilldrick.github.io/easy6502/)

------
drivers99
I didn't see a link to navigate to the rest of the book, so here's the Table
of Contents from the same date:

[http://web.archive.org/web/20010812234934/http://cs.smith.ed...](http://web.archive.org/web/20010812234934/http://cs.smith.edu:80/~thiebaut/ArtOfAssembly/ArtofAsm.html)

------
rcgorton
If, as a novice, you wish to write assembly code: \- compile your code with
"-O3 -S" and examine \- analyze it.

Assume that glibc for your architecture is going to be hand tuned (and
exceptionally highly optimized)

Read and try to understand the native mem _() and str_ () routines, as the
folk who write these routings DEEPLY understand the micro-architecture and
instruction set.

A counter example: all implementations of strlen() which evaluate a single
character at a time are completely inept if the architecture has vector
comparison capabilities.

~~~
slavik81
If you can cut things down to something reasonably self-contained,
[https://godbolt.org/](https://godbolt.org/) is incredibly useful. For
example, I was curious about the approximate inverse square root instruction,
so I wrote some code:
[https://godbolt.org/g/qdfSj4](https://godbolt.org/g/qdfSj4)

It's a lot easier to read that than the raw output from gcc. The highlighting
between matching segments is nice, and the right-click menu has all sorts of
goodies, like scrolling everything to the same place or showing the manual
entry for some instruction. Plus, it's super easy to see the effect of
switching flags or compilers.

Though to your point, apparently godbolt v0.0.1 was basically just:

    
    
        watch "g++ /tmp/test.cc -O2 -c -S -o - -masm=intel | c++filit | grep -vE '\s+\.'"

------
dver
Randy wrote the Lisa Assembler for the Apple II.

[https://archive.org/details/LISAAssemblerVersion2.5ManualPho...](https://archive.org/details/LISAAssemblerVersion2.5ManualPhotocopySource)

------
interfixus
Memories! Thank you for digging this up. 1996 sounds about rigtht - that's
when I actually read the thing, and that, alas, is around the last time I did
any serious assembly. Switching to Linux, and later on to 64bit, and all sorts
of complexities cropping up, nd portability becoming more of an issue, I sort
of lost touch, but it was wonderful while it lasted. Squeezed some screaming
speed and ridiculously microsized code out of 486's and early pentiums.

I stil squirm when I see anything javascripty labelled ' _asm_ '. Because, you
know, it's not.

------
ausjke
Recalling when I was at college I used machine code to pre-fetch data into
cache to improve an algorithm by 40x, even the professor did not believe that
and asked me to explain all the hacking code I did and later on gave me the
highest grade for that class. Yes ASM and machine-code are fantastic...

------
nthompson
I learned x86 floating point assembly from Ray Seyfarth's book:

[https://www.amazon.com/Introduction-Bit-Assembly-
Programming...](https://www.amazon.com/Introduction-Bit-Assembly-Programming-
Linux/dp/1484921909/)

I figured out how to write some basic stuff, then I learned to use perf to
performance tune. Being able to read a little assembly was a revolution for
me.

I also chuckled about how C is non-portable; omg C++ is so much worse. In some
sense, x86 asm is more portable than just about anything now, sure you can't
run it on ARM, but your C++ code won't compile on ARM either and you'll be in
#ifdef hell for two weeks to get it there, at which point you'll give up.

~~~
blt
Why is C++ less portable than C? In my experience, non-portable code happens
when the interaction with the OS is not well isolated. Since the major OS
interfaces are C header files, I don't see why C++ makes it any worse.

~~~
nthompson
I should've clarified: I meant portability of code so that is can be compiled
by multiple compilers, VS, clang, gcc. The feature set for C++ is so vast that
it's almost certain that you'll write code on for one compiler that doesn't
compile on another.

------
sp332
Available in print from No Starch Press, last updated in 2010
[https://nostarch.com/assembly2.htm](https://nostarch.com/assembly2.htm)

~~~
nerraga
The second edition introduces high-level assembly (HLA) though. I never found
HLA to be that appealing. I'd be curious to know if anyone who has read the
book found it to be useful in learning assembly. I used "Assembly Language for
x86 processors" by Kip Irvine, and I thought it was pretty good.

~~~
sureaboutthis
I've had many an argument with Randy over HLA and I agree. His point is that
it makes assembly and computer programming at a low level easier to understand
but I just don't see it.

------
phkahler
Writing assembly is tedious when the processor is smaller than the task at
hand. Doing more than 8-bit math on a 6502 was a pain because you had to
handle multi-byte addition yourself. Zero page - because no 16bit pointers.
But when the processor isn't too small and the instruction set is well written
with humans in mind (I look away from Intel here) it can be kind of nice. The
MC68000 was a dream compared to earlier processors I'd used before.

On a related note, I learned first on an 8080 but with a different naming and
syntax than the standard intel ASM. Maybe it's because that's what I learned
first, but it still seems better to this day.

------
joker3
Is anyone still programming in assembly in 2018? Maybe some embedded systems
people?

~~~
glangdale
Not really, but I'm writing C code and reading the asm with the expectation of
seeing exactly the asm I expect. About the only major thing I want from the
compiler is register allocation and scheduling, but it's way more maintainable
to let the compiler make these decisions based on its machine model than have
me do it.

Note that I'm a heavy user of intrinsics and SIMD, so I'm writing a lot of
code where I've pretty much already done instruction selection, often at
algorithm design time.

------
nemasu
I love assembly! I think if you know C/C++ it's not too difficult to learn.
One thing I noticed is, it can be a bit rough coming back to an old project, I
thought I had left enough comments on one of my projects
([https://github.com/nemasu/asmttpd](https://github.com/nemasu/asmttpd)), but
I was still scratching my head a bit in some places.

------
bordercases
Knuth's Art of Computer Programming is written in an Assembly variant, FWIW.
At least you get to see the memory as it's actually being written to.

------
peter303
Its a fair metric that the amount of maintenance in coding support is
proportional to the number of lines of code you write. Assembly code is an
order of magnitude lines longer than higher level languages.

Otherwise I dont think Assembly is that difficult to learn or code.

------
VectorLock
A shining example of the principal that sometimes restrictions precipitate the
most creativity.

------
zorkw4rg
I only got into assembly recently when programming the C64, its such a simple
instruction set and there is so much documentation that it seemed to me much
easier to get into. Also its fun to have to work around its limitations.

------
nootropicat
x86/amd64 assembly, along with common lisp, are two languages that I find
pleasurable in itself to write in. Probably because there no artificial
barriers to what is possible. There's nothing more infuriating than knowledge
that something is possible but artificially prevented/hidden.

------
calebm
Which assembler do people typically use these days? nasm?

~~~
nootropicat
I recommend fasm

------
chris_wot
I loved this, best book on assembly ever written.

