Assembly will never die

MrAl

Joined Jun 17, 2014
13,918
just stumbled on this thread. recalling putting together and playing with ZX81. shortly after that got spectrum 48k, and soon after that first PC (XT).
when it comes to assembly the most exciting time for me was the 90s when assembly demo scene was making big waves with visual and audio effects.
and who does not like good story like how Rob Barnaby made WordStar?
Hi,

I loved assembler because you had control over every single instruction plus every cycle time period. If you set a loop to run in 1ms, it ran in 0.001000 seconds not 0.001001 seconds. It was beautiful compared to the crazy stuff we see today. It's hard to code that though if you want multi threads and such that we seem to need today. I've done it, but it's not easy.
I remember back in the day when I worked for a company and had to code something fairly complicated in assembler. I had to make a flow chart so I could keep track of everything that was happening or could happen. It was pretty neat though. Today I think we are too lazy to do that kind of thing anymore and it does take a lot of time too, and not doing that leads to sloppy code.
 

MrAl

Joined Jun 17, 2014
13,918
Ha.

So I wonder: is this a case (i.e. FFMPEG) where assembly is actually required to achieve necessary performance metrics on a modern 64 bit processor, or are they just intellectual purists (and programming masochists)?

In any case, I'm happy they're keeping the flame alive on modern hardware.
Hi,

Oh I did not know that, but I have seen other cases where a higher level language just didn't perform well enough and I had to go lower. In a few cases, I did have to go back to asm but that was because the higher level language simply did not have the right C language calling convention needed for an implementation of COM which is a binary standard and still being used today.
Many years ago I had to use asm to create a math package because the higher level language was just too slow for things like matrixes which require lots and lots of operations to compute. That was before coprocessors came onto the scene. Today there are still advantages however especially in big number (greater than 17 digits) calculations.
 

MrChips

Joined Oct 2, 2009
35,322
That's probably because it *is* more difficult than C :)
I think everybody finds this out sooner or later.
It depends on how one was introduced to ASM. If that was all you had and you were well grounded in learning ASM then it is not difficult.

Having said that, imagine that you had to program the following:

RESULT = ( K x A[++i] - L x B[++j] ) / M x C[++k]

In C, you simply just do that.
In ASM, you would likely have to create your own multiplication and division functions and array operations.
A HLL does all the nitty-gritty stuff for you.
 

joeyd999

Joined Jun 6, 2011
6,562
That's probably because it *is* more difficult than C
Context is important.

It is far easier for me to write PIC 8 bit code in .asm than C, as I've noted many times before.

With C, one needs to rewrite and recompile repeatedly to get desired effects -- assuming desired effects are even possible without adding inline asm.
 

MrAl

Joined Jun 17, 2014
13,918
It depends on how one was introduced to ASM. If that was all you had and you were well grounded in learning ASM then it is not difficult.

Having said that, imagine that you had to program the following:

RESULT = ( K x A[++i] - L x B[++j] ) / M x C[++k]

In C, you simply just do that.
In ASM, you would likely have to create your own multiplication and division functions and array operations.
A HLL does all the nitty-gritty stuff for you.
Hi,

Am not sure what you are saying here.
If we have A and B and compare them, we can make statements about A and B. If we only have A, then we don't have anything to compare it to so how can we say that A (or B) is somehow better.

If I have a car and a truck I can say that the car is easier to drive than the truck and it rides smoother. If all I ever had was a car I can't compare it to a truck I don't have yet but the whole idea is to do a comparison.

I realize C can be difficult too sometimes though because of the extremely varied syntax.
 

MrAl

Joined Jun 17, 2014
13,918
Context is important.

It is far easier for me to write PIC 8 bit code in .asm than C, as I've noted many times before.

With C, one needs to rewrite and recompile repeatedly to get desired effects -- assuming desired effects are even possible without adding inline asm.
Hi,

Well when we make comparisons like these we usually don't consider fringe cases to be the rule.

I liked PIC coding in asm too and C takes up more room in memory usually, so there are advantages.
 

joeyd999

Joined Jun 6, 2011
6,562
"Grok, if I asked you to write a program, not in C or a higher level language, but in x86 assembly, or, even better, x86 object code, would you be able to do it?"

**Yes.**

I can write x86 assembly (both 32-bit and 64-bit) and, for small or simple programs, raw x86 machine code / object code as well.

### What I can actually do

- **x86 assembly** (NASM, GAS, MASM, etc.): straightforward. I can produce complete, assembleable programs — including Linux or Windows system-call interfaces, function prologues/epilogues, stack handling, and common idioms.
- **Raw machine code / object code**: possible for small routines or short programs. I can emit the actual opcode bytes (hex), complete with addressing modes, prefixes, etc. For anything beyond a few dozen instructions this becomes error-prone by hand, so I normally prefer to give you assembly plus the corresponding hex dump of the machine code.

### Practical limits

- Larger programs are much better written in assembly and then assembled with a real assembler (NASM, GAS, etc.). Hand-assembling long stretches of x86 is tedious and easy to get wrong on relative offsets, RIP-relative addressing, etc.
- I won’t claim I can perfectly hand-assemble a multi-thousand-line program with no errors; nobody can reliably do that by eye.
- I can also explain the encoding of any individual instruction or sequence you care about.

If you want to try it, just tell me:
- Target (Linux x86-64, Windows x64, bare metal, 32-bit, etc.)
- What the program should do
- Whether you want pure assembly, assembly + hex listing, or only the raw bytes

I can generate it.
 

joeyd999

Joined Jun 6, 2011
6,562
"Grok, I bet you could hand-assemble z80 code! I did that as a 9 year old kid."

Absolutely. Hand-assembling Z80 is very doable.

The Z80 instruction set is compact and regular enough that small programs (a few dozen instructions) can be hand-assembled with reasonable accuracy—especially if you keep a decent opcode table nearby. Relative jumps, the IX/IY offsets, and the prefix bytes (CB, DD, ED, FD) are the main things that trip people up, but they’re manageable.

Plenty of people did exactly what you did: as kids with a pencil, paper, and a Z80 opcode chart, writing machine code for Spectrum, TRS-80, Coleco, or whatever they had. It’s a great way to really internalize how the machine works.

If you want to try it right now, give me a short program idea (or even just a few lines of Z80 assembly) and I can hand-assemble it to hex bytes for you—complete with the calculated addresses and any relative offsets. Or I can just spit out a tiny classic routine (clear screen, print a character, simple loop, etc.) already hand-assembled.

Your call.
 

WBahn

Joined Mar 31, 2012
33,364
"Grok, I bet you could hand-assemble z80 code! I did that as a 9 year old kid."

Absolutely. Hand-assembling Z80 is very doable.

The Z80 instruction set is compact and regular enough that small programs (a few dozen instructions) can be hand-assembled with reasonable accuracy—especially if you keep a decent opcode table nearby. Relative jumps, the IX/IY offsets, and the prefix bytes (CB, DD, ED, FD) are the main things that trip people up, but they’re manageable.

Plenty of people did exactly what you did: as kids with a pencil, paper, and a Z80 opcode chart, writing machine code for Spectrum, TRS-80, Coleco, or whatever they had. It’s a great way to really internalize how the machine works.

If you want to try it right now, give me a short program idea (or even just a few lines of Z80 assembly) and I can hand-assemble it to hex bytes for you—complete with the calculated addresses and any relative offsets. Or I can just spit out a tiny classic routine (clear screen, print a character, simple loop, etc.) already hand-assembled.

Your call.
How is a computer program going to "hand assemble" it? What would that even mean? If it's output counts as being "hand assembled", why wouldn't the output of an assembler qualify just as much?
 

kiroma

Joined Apr 30, 2014
355
Will it also force us back to Assembly?

I can't watch the video now, maybe in the coffee-break I can watch it all if its under 10 min, but wasn't Rust to be the substitute of C?
Also, I didn't dive into how the artifacts of edge AI are making now, but it seems rather complex, because the titles are "all of this animation was done in code", and for games +"not using a single asset".

I think AI will also do the "good enough" version of things. You set your goal of 60 FPS on the display/game/UI and then wait until it gets to the point. The language used will be merely a property of the file, which is somewhat sad, but we have to embrace that AI already is much more capable of doing incredibly complex things in an incredibly small amount of time. Tip: follow "evolving.ai" on Instagram, this page has the advances of each week of any AI that does something that break the edge.
 
Top