Live data from Hacker News

X86 assembly doesn’t have to be scary

blog.benjojo.co.uk

21–30 of 129 posts

Re: X86 assembly doesn’t have to be scary

#21
post #10

I think to many programmers assembly is the "GOTO" of programming languanges: From the day you start learning to program, you are told that all this fancy high-level-language stuff is there so you do not have to deal with assembly. So most people never go there. I did go there, briefly, about ten years ago. It was wicked fun. But all in all, I may have written maybe 20 or 30 instructions of assembly in total. I did t…

I always describe it as: Assembly is dead simple, it is only hard to write nontrivial programs in it. Manual register allocation, other micromanagement, and the necessary changes when you change the logic, that is hell.

Re: X86 assembly doesn’t have to be scary

#22
post #11

I wonder if the history of x86 is holding us back in a big way. It started out being close to the metal but now it's an abstraction that can mislead you if you think processors are literally working the way x86 assembly describes. And surely the whole spectre issue could be lessened if we could be less reliant on CPUs having to guess what to keep in cache, which code paths are most likely, etc?

These days there are an absurd number of abstraction layers in any computing stack.

Fire up anything electron based, and you are looking at scripts being JITed inside a "VM", sitting on top of an OS that abstract away the hardware, sitting on top of hardware that is pretending to be something from the 80s/90s.

Re: X86 assembly doesn’t have to be scary

#23
post #19
post #6

Loved the article. Then one can follow up with some MS-DOS classics. https://www.amazon.com/Peter-Nortons-Assembly-Language-Book/... https://www.amazon.com/Advanced-S-DOS-Programming-Microsoft-... https://www.amazon.com/Peter-Norton-Programmers-Bible-progra... https://www.amazon.de/PC-Intern-Programming-Encyclopedia-Dev...

I see your Norton and raise you an Abrash: https://www.amazon.com/Zen-Assembly-Language-Knowledge-Progr... https://www.amazon.com/Zen-Graphics-Programming-2nd-Applicat... https://www.amazon.com/Zen-Code-Optimization-Ultimate-Softwa... Zen of Asm is also online, I think a few of the other works, too. http://www.jagregory.com/abrash-zen-of-asm/

That is unfair. :)

Re: X86 assembly doesn’t have to be scary

#24
post #20

When I was about 14 I was enthralled with programming my new Commodore 64, first in BASIC, then 6510 assembly. I had the opportunity to accompany my mother to a one-day class on programming. Being just an intro on the subject, I was well ahead of what they would be discussing, but thought it would interesting to talk to some adults that were also into programming. I was talking to a couple of guys about what I had be…

>"How can you possibly write anything with only three registers?!"

AFAIK you can even go down to 1 register, which is how stack machines work. You might even say it’s 0 registers because it’s not something you can directly access.

Re: X86 assembly doesn’t have to be scary

#25

Earlier quoted context omitted.

Why not? If they're determined enough, they'll get it. I learned a lot back in the day by spending many hours with the book PC Intern and some other book on x86 Assembler. Granted, I had a little experience with assembler on a C=64, but, I learned _that_ in a similar way.

> If they're determined enough, they'll get it. That's the exact opposite mindset of someone trying to "not scare newbies away."

I think the determination of newbies is being underestimated. A lot of us "old timers" didn't have the internet. Just a few books and a whole lot of "Imma figure this crap out!".

Re: X86 assembly doesn’t have to be scary

#26
post #11

I wonder if the history of x86 is holding us back in a big way. It started out being close to the metal but now it's an abstraction that can mislead you if you think processors are literally working the way x86 assembly describes. And surely the whole spectre issue could be lessened if we could be less reliant on CPUs having to guess what to keep in cache, which code paths are most likely, etc?

As someone who hasn’t written assembly in 20+ yrs (some 68k back then, and bits of z80), I’m curious about some examples of how the assembly abstraction diverges from the underlying processor.

Re: X86 assembly doesn’t have to be scary

#27
post #3

If your intention is to avoid scaring newbies off, I'm not sure if 16bit real mode, PC boot process, BIOS services and all that arcana that follows is the best place to begin.

I agree with you to an extent: The IBM PC was not a very elegant design, and other computers certainly had less complexity to them. But there is a point I want to make which defends this choice somewhat:

Newbies like me are more frustrated by thinking there's no path from introductory material to something useful or realistic. Something that's more immediately friendly would be a simplified virtual machine with no or trivial peripheral hardware, like Redcode in Core War:

http://vyznev.net/corewar/guide.html

The death of education is "So What?": "OK, I've learned to play Core War and I know enough to write a warrior that can occasionally beat other warriors written by beginners. So far, so good... so what? I want to program computers in assembly, not play games using assembly programs, so where's the path from where I am now to where I want to be?"

In this case, the pathway from VM opcodes to native opcodes is hardware interface and, while the IBM PC has some funky hardware, it's heartening to know that your code could, in principle and barring emulation errors, run unmodified on real hardware and do something. Not something useful, but you can get to useful. You can ramp up to it, now that you have the pathway in front of you. It might be a long pathway, but it's there.

Re: X86 assembly doesn’t have to be scary

#28
post #11

I wonder if the history of x86 is holding us back in a big way. It started out being close to the metal but now it's an abstraction that can mislead you if you think processors are literally working the way x86 assembly describes. And surely the whole spectre issue could be lessened if we could be less reliant on CPUs having to guess what to keep in cache, which code paths are most likely, etc?

As someone who hasn’t written assembly in 20+ yrs (some 68k back then, and bits of z80), I’m curious about some examples of how the assembly abstraction diverges from the underlying processor.

https://news.ycombinator.com/item?id=9264195

Re: X86 assembly doesn’t have to be scary

#29
post #19
post #6

Loved the article. Then one can follow up with some MS-DOS classics. https://www.amazon.com/Peter-Nortons-Assembly-Language-Book/... https://www.amazon.com/Advanced-S-DOS-Programming-Microsoft-... https://www.amazon.com/Peter-Norton-Programmers-Bible-progra... https://www.amazon.de/PC-Intern-Programming-Encyclopedia-Dev...

I see your Norton and raise you an Abrash: https://www.amazon.com/Zen-Assembly-Language-Knowledge-Progr... https://www.amazon.com/Zen-Graphics-Programming-2nd-Applicat... https://www.amazon.com/Zen-Code-Optimization-Ultimate-Softwa... Zen of Asm is also online, I think a few of the other works, too. http://www.jagregory.com/abrash-zen-of-asm/

Ahhh, Zen of Graphic Programming was my one of first graphics books, which led straight to Foley, vanDam, et. al., and I was hooked :)

It's safe to say Abrash's book had a big impact on me.

Norton's books also make me nostalgic, so thank you for that, GP.

Re: X86 assembly doesn’t have to be scary

#30
I started with 6502, then ARM in 1989 (thanks acorn!), then a little bit of x86. The latter was a culture shock. It’s was like grooming the devil’s genitals in comparison to ARM. It drove me to C and Unix where I’ve been happy ever since (occasionally a bit of PIC assembly as well).

It’s not scary just nasty.

Post reply on HN