Live data from Hacker News

Some Assembly Required: An approachable introduction to assembly

github.com

91–100 of 131 posts

Re: Some Assembly Required: An approachable introduction to assembly

#91

Good job. Some constructive criticism: There's quite a big difficulty spike so to speak in the later section as you go towards the code examples. The beginning explains relatively simple concepts like binary, then basically jmps into an instruction table which won't make sense to anyone who hasn't done some form of programming (they would know binary then, right?). The tone is also a bit off putting, although I might…

> Learning assembly is not actually that fun, it's rather painful. It's what you do with it that is fun. As a teen, I taught myself assembler circa 1982 on my Radio Shack Color Computer (with 4k of RAM!). It was indeed painfully challenging, especially due to the complete lack of information available and the fact I didn't know anyone else who knew anything about it. The only reason I persisted was that the BASIC int…

You put it better than I did. I'm younger than you so I had IRC & phpBB to lean on, but that still meant clawing out the advanced knowledge from the hands of the elders. It's where I learned that the best way to get a real answer is to first say something wrong. But at least smart enough to get a response.

The feeling of mysticism and challenge is dispersed when put into an easy to grasp format. This enables more people to learn enough to reach the skill floor, but it doesn't teach those with an able mind to reach for the ceiling. I see this nowadays a lot, most people around me who didn't grow up with this culture are much worse debuggers. That's not because of their technical skills, but a lack of tenacity. Having answers be far far away means that when you start finding them regardless, you gain an inner mindset of "no matter how hard this is, eventually it is understandable". Seeing what other people could reverse engineer with extremely poor resources inspires one to try harder when there's no solution in sight. It's also taught me that I am _nowhere near as smart_ as I thought I was. To a hilarious degree. Somehow this is not a paradox.

Re: Some Assembly Required: An approachable introduction to assembly

#92
post #14

Assembly language is actually simple stuff. You just need to read the datasheet. No difficult type systems to deal with. In the old days programming assembly language was nasty because one mistake could mean your computer had to be rebooted and you lost your work. Not anymore.

Just read the data sheet!

googles Intel CPU data sheet

Ah, here we go.

https://www.intel.com/content/www/us/en/products/docs/proces...

Just two volumes and 1000 pages of reading. Simple!

Re: Some Assembly Required: An approachable introduction to assembly

#93
Having started my career at Bell Labs in 1984, the fact that you included AT&T X86 syntax cracked me up.

If you are still interested in learning more, ARM and PowerPC are also both interesting assembly targets.

Prior to Bell Labs (college) my assembly experience was 8085 bare metal (no OS) or Z80 under CP/M and MP/M. I wrote a couple console management applications for MP/M that had to dig into BIOS/BDOS routines. It was fun, and that was the thing that made my EE self realize that I wanted to work on software in embedded systems.

Re: Some Assembly Required: An approachable introduction to assembly

#94
post #43

There was a coding competition at a local podunk BBS back in ~’91. I figured I would use it as an excuse to learn some assembly. The goal of the challenge i entered was to find all of the prime numbers between one and a million. Of course my goal with the assembly approach was speed and executable size. In both of those I smoked the competition by 3 to 4 orders of magnitude. But the scoring mechanism was heavily weig…

Well, if LoC didn’t count you could just write a gigantic multi-megabyte print statement :)

Re: Some Assembly Required: An approachable introduction to assembly

#96

So probably a really dumb question, but given that assembly has a limited number of operations and a limited number of registers, what are processors doing with the ever growing number of transistors added to them? What is processed with billions of transistors that can't be done with thousands?

The sibling comments cover the bases really well, but just in case it's not obvious, what you are thinking of as a relatively simple machine - with a limited range of operations and registers - is actually itself an abstraction.

You see the machine executing a sequence of instructions, and that is exactly what happens - eventually.

But behind the scenes, the goal of the hardware is to execute those instructions as quickly as possible. Since there's a limit to how fast silicon can work, the way to achieve this is via a number of tricks that effectively throw yet more circuitry at the problem, taking you from millions to billions of transistors.

Just one of these tricks for example is caching. Instead of writing directly to memory (as it appears to your assembler code), the CPU actually writes data to the L1 cache, a smaller but much faster block of memory on the CPU itself. At a later time, the data can be transferred from the cache out to RAM. In fact a modern CPU will have caches feeding into caches - e.g. CPU feeds into the L1 cache, which itself feeds into the L2 cache, then into the L3 cache, and finally into RAM. At each step, the cache gets larger and slower - so while the L1 cache is measured in KB, the L3 cache in a modern CPU might be up to 64MB in size.

You don't see any of this when you are writing assembler code. To all intents and purposes the caches are invisible to you. There are obscure instructions like CLFLUSH that provide very limited control of the cache but these are not typically something you'd use.

It's easy to see how managing these caches enormously increases the circuitry in the chip, without any need for you, the assembler programmer, to even think about them.

As other commenters have noted, other areas where extra circuitry is thrown at the problem include area is pipelining. In your mental model, the CPU is probably plodding along executing instructions one after another. In practice the CPU is aggressively trying to reorder those instructions and execute them in parallel as much as possible. This is an incredibly complex process, requiring enormous amounts of circuitry.

TLDR; what you see as a relatively simple CPU instruction set is really an abstraction - behind the scenes is an enormously complex collection of moving parts that break your code down and try and execute it as quickly as possible.

Re: Some Assembly Required: An approachable introduction to assembly

#97
post #94
post #43

There was a coding competition at a local podunk BBS back in ~’91. I figured I would use it as an excuse to learn some assembly. The goal of the challenge i entered was to find all of the prime numbers between one and a million. Of course my goal with the assembly approach was speed and executable size. In both of those I smoked the competition by 3 to 4 orders of magnitude. But the scoring mechanism was heavily weig…

Well, if LoC didn’t count you could just write a gigantic multi-megabyte print statement :)

That's thinking outside the box! xD

Re: Some Assembly Required: An approachable introduction to assembly

#98
post #14

Assembly language is actually simple stuff. You just need to read the datasheet. No difficult type systems to deal with. In the old days programming assembly language was nasty because one mistake could mean your computer had to be rebooted and you lost your work. Not anymore.

I may be very out of date, as my last assembly language programming was in 80386 days - but types are important in x86. You definitely need to know your words from your bytes, and your index from your offset.

Re: Some Assembly Required: An approachable introduction to assembly

#99

Love this! Must admit, my favourite part of doing a CS degree was creating a CPU core from scratch (a cut down ARM, running on a FPGA), then writing asm to run on it. So satisfying knowing I made the actual CPU (at gate level) and ran my own code on it. I’d be happy to do a YouTube series covering how to do this if anyone is interested.

Check out Ben Eaters youtube channels https://www.youtube.com/channel/UCS0N5baNlQWJCUrhCEo8WlA - He builds similar, and offers a kit for sale at (from what I can tell) a reasonable price, so you can also DIY.

Re: Some Assembly Required: An approachable introduction to assembly

#100
post #97
post #94

Earlier quoted context omitted.

Well, if LoC didn’t count you could just write a gigantic multi-megabyte print statement :)

That's thinking outside the box! xD

These days you could use a language with compile-time macro execution like nim or D and have it both ways…
Post reply on HN