

A quick introduction to x86 assembly for everyone - dhaivatpandya
http://poincare101.herokuapp.com/post/26

======
ctdonath
A quick introduction to C++ for everyone

In a text editor, create a file called foo.cpp with the contents

void main(){int x,y=4;x=y;}

At a unix command prompt type

gcc foo.cpp

./a.out

That creates sort of a couple post it notes labeled x and y, with the number 4
on the y paper. Then it uses the equals sign (which is stupid because it
doesn't compare anything, it copies numbers) to put what's on y onto the x
paper.

Cool eh? Go Google "c++ keywords" for more you can do.

</sarc>

------
DHowett
This article looks like a really high-level approach to assembly based on a
few incorrect premises.

Many of the sentences here seem to contain incorrect original research or
oversimplifications of the concepts required to understand assembly.

For example, "So, processors run something call opcode, which basically means
binary. Of course, not all processors are the same, but, to preserve some
measure of sanity, there's something called x86 which is a specification which
gives some guidelines about opcode."

Additionally, Jumping to _start really isn't recursion in the sense of
"calling a function from within itself," it's a jump to a named location in
code- by the definition laid out in the article, loops are a form of
recursion.

It's also a bit disingenuous to say that GAS (or AT&T syntax) is not meant to
be written by developers, and that it was developed as a backend to GCC. While
the latter may be true it does not necessarily reflect on the usability or
accessibility of the language or the dialect.

------
Figs
This is not really a very useful introduction since it doesn't go deep enough
for someone to continue learning on their own. As soon as you start looking
for more details about x86, you'll run into a lot of confusing information
(and probably get stuck).

x86 is a ridiculously complicated architecture with over 30 years of
historical baggage -- it's very difficult for a beginner to tell what is
relevant to modern x86 computers vs what was only relevant to x86 computers
circa 1978. I'm talking about things like segmentation, real mode vs protected
mode vs ..., the fact that there are multiple FPUs with different instruction
sets (x87, SSE, etc.) and other instructions that reuse the registers
(MMX)..., and let's not forget the 64-bit extensions either...

If someone would go and explain the history and design decisions of the x86
and summarize what's still relevant for e.g. user mode programming under
Windows and Linux on computers released in the last 5 years, that would be
_really_ helpful to a lot of people trying to learn x86 assembly.

------
ComputerGuru
@dhaivatpandya: "We use the _resistors_ EAX and EBX."

I'm sorry, but this is a terrible introduction to assembly. It incorrectly and
inadequately explains what registers are, does not explain what's being done,
and is 2 paragraphs long.

~~~
duskwuff
And, perhaps worst, it doesn't actually give any demonstrably working
examples. (One of the two example programs hangs by design; the other one will
probably crash by falling off the end.)

~~~
TazeTSchnitzel
Yup, second gets me a segfault.

------
TazeTSchnitzel
If you are on x64 Linux and get this:

    
    
        ld: i386 architecture of input file `first.o' is incompatible with i386:x86-64 output
    

What you want to do is type this instead:

    
    
        nasm -f elf64 first.s
    

On another note, the link to intel's "command listing" has horrible CSS. If
you hover over it, it takes up more space, which moved it to the next line
with my browser width, making it impossible to click.

~~~
dhaivatpandya
Fixed the CSS.

~~~
TazeTSchnitzel
Thanks!

------
hannibalhorn
Honestly, the best way to get started with assembly is to start with another
architecture than x86. My course in university was on 68k, and I thought it
was much cleaner. These days, I'd probably suggest ARM - it's both relevant to
the modern world and not quite as hindered with legacy concepts.

------
ah-
I like how it's really straightforward but have some objections regarding the
terminology.

I wouldn't call "the thing processors run" opcode but machine code or
something like that. Also, the usage of "procedure" in the context of assembly
is a bit unusual.

~~~
duskwuff
Yeah, an opcode is something totally different -- it's a name for a type of
instruction (e.g, "mov" or "ret").

------
dlsym
So the next logical step would be the introduction of conditional jumps,
tests, flags...

It is a bit disappointing that the whole article is gathering some velocity,
when the author hits the break for a full stop.

------
reginaldo
One of the best introductions to x86 assembly I know about is
<http://www.drpaulcarter.com/pcasm/>.

It's succinct at "only" 195 pages. People who are interested can use this to
start and then read the Intel manuals when they need something that is not
covered by the tutorial.

------
X-Istence
Back in uni I took a class on Intel x86 assembly, and I ended up writing a
small program that would take two numbers as arguments to the program and add
them and then spit out the result.

It would convert from c-style strings to actual numbers, do 32 bit addition on
them, and then convert the number back to a c-style string before printing it
to the screen.

For anyone getting started this may be worth a look, as I commented every
single last line:

[http://personal.x-istence.com/post/2008/02/03/addnumbersasm-...](http://personal.x-istence.com/post/2008/02/03/addnumbersasm-
updated)

(Do note, I also set up various stack frames, mainly so that I could do
debugging of my assembly code in gdb)

Edit: This will only compile and run on FreeBSD and or Mac OS X due to the use
of FreeBSD syscall numbers and calling convention by pushing parameters to the
stack unlike Linux which wants stuff in register (see
[http://www.freebsd.org/doc/en/books/developers-
handbook/x86-...](http://www.freebsd.org/doc/en/books/developers-
handbook/x86-system-calls.html))

------
rpsw
I found a good way to learn some basic assembly is to experiment with things
like buffer overflows and reverse engineering (preferably on the right side of
the law). There are plenty of websites out there that offer security
challenges where you can exercise those skills.

------
slig
See also
[http://web.archive.org/web/20071016092851/http://jojodi.com/...](http://web.archive.org/web/20071016092851/http://jojodi.com/?p=107)

Unfortunately the original domain seems to be offline for while.

