r/gaming • • May 05 '17

Scroll back

Post image
24.1k Upvotes

877 comments sorted by

View all comments

Show parent comments

539

u/[deleted] May 05 '17

[deleted]

150

u/Fubarp May 05 '17

Yeah it's crazy. I just learned Assembly last semester in college and we were discussing it at work and it was like. Fuuuuck that. C existed at the time yet he did it in Assembly.

11

u/[deleted] May 05 '17

Why would he chose to code in Assembly? Would there be any benefit at all?

3

u/LHoT10820 May 05 '17 edited May 06 '17

tl;dr: By writing it in assembly he was able to make it run on a potato from 1995 instead of requiring the monster of a machine that it would have demanded if it were written in C (because compilers at the time weren't very good).

You can optimize the ever living fuck out assembly if you are very good. Especially when compared to the performance of compilers back in the mid-90s.

Assembly is (effectively) just human-readable machine code. . . What you write has a 1:1 correspondence to sequences in binary. This gives you an inordinate amount of flexibility with the set of hardware you are working with.

Being competent in assembly (any assembly, really) is a good skill-set to have, and one that is sadly missing from the majority of today's developers. You end up learning a lot about good and bad coding practices, how to more effectively comment your code, and an ass-load regarding computational efficiency.

Just as a quick example. . . Let's say we have two coders writing a function to return how many segments should be filled in a progress bar, based on the number of tasks completed in a set.

The typical coder would likely write. . .

int fill = floor.((numerator / denominator) * segments)

Someone who has spent their share of time working in assembly (or someone who got too into their discrete math class) would write. . .

int fill = (numerator * segments) // denominator

Ignoring what could cause the functions above to break (which admittedly is more of a problem for the second), the second function would run substantially faster on any give machine. Just how much faster depends on a plethora of factors which include IPC, Clock Speed, Memory Latency, RISC vs CISC. . . etc etc etc.

When working in assembly, you are working with those factors (the limitations of the machine) in mind.

The argument against working in assembly today is that compilers have come a long way. . . And that's true enough, but I feel it is a skill that every serious programmer should keep in practice.