Live data from Hacker News

Some Assembly Required: An approachable introduction to assembly

github.com

61–70 of 131 posts

Re: Some Assembly Required: An approachable introduction to assembly

#62

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?

Among other things - larger caches, more instructions, more cores and more busses in between them.

Re: Some Assembly Required: An approachable introduction to assembly

#63

very nice! I wouldnt give this to a programming novice but its very nice for people who know their stuff and just havent done asm yet.

Thanks! Totally agree - you need to understand some programming basics in order to understand the examples in the code section. Things like variables and for loops.

Re: Some Assembly Required: An approachable introduction to assembly

#64

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?

1. Modern CPUs have a larger internal register file and dynamically remap the logical registers referenced by machine instructions into physical instructions.

2. Modern CPUs have a very complicated instruction reordering mechanism and data dependency analysis mechanism that allows CPUs to execute multiple instructions in parallel, when it's possible.

3. A lot of transistors are used for caches (instruction and data caches, and other kinds of buffers like the one used for branch prediction etc).

4. Even a single core has multiple copies of the execution units which allow to execute some instructions in parallel (see above).

Re: Some Assembly Required: An approachable introduction to assembly

#66

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?

It's not a dumb question, but it's so broad that it would take at least an entire textbook to fully answer it.

Just off the top of my head, some possibilities are:

* More cores

* More numerous/powerful execution units that can do e.g. vectorized math

* Architectural features such as virtualization and security defenses

* Bigger and more flexible caches

* Complex pipelining/out-of-order/speculation logic that allows more instructions to be executed (on average) per clock cycle

* Special-purpose functional units that dramatically accelerate particular applications (e.g. AES encryption, video encoding/decoding) and are idle the rest of the time

* Replacing "deep" networks of logic gates with equivalent "wider" ones, which occupy more die area but have a shorter critical path, enabling faster clock speeds

Re: Some Assembly Required: An approachable introduction to assembly

#67

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?

Multiple CPUs, Pipelining, multithreading, onboard graphics, Apple's efficiency and machine learning cores... and multiple CPU cores, as well. The code demonstrated in these examples is essentially executed as a single thread in a single core. Modern CPUs are faster not only because of faster clock speeds, but more CPU cores and peripheral stuff, like cache memory and more, on each chip. Packing the transistors closer together means there's less distance to travel between, for example, the CPU and the arithmetic logic unit, or between the CPU and the on-board cache memory.

And I'm sure I've barely scratched the surface.

Re: Some Assembly Required: An approachable introduction to assembly

#68

I was worried this was only going to be a discussion of x86 assembly. Pleasantly surprised it included 6502 and RISC-V. It's worth reading even if you're not a teenager.

I'm glad you liked it! By a teenagers' guide I meant it was written by teens (including me: I'm 17). What do you think of the warehouse analogy?

The warehouse analogy was great. You and your co-writers did a fantastic job.

Re: Some Assembly Required: An approachable introduction to assembly

#69

Pardon, but the assembly code on the "Loop de Loop" chapter currently seems broken. "rax" is acting as all three variables somehow.

Nice catch! Just to be clear, it was that we were incrementing our exponent but not our counter, is that right? I pushed up a fix, but let me know if there were other issues.

It's a bit more involved than that.

  mul rcx, rax       ; multiply our result by our base, save into rcx
This should probably be using rbx, since that's the designated base, not rax, which is the exponent.

In the explanation just above, there's a 2*8 step missing, while this one is incorrect:

  4. result = 16 * 2, result is now 16
Since 2*16 is not 16.

Re: Some Assembly Required: An approachable introduction to assembly

#70

Earlier quoted context omitted.

Nice catch! Just to be clear, it was that we were incrementing our exponent but not our counter, is that right? I pushed up a fix, but let me know if there were other issues.

It's a bit more involved than that. mul rcx, rax ; multiply our result by our base, save into rcx This should probably be using rbx, since that's the designated base, not rax, which is the exponent. In the explanation just above, there's a 2*8 step missing, while this one is incorrect: 4. result = 16 * 2, result is now 16 Since 2*16 is not 16.

Ahhhhh thank you! Do you mind opening a PR or issue so I can get to that? Thank you for noticing!!
Post reply on HN