Live data from Hacker News

Learning to Read X86 Assembly Language

patshaughnessy.net

131–140 of 238 posts

Re: Learning to Read X86 Assembly Language

#131

Earlier quoted context omitted.

I haven't. It's probably not fun.

It wasn't easy. Very asymmetric, not many registers, and tiny stack. The only things that were written directly in it were the operating system, and the virtual machines for higher level languages such as COBOL and MPL, because it was too hard to compile to. I worked on the virtual machines. After programming in it, I can assure you that programming in other assembly languages (including x86) is a breeze. I should pu…

Isn't the high level Burroughs assembly a compertly insane almost high level language? I looked into implementing it into my assembler and just ran in the other direction when I saw how much unnecessary co plexity there was in the language.

Re: Learning to Read X86 Assembly Language

#132
post #49

To understand assembly it really helps to know at least something about how computers work on a low level. When I first tried learning it (long time ago, in a high school) I had no idea how computers really work on such a low level, how CPU's addressing registers and that kind of stuff, and while I managed to learn the syntax, even write some asm code, it was all really confusing to me. And only few years later on Un…

It's helpful to realize x86 assembly is not what's executed by the machine; machine code is. One assembly instruction, e.g. ADDL, is translated to several different machine code instructions depending on the destination, source, and addressing mode.

There would be much less confusion about this in the descendant posts if this said "One assembly mnemonic is translated to ..."

Re: Learning to Read X86 Assembly Language

#133

Earlier quoted context omitted.

>It also didn't have memory segmentation The Z80 only has a 16-bit address space. My favorite CISC architecture is the 68000 series.

Yes. But you could install an MMU. The 68k (and it's 8-bit semi-cousin, the 6809) were very nice. However, unlike the Z80, the 6502, and x86, they're no longer being made, and are increasingly rare.

68k Macs are easy enough to find on eBay. Grab one of the old Powerbook 1xx series laptops and you have a self-contained development station that's less expensive than many modern microcontroller dev kits.

Re: Learning to Read X86 Assembly Language

#134

Earlier quoted context omitted.

Unfortunately not, but I'd love to hear from those who do.

I wouldn't be surprised if the reason was that people at Bell labs were mimicking some older syntax.

Yeah, I suspect this too. They did something similar with Golang (and Rob Pike still defends it, sadly).

Re: Learning to Read X86 Assembly Language

#135

Earlier quoted context omitted.

Unfortunately not, but I'd love to hear from those who do.

I wouldn't be surprised if the reason was that people at Bell labs were mimicking some older syntax.

I remember reading a long time ago about the syntaxes and the author said that it is because AT&T assembled faster. Makes sense considering that the intel syntax requires some backtracking (or more of temporary data).

(please don't upvote if you agree, i'm at 69 points :)

Re: Learning to Read X86 Assembly Language

#136

Earlier quoted context omitted.

They should all have same binary encoding, which means they can all be decoded to any human readable format regardless...

Assembler directives absolutely break this.

Doesn't it only appear in assembly? If you disassemble, are they still present?

Re: Learning to Read X86 Assembly Language

#137

What a train wreck! It’s hard to imagine a more confusing state of affairs. I'd say that's more attributed to someone many many years ago deciding they would not follow the official Intel syntax (for what reason I do not know), and somehow convincing the rest of the community to follow them. That's actually one of the things that could make for a very interesting article: how one processor family got two different an…

And Golang uses a separate syntax from Intel syntax and AT&T syntax, so now there are three incompatible syntaxes in common use. What a mess. :( In Go's case it's because they wanted to have the syntax reflect the MachineInstr-like abstraction they have in place. I wouldn't be surprised if something similar was responsible for the AT&T syntax as well. (In case it isn't clear, my preference is to do what LLVM does and…

For extra points the Go syntax has /no/ spec.

To quote "The details vary with architecture, and we apologize for the imprecision; the situation is not well-defined." [0]

[0] https://golang.org/doc/asm

Re: Learning to Read X86 Assembly Language

#138

Also Matt Godbolt's gcc explorer is the the bee's knees for understanding assembly https://godbolt.org/ I think that playing around with it for 2 hours will teach you more than most classes on the topic. It really drives home why interactivity is such a bit deal in education. You should also try writing a script for counting instructions in binaries. It's pretty illuminating. Here are some sample statistics https://w…

One great example to try: add -O3 to the compiler options, then write a function returning its argument multiplied by 2, 3, 4, ... You'll see the various ways the compiler avoids emitting an actual multiplication instruction. The smallest multiplier I found that actually produced an imul: 46.

Interesting example, I came up with clang 3.9 producing an imul with 11 though.

Re: Learning to Read X86 Assembly Language

#139

Earlier quoted context omitted.

Suppose you're right and the registers are arbitrary. Then how would foreign function calls work? If you're compiling Rust code that calls into a C library, how does it know what registers to use? So the choice of registers cannot be arbitrary, unless the compiler knows the function is only used within an object file. The registers are predetermined by a convention unless you use the 'static' keyword to signal that t…

Then how would foreign function calls work? If you're compiling Rust code that calls into a C library, how does it know what registers to use? By using information kept with the function, or perhaps even encoded into the function name itself (as already happens when distinguishing between different calling conventions, or in the case of C++ name mangling)? Coming from an Asm background, where there basically is no on…

[deleted]

Re: Learning to Read X86 Assembly Language

#140

Earlier quoted context omitted.

One great example to try: add -O3 to the compiler options, then write a function returning its argument multiplied by 2, 3, 4, ... You'll see the various ways the compiler avoids emitting an actual multiplication instruction. The smallest multiplier I found that actually produced an imul: 46.

Interesting example, I came up with clang 3.9 producing an imul with 11 though.

With optimization turned on?

GCC produces an lea that multiplies by 5 into %rax for the return value, then another lea that multiplies that by 2 and adds the original.

Post reply on HN