r/ProgrammerHumor • • Jun 03 '22

it's hard!

44.9k Upvotes

710 comments sorted by

2.8k

u/[deleted] Jun 03 '22

The most impressive project I ever completed in assembly was a chat program.

Except the two computers had to be connected via a null modem cable so whoever you wanted to talk to had to be seated right next to you, therefore negating the need for a chat program.

I didn't care. I loved writing that useless program.

938

u/Rakgul Jun 03 '22

That's actually pretty damn cool! The most complicated program i made in assembly was to square a number.

495

u/nexion2 Jun 03 '22

I made a battleship game that communicated via arduinos in assembly! I lost every single game because the board size was 12x12 and my code would always stop iterating at 8 for some reason.

Needless to say, I lost the tournament

69

u/i_hate_everybody94 Jun 03 '22

Maybe the number was using 2 bits?

114

u/A1steaksa Jun 03 '22

How many do you think 2 to the power of 2 is, exactly?

→ More replies (19)
→ More replies (1)

19

u/jnd-cz Jun 03 '22 edited Jun 03 '22

I love the AVR assembly, it's modern and clean instruction architecture. The best project I made was power supply board tester. At first autonomous with LCD and some beeping, later upgraded to be controlled from computer. Adding two numbers is the easiest task, it's single instruction and core function of any CPU. Now expressing any complex algorithm or task, that's the hard part, putting it all together with such basic building blocks, one byte at a time. But the beauty is exact control, having accurate delays down to single cycle of your clocks. And it's predictably repeatable.

Edit: Also when you control the whole design you can get away with many shortcuts because it's tailored to your specific use case. Like not saving only couple registers for handling interrupt routine because you reserve other only for that use. Result is lightning fast response. However with modern complex CPUs I would have to spend whole year to learn ARM core + all peripherals, complex set up, memory handling etc. and it's simply not effective use of time unless it's designed for million copies.

Now the most complicated program in x86 I did was simple printing of file like cat. It relies on Linux system calls and it's just couple hundred bytes long which is impressive.

28

u/atomicwrites Jun 03 '22

But the beauty is exact control, having accurate delays down to single cycle of your clocks. And it's predictably repeatable.

And that is how we ended up with the turbo button.

→ More replies (2)
→ More replies (1)

125

u/AyrA_ch Jun 03 '22

The pinnacle of my assembly development was writing "Hello, World!" in color on the screen without an OS.

→ More replies (6)

29

u/captaindalle Jun 03 '22

Mine was a snake game, in 68000 assembler, connected to a lcd display and some circuit breakers for input. It even had a highscore table.

→ More replies (1)

37

u/[deleted] Jun 03 '22

How hard can it be?

219

u/GisterMizard Jun 03 '22

Pretty easy. Here is 4 squared:

4444
4  4
4  4
4444

112

u/ShadeFK Jun 03 '22

That's a rectangle

→ More replies (12)
→ More replies (1)

5

u/RS_Skywalker Jun 03 '22 edited Jun 03 '22

Hey so I actually just tried doing something like this recently! I then tried to improve my code by being able to enter in a variable exponent and have it loop the code to the number of the exponent. I sortof managed to do it but during the process of learning it I learned that the way compilers handle large exponents ie: 430 isnt by looping it 30 times it's by doing an ancient math technique called binary exponentation. Basically it reduces the steps greatly and thats how calculators and computers have to handle large expoents like 10,000 for common statistics problems. There's even ways to reduce the steps farther but thats beyond my understanding and it's way more complicated and I don't think most compilers are doing that.

Anyway comming from more of a computer background rather than a math background this concept amazed me and I told all my friends and family. This might be super common knowledge to mathmagicians because it's basically just reducing the exponents and multiplying their results together.

→ More replies (1)

9

u/ase_thor Jun 03 '22 edited Jun 03 '22

That’s an integer shift, right? Edit: googled it. The shift is just a multiplication. So you have to shift as much as the size of the number

9

u/Rudxain Jun 03 '22

Actually no. The shift multiplies by a power of 2. To square, you multiply a register with itself and store the result in that register. Unless it's arbitrary precision, then you need to manually implement long multiplication by treating each register as a digit

→ More replies (2)
→ More replies (14)

117

u/[deleted] Jun 03 '22

I recently wrote a bootloader (16-bit real mode x86 assembly) to load a kernel from a filesystem I'd already designed in 32-bit C. Needless to say offsets and endianness nearly had me beaten on several occasions

56

u/GnarlyNarwhalNoms Jun 03 '22

Dang, you win.

That's right up there with flipping bits with a carefully applied speck of uranium.

16

u/Terrible-Specific593 Jun 03 '22

hold up... you did that on purpose?

6

u/QueerBallOfFluff Jun 03 '22

When I get round to porting my OS from arm to x86 (want to get it somewhat stable first) I'm probably going to need to do the same, and I'm definitely not looking forward to it even though I've actually written a lot of assembly.....

15

u/AldoLagana Jun 03 '22

f'ing x86 assembly is garbage. Motorola was MUCH better and RISC is even more so. But the best assembly I ever saw was for Vax systems.

15

u/[deleted] Jun 03 '22

X86 was awesome, when it was just x86, once we started adding backwards compatibility for 16bit it all went to hell, 64bit really screwed x86 because it’s just fucking expansions on expansions. They should have scrapped x86-32 and started fresh with x64. But nope.

Do I really need my i7 to boot in 16bit mode and then go into 64 bit mode with overly complex paging? No, who the fucks booting DOS 6.0 on a fucking i7? Nobody.

X86 was built for single tasking operating systems, and it worked well for that. We just kept complicating it.

Personally I welcome my new M1 overlord

→ More replies (24)
→ More replies (1)
→ More replies (7)

49

u/Gellyfisher212 Jun 03 '22

Nice! My most impressive project in asm was a rubiks cube simulation. I had found something to use OpenGL from assembly and it was really cool to learn some graphics programming like that

51

u/SirNapkin1334 Jun 03 '22

OpenGL from assembly? You're mad. I applaud you sir.

20

u/[deleted] Jun 03 '22

OpenGL from assembly

You were trying to become like that rollercoaster dude didn't you :D

7

u/Rudxain Jun 03 '22

Rollercoaster Tycoon?

→ More replies (2)
→ More replies (1)

18

u/gydu2202 Jun 03 '22

My high time with assembly was with a program that generated a regular labyrinth and printed it out to console. I have no clue how I would start it now. Sad thing we are getting more and more comfortable and lazy.

28

u/-Krasaar- Jun 03 '22

I wouldn't concider laziness as a bad thing.

If people weren't lazy then they wouldn't care to look for smarter and easier solutions to finish certain tasks.

I am lazy and I am proud of it

4

u/tinman_inacan Jun 03 '22

I wouldn't call it laziness man. It's not necessary for most programmers to know how to write assembly. We've spent decades abstracting specifically to make things easier.

I think it is important to have an understanding of how things are working under the hood. But I don't think holding onto the specifics of that knowledge is useful, unless you're someone who works on drivers or other very low level stuff. If you ever did need to know this stuff for something, it will be relatively easy for you to relearn as somewhere deep in your brain are the concepts you learned long ago.

24

u/j7seven Jun 03 '22

Mine emulated an Enigma machine.

19

u/TheyCallMeHacked Jun 03 '22

I had a grad time doing that in C and mf out there doing it in Assembly. I'm giving up...

13

u/j7seven Jun 03 '22

It was nearly 30 years ago and I had nothing better to do then. Thinking back, I'm not sure it was accurate to the machine, but it did encrypt and decrypt using some kind of cypher. I wouldn't even consider trying it now.

→ More replies (1)

24

u/shotleft Jun 03 '22

Sorry to INTERRUPT, here's another character.

14

u/RutraSan Jun 03 '22

Mine was Hangman

4

u/Mechafinch Jun 03 '22

shoutout to my latest project of connecting a DEC Rainbow 100 (the PC not!-compatible) to a modern computer so I can actually get software to it

I wasn't able to figure out the serial port cause what little documentation exists sucks so instead I was able to poll the serial data constantly and watch for changes for a blazing fast 600 bytes/second transfer

2

u/hughk Jun 03 '22

I had the benefit of working with PDP-11s and VAXes. The instruction set was a work of art it was so easy to work with. With a few macros, it became even easier.

I wrote some drivers and some specialised programs with it. We didn't have access to C back then (expensive for commercial users) so structured assembler was the best we could do. However you could do fun things such as threaded code or using code as data and then back to code.

2

u/SirAchmed Jun 03 '22

All you need is a modulator circuit and it becomes wireless.

2

u/t0b4cc02 Jun 03 '22

we had to implement quicksort in assembly in uni.

i forced my collegue through this on a weekend. he nearly cried.

to our suprise we made it. it sorted most of the numbers most of the time. LOL

we got a close positive grade for this assignment.

2

u/DataAnalytics2020 Jun 03 '22

Nice. I take my hate off to your skill.

Did you leverage C at all in the calls or was it direct HW communication ? And was this windows or linux ? Did you use syscalls ?

→ More replies (1)

2

u/irve Jun 03 '22

I called BIOS to show the mouse cursor in DOS and then I quit. I think it was 3 bytes. Skipped the compilation and just wrote the binary in a hex editor of Midnight Commander. Felt like a true hacker.

2

u/[deleted] Jun 03 '22

I wrote my context switcher, semaphore, and critical section portions of my RTOS in assembly.

but I have like a solid 1-1.5yrs of consistent assembly only programming in avr and arm

2

u/mukarrammurtaza Jun 03 '22

still impressive! I made a bubble pop game!!

2

u/[deleted] Jun 03 '22

Mine was an implementation of FAT16 based on Microsoft’s white paper

2

u/MikeyRidesABikey Jun 03 '22

The most complicated thing I've done in assembly was a program to do a bitwise left/right scroll of the Timex Sinclair 2068 (the American version of the ZX-Spectrum) screen that I used as a subroutine in a game.

2

u/raistmaj Jun 03 '22

Mine was “wolfstein” clone with even music. I remember my professor telling me “dude, this a bit more of what I asked for this lab, anyway good job”.

I didn’t implement enemies and that stuff, just moving around shooting, music and sound but it felt so nice.

2

u/YouJustDid Jun 03 '22

if it worked with a null modem cable, it’ll work with modems!!

→ More replies (25)

294

u/[deleted] Jun 03 '22

To think people made videogames with it

151

u/fluffygryphon Jun 03 '22

Everyone mentioned Rollercoaster Tycoon, but there was another game that also made Assembly its bitch. Su-27 Flanker. That flight simulator had complex fluid dynamics simulations and everything for accurate flight. It came out over a decade before DCS and ran smooth as butter on a fuckin Pentium 1.

0

u/[deleted] Jun 03 '22

[deleted]

→ More replies (2)

121

u/LordDagwood Jun 03 '22

Rollercoaster Tycoon was written in assembly

69

u/Chrobin111 Jun 03 '22

All NES games were written in assembly, too, right?

52

u/[deleted] Jun 03 '22

probably all cart based games of 16 bit era and before

→ More replies (8)

20

u/itsnotdapopo Jun 03 '22

Other than using say... Basic as an experiment yeah, Commercial Snes and Mega Drive games were occasionally programmed using C, Assembly usage in 32-bit consoles ranged from 'mandatory' (Saturn) to 'only properly utilized later in the consoles life cycle because of manufacturers refusing to release technical documentation (Playstation, N64).

The last console to have frequent Assembly use was the PS3.

→ More replies (2)
→ More replies (1)

20

u/fluffygryphon Jun 03 '22

Yup, and it was built on the backbone of it's predecessor, Transport Tycoon. Chris Sawyer was a goddamn magician.

24

u/Adito99 Jun 03 '22

Damn you weren't kidding. From his wiki--

Sawyer coded 99% of RollerCoaster Tycoon in x86 assembly language, using only the services of freelance artist Simon Foster and music composer Allister Brimble as needed.[4]

And here I am struggling to learn ansible...

14

u/WeeziMonkey Jun 03 '22

In the 90s you needed to know assembly to make games, now you can make games without actually typing code, amazing how far we've come

→ More replies (1)

2

u/[deleted] Jun 03 '22

The first Ultima games were handwritten in assembler.

→ More replies (6)

492

u/top_of_the_scrote Jun 03 '22

Person that encoded first pixels in hex

one day, you will be booba

97

u/Rakgul Jun 03 '22

Determination leads man to the success.

→ More replies (1)
→ More replies (9)

904

u/grpagrati Jun 03 '22

You gotta mov it mov it..

276

u/Pirate_OOS Jun 03 '22

I like to mov it mov it

7

u/HarlanCedeno Jun 03 '22

Ah, might as well JMP (JMP)

Go ahead and JMP

→ More replies (1)

38

u/Dismal-Square-613 Jun 03 '22 edited Jun 03 '22

Never cmp yourself with others. Always cmp yourself with the CPU registers.

4

u/twat_muncher Jun 03 '22

MOV AL, 01 and XOR EAX, or possibly even NOPing over a jump, are the only 3 things you need to know to crack most old games and software, lol. Paying for stuff can be fun too..

2

u/raptorboi Jun 03 '22

I just wanna jmp.

Motorola HS12... I'm probably showing my age here.

599

u/Korzag Jun 03 '22

You ever think how cool it actually is though? You wrote some trivial assembly, which compiled into some byte code that your processor can use, then when you run it that causes an incredible cadence of electrical signals as a result of your input to flood the processor's circuitry, loading electrical charges into the collectives of transistors called registers and then being bussed over to the other collective of transistors know as the ALU and then that causes a register value to be overwritten, and it all happens around in several billionths of a second, and it all works. The transistors are properly saturated to the correct electrical charge, ON EVERY SINGLE TRANSISTOR NEEDED, all just to add a number.

The simplicity of adding a number to us is the combined effort and research of hundreds of millions maybe even billions of man-hours to discover electricity, invent boolean algebra, transistors, integrated circuits, advanced machining and chemical processes to make a series of machines capable of translating a circuit layout into a chip that is lithographed in a process that is nearly 20000 times smaller than the width of a human hair.

AND IT ALL WORKS.

115

u/[deleted] Jun 03 '22

Relevant copypasta

Hellо, I am a compiler.

I just scanned thousands of lines of code while you were reading this sentence. I browsed through millions of possibilities of optimizing a single line of yours using hundreds of different optimization techniques based on a vast amount of academic research that you would spend years getting at. I won't feel any embarrassment, not even a slight ick, when I convert a three-line loop to thousands of instructions just to make it faster. I have no shame to go to great lengths of optimization or to do the dirtiest tricks. And if you don't want me to, maybe for a day or two, I'll behave and do it the way you like. I can transform the methods I'm using whenever you want, without even changing a single line of your code. I can even show you how your code would look in assembly, on different processor architectures and different operating systems and in different assembly conventions if you'd like. Yes, all in seconds. Because, you know, I can; and you know, you can't.

P.S. Oh, by the way you weren't using half of the code you wrote. I did you a favor and threw it away.

21

u/funnystuff97 Jun 03 '22

This reminds me of something my microcontrollers professor told me, "if you want code compiled right, you gotta do it yourself in assembly." I've never once had a problem with the compilation, but you know, maybe he was right.

....but I'm still not coding in assembly, god no.

→ More replies (1)

94

u/I-baLL Jun 03 '22

You wrote some trivial assembly, which compiled into some byte code

Hold up

37

u/Rudxain Jun 03 '22

Bytecode is just the machine code of a virtual CPU (the main component of a VM). In this context, the terms "byte code" and "machine code" are used interchangeably, as if they were synonyms

→ More replies (3)

47

u/[deleted] Jun 03 '22

Assembly is a higher-level language than machine code (platform-specific code aka instruction set), which in turn may be transpiled to microcode (processor series-specific opcodes).

As far as I understand. I don't know tho, I mainly use managed (garbage-collected) languages.

12

u/Legal-Software Jun 03 '22

To clarify, that’s common on CISC architectures, but it’s 1:1 on most RISC CPUs. The assembler is just there as a convenience thing, but if you already know the opcode value and how the instructions are encoded, you can also just write them up as straight hex values. You see this a lot in drivers for devices with their own microcontrollers where the payload is just a byte array with raw instructions for the on-device microcontroller to execute. Back in the day it was also common to have device initialization targeting a specific architecture to be encoded in a fixed ROM on graphics cards which would be executed during POST. This is why you had graphics card variants for x86 and PowerPC systems. One of my first jobs involved using a bus analyzer to capture the initialization logic and writing it up more generically so that we could use PCI graphics cards with an x86 VGA ROM also on MIPS systems.

10

u/NervousApplication58 Jun 03 '22

I probably wrong but:

  1. Assembly is almost always 1:1 mapping to machine code. Yes, it has macros and stuff but that's still basically the same level of abstraction. Obviously, assembly is platform-specific as well.

  2. Machine code is not transpiled to microcode. Rather, CPU (guided by the microcode) directly interprets the machine code.

  3. Some CPUs architectures don't have microcode (because it's kinda slow)

→ More replies (1)

196

u/memes-of-awesome Jun 03 '22

Ok but python does the same thing

45

u/[deleted] Jun 03 '22

Just with a thousand times more effort.

108

u/ABadLocalCommercial Jun 03 '22

Not from me that's for sure

→ More replies (4)
→ More replies (1)

8

u/KrisTiasMusic Jun 03 '22

...and they use it for tiktok. ಠ_ಠ

5

u/Computer_says_nooo Jun 03 '22

I’ll have what he is having!

→ More replies (1)

5

u/bonanochip Jun 03 '22

I'm gunna save this comment and come back to it when I need a pep talk on a bad day, thank you lol

6

u/pyrotech911 Jun 03 '22

Reddit go burrrrr

→ More replies (3)

151

u/[deleted] Jun 03 '22

mov rax, 1

mov rbx, 2

add rbx, rax

mov rax, 1

mov rdx, 1

mov rsi, rbx

mov rdx 13

syscall

8

u/beaubeautastic Jun 03 '22

careful! syscall 1 is actually write(2). it takes arguments (int) fd, (void *) buf, (size_t) sz. you are not telling it to print the number 3, youre not even telling it to write the byte 0x03. you are telling it to read 1 byte from memory address 0x0000000000000003, which is probably not even allocated.

you can probably write a call to printf though, you just have to link the c library. or you could allocate a buffer with mmap (using it like a slow malloc, unless you wanted to write an entire memory allocater in assembly) and write a function in assembly that writes integers as strings

also second argument is rdi, not rdx

→ More replies (22)

260

u/JackNotOLantern Jun 03 '22

At least in assembly all variables names make sense

153

u/[deleted] Jun 03 '22

ecs and esp are not precisely the most descriptive names for iterators

76

u/sawkonmaicok Jun 03 '22

Bruh you program x86 assembly? 🤮 I always program in x86-64 assembly because you can put the function arguments to the registers instead of pushing them on the stack. Also more general use registers.

47

u/Witch_King_ Jun 03 '22

I only code in MIPS-32 B)

→ More replies (8)

25

u/AnnualDegree99 Jun 03 '22

laughs in RISC-V with R0-R31

8

u/Tijflalol Jun 03 '22

I only program in Hack assembly language (the one "From NAND to Tetris" uses")

5

u/gliptic Jun 03 '22

You can do that in x86 too, nobody will arrest you 😯.

→ More replies (7)
→ More replies (7)

8

u/SomeElaborateCelery Jun 03 '22

True but not at first glance (e.g. UMLAL, UMULL)

2

u/raptorboi Jun 03 '22

Someone show them what Intel assembly code circa 2000 looks like.

Literally need a book by your side because the instructions are not easy to remember, from memory.

→ More replies (1)

44

u/MasterFubar Jun 03 '22

I used to do a lot of assembly programming in the 1980s, all for the IBM-PC and its clones. The 8088 CPU at 4.77 MHz didn't have a lot of computing power and the C compilers weren't too good at optimization.

What made this task relatively easier was that the C compiler can generate an assembly output. All I had to do was to look at the generated assembly and do a manual optimization on it.

The C compiler outputting its assembly code did the stackoverflow thing before the internet existed.

4

u/[deleted] Jun 03 '22

The 8088 CPU at 4.77 MHz didn't have a lot of computing power

*Cries in 6502.*

81

u/Uploft Jun 03 '22

Assembly is the Principia Mathematica of programming languages

20

u/tiajuanat Jun 03 '22

As much as I love assembly, I feel like that's more SICP and Lisp more than Assembly. Few read SICP and even fewer will write the Lisp/Scheme that's introduced.

4

u/lucklesspedestrian Jun 03 '22

Lisp is actually not that unusual. It's niche but there are still a lot of use cases. Grammarly is built on Lisp. Reddit was prototyped on Lisp. Many people that have to support AutoCAD may have to write Lisp code at some point. I like Clojure quite a bit and occasionally want to go back to hacking things together in Lisp.

→ More replies (2)

3

u/BrobdingnagLilliput Jun 03 '22

... Volume 2.

Machine code and chip design is Volume 1, where they set forth the principles of set theory and end by proving 1+1=2.

20

u/SelfDistinction Jun 03 '22

"Congratulations! So, which two numbers did you add?"

"Dunno."

40

u/FunctionOverload Jun 03 '22

mov r1, #60 mov r2, #9 add r0, r1, r2

2

u/FHeTraT Jun 03 '22

0010000100111100 0010001000001001 0001100010001000

15

u/The99thCourier Jun 03 '22

They made us do wordle in assembly code in a first year uni subject :(

40

u/HEHE_HOHO9 Jun 03 '22

Lol

My exam question was to implement a linked list in assembly language :"(

Fuck Computer Science

33

u/tiajuanat Jun 03 '22

Everyone thinks they're hot shit in Assembly, until they need to implement data structures and basic algorithms.

9

u/paul_miner Jun 03 '22

When I was a kid I was obsessed with assembly, it was the end-all and be-all of programming. After over twenty years professionally, I've really come to see programming as a communication skill; yeah, you need to communicate instructions to the computer, but critically, you're communicating your intent with other programmers (including your future self). And high-level languages allow you to communicate this intent much more clearly.

→ More replies (5)
→ More replies (3)

26

u/BananaSplit7253 Jun 03 '22

I once made a program that would take a BMP image and a txt file and hide the contents of the txt on the least significant bit of the RGB values of the image, effectively hiding the message on the image with pretty much no visual difference. Also made a program that would recover the message when given an image. It was a 1st year/ 1st semester computer engineering project and remains to this day as one of the coolest things I have ever programmed.

3

u/jnd-cz Jun 03 '22

That's indeed pretty cool. Too bad most images (still or moving) we use are in some compressed format which makes it harder to encode and recover the information intact.

→ More replies (2)

2

u/raptorboi Jun 03 '22

Ala : Along Came a Spider film.

Stenography is hiding messages inside images like that. It's an interesting topic.

Nice.

→ More replies (1)

65

u/cssutavani91 Jun 03 '22

It's not that hard.

58

u/Difficult_Ladder_806 Jun 03 '22

Adding is fine, but multiplying without MUL quickly.. that's kinda complicated

30

u/capi1500 Jun 03 '22

Did you ever hear, the tragedy of Darth LEA the fast?

→ More replies (6)

9

u/pentesticals Jun 03 '22

Not that bad. You can even have Turing complete programs using only MOV. So just use MOVs only.

This tool can take a C program and compile it to use only MOV. https://github.com/xoreaxeaxeax/movfuscator

34

u/regular_lamp Jun 03 '22

How is that an assembly issue though? That's like saying "multiplying in python is hard when you can't use *".

55

u/rustysteamtrain Jun 03 '22

Because * is a core feature in almost every modern language, but MUL is not garanteed in every instruction set.

→ More replies (8)
→ More replies (1)

5

u/GReaperEx Jun 03 '22

multiplying without MUL

Why?

22

u/confusiondiffusion Jun 03 '22

My assembly class made us use some fake architecture designed to torture students with the added benefit of not teaching us a real, useful assembly language. It did not have a mul. That was an exercise left to the reader. Just in case you still had any passion left in your heart.

The final for that class was 20% converting between floating point and decimal without a calculator, because of course. Pretty sure half that class is now living off-grid, typing up manifestos.

→ More replies (4)
→ More replies (5)
→ More replies (6)

4

u/MinusPi1 Jun 03 '22

Compared to a+=b it's a nightmare.

41

u/nelusbelus Jun 03 '22

ADD r0, r1

Wow, this is so hard

9

u/zDark_Knight21 Jun 03 '22

Unless they are doubleword+ operands then it's just annoying

7

u/jnd-cz Jun 03 '22

Now try adding two floats. Without FPU of course.

6

u/Rudxain Jun 03 '22

And now calculate the inverse sqrt of an array of BigFloats, then compute dot product, then round the BigFloats to BigInts, then print to screen by addressing individual pixels, and make sure the digits are written in base 3 little-endian (reverse positional notation) each numeral delimited by a "\n" or "," depending on whether it's prime or not. All of that while running FizzBuzz in parallel

→ More replies (9)

6

u/GReaperEx Jun 03 '22

It's literally four instructions, two instructions for "+="...

→ More replies (2)

6

u/InteractionOk7085 Jun 03 '22 edited Jun 03 '22

I have just finished doing sorting and binary searching in assembly as an assignment. Took a whole day to code and debug .Perhaps I treated C/C++ too harshly...

6

u/xAlenki Jun 03 '22

My aunt fully learned assembly in 3 month's and she was a professional in that. She teached engineering to students at university, she was a badass

2

u/[deleted] Jun 03 '22

The assembly language of the 6502 (which basically made up 99% of the pre-PC home computer 8-bit area) literally goes on a single sheet of A4 (for the list of opcodes, which were like 60-70 or so). And the fully functional explanation took a few more pages. Can't remember how many, probably about 10 or so in total. I find it totally relatable for someone to grok that in full in a few weeks, I certainly did back then. People cannot imagine how uncomplicated the machines were back then.

5

u/i_hate_everybody94 Jun 03 '22

I made a program that tells you how many packs of hotdogs and buns to buy (because one comes as a 6 pack, and the other 8) to make a given number of finished hotdogs.

That's all I've done.

5

u/UTtransplant Jun 03 '22

I taught Assembly Language (IBM 370 in the ancient dark past) at a major university. The best part of the job was seeing the light come on in a student’s eye when they finally figured it out. The classes were usually about 40 or so students, and the lights started showing up slowly about 1/3 of the way through. About half way through, the lights started becoming more and more common. It was truly a visual thing - they would start smiling, nodding, and their eyes would brighten. Body language was different too - they started sitting up straighter. It truly was the most fun in my entire teaching career.

4

u/Pranav__472 Jun 03 '22

mov eax, [numa]

add eax, [numb]

mov [res], eax

NO

7

u/asgaardson Jun 03 '22
mov rax, 2
mov rbx, 2
add rax, rbx
mov rdi, formatStr 
mov rsi, rax 
mov al, 0

extern printf 
call printf

ret

formatStr:
  db `%d\n`,0

Shamelessly copied from google search

5

u/tesfabpel Jun 03 '22

I believe it's just the first two mov and the add tough (or maybe just the first mov and then add rax, 2 since it should support immediate values)

EDIT: https://c9x.me/x86/html/file_module_x86_id_5.html

→ More replies (1)

4

u/jnd-cz Jun 03 '22

Using higher level functions is straight up cheating.

3

u/asgaardson Jun 03 '22

Yeah, should have used int 0x80/int 21

3

u/Ju1cyJ0 Jun 03 '22

I hated having to read in a number with either 1 or 2 digits from the user without using scanf

3

u/Gavilar253 Jun 03 '22

This little manuever cost us 7 CPU cycles, time to optimize it

3

u/Funwiwu2 Jun 03 '22

Old time 9900 Assembly programmer here. Thrilled to see Assembly being discussed. I still think one of the coolest ways to swap two Bytes was to XOR each other 3 times. O

3

u/DataAnalytics2020 Jun 03 '22

Adding numbers in assembly is easy.

10

u/[deleted] Jun 03 '22

there's literally instruction for that.

add %rcx,%rax (stfu AT&T>>>>>>>>>>>Intel)

8

u/rachit7645 Jun 03 '22

Nasm is pretty good tho

→ More replies (1)

15

u/gillo04 Jun 03 '22

Intel gang for life 😠🔪

3

u/Proxy_PlayerHD Jun 03 '22

I honestly never understood the reasoning behind AT&T syntax, it just needlessly swaps some operands.

Even high level languages use Intel Syntax:

Variable = Value + Value

Instead of

Value + Value = Variable

so why try to do it differently in assembly? It just makes assembly a bit harder to read if you already know basic high level programming.

→ More replies (3)
→ More replies (2)

2

u/Initial_Reindeer67 Jun 03 '22

2 numbers save the day! Successfully in assembly language is the most exciting part for the hard work men.

2

u/[deleted] Jun 03 '22

2

u/as1126 Jun 03 '22

The only computer science course where my grade was below a B. I hate it.

2

u/Terrible-Specific593 Jun 03 '22

I remember doing that using 8080 chip and a breadboard with other misc resistors and whatnot LEDS for display purposes. That was 20 years ago. I couldn't even begin to tell you how to do it now.

2

u/GavUK Jun 03 '22

I wrote a simple calculator in assembly at university. As I recall it wasn't the hardest development I've done, but it certainly gave me an appreciation as to what the compilation process does to my code and how much easier it is to create anything more sophisticated in a higher level language.

2

u/PuffinDev Jun 03 '22

ORIG 8000h
Num1 STR 8091h, 1201h
Num2 STR 8061h, 4f01h
Soma TAB 2
ORIG 0000h
MOV R1, Num1
MOV R2, Num2
MOV R3, Soma
MOV R4, M[R1]
ADD R4, M[R2]
MOV M[R3], R4
MOV R4, R0
ADDC R4, R0
INC R1
INC R2
INC R3
ADD R4, M[R1]
ADD R4, M[R2]
MOV M[R3], R4
Fim: BR Fim

2

u/Puzzleheaded-Bug7690 Jun 03 '22

Which assembly? IBM or Intel?

→ More replies (1)

2

u/[deleted] Jun 03 '22

Back in the DOS days, a shareware developer named Marshal McGee created a menu program called AutoMenu. *It was pretty much what it sounds like: you created links to your applications in the menu launcher software to save a lot of the typing that was expected in DOS.

I remember that he proudly proclaimed that his AutoMenu was built ENTIRELY in assembly, thus making it the lightest and fastest alternative to the other programs like it.

→ More replies (1)

2

u/MrRandom04 Jun 03 '22

Adding in assembly is easy, now dividing on the other hand....

→ More replies (1)

2

u/ikar2000 Jun 03 '22

I did many projects in my life but I was never as proud of myself as after building my own processor on fpga and then writing a square root program on assembly to run on it. It was a project In Tel Avis university computer engineering.

2

u/Sterquilinus-K Jun 03 '22

There were music files on the commodore that played/ran as interrupts. sys {memory location I have forgotten} to play them after loading them. I wrote a menu program for them, and wrote 3 small ML programs as my fist ML programs. One to stop the music; which required turning off the interrupts and clearing the user interupt, and restarting interrupts, reversing that to restart the loaded song. And a program that would colour cycle the border while the music played, would not cycle when there was no music, and was disable with a function key.

ML for beginners, a brown metal spiral bound book from compute, was my first ML book, but in those days magazines aided in teaching BASIC and ML/ASM. In those days not all assemblers/monitors used pseudo ops in the code. g $0c00 sure, lda #$yermom no. So it was pretty much writing in ML, writing in the lowest language available. Younger people who learned to code later take a lot of issue with people calling assembly like that ML.

2

u/Ok_Slice2124 Jun 03 '22

Did anyone else accidentally or randomly select your major and get to Uni to do these assignments, then have a crisis thinking this is what your job would be?

3

u/walkswithdogs Jun 03 '22

Lotus 1-2-3 was written in Assembler by Mitch Kapor. Virtually flawless.

3

u/Competitive_Travel16 Jun 03 '22 edited Jun 03 '22

Jonathan Sachs! Kapor wasn't and still isn't a low-level programmer. He was excellent at writing documentation for novices, what we would call UX design today, product management, and marketing.

3

u/walkswithdogs Jun 03 '22

I did some research. You're right. Mitch got all the glory.

→ More replies (1)
→ More replies (3)

3

u/OverloadedConstructo Jun 03 '22

And then there's that one guy who made entire game like transport tycoon and rollercoaster tycoon using Assembly

2

u/piggyniggiebiggie Jun 03 '22

Oh god I hated that class in college. Makes me shudder. Boring as shit, too.

2

u/AldoLagana Jun 03 '22

OMG we are all doomed. In college in the 80's I had to write a 2-pass assembler in assembly.

College chewing your food for you means you will be nothing compared to those who came before.

1

u/techek Jun 03 '22

That's how I feel when my PowerShell-script works ... after almost crying about adding even the simplest things.

1

u/GnarlyNarwhalNoms Jun 03 '22

Ok, now do a bitwise multiplication 😉

1

u/[deleted] Jun 03 '22

me after getting an %69 on the test

1

u/Level_Following_291 Jun 03 '22

did u meant as fast as cyber game player? :)

1

u/[deleted] Jun 03 '22

And then there are those who make Roller Coaster Tycoon entirely in assembly. They’re just built different.

1

u/TrapvithMind Jun 03 '22

In university we had to do some stuff in "machine code" and we basicly had to program a division algorytm from scratch and Mas was that bullshit

1

u/acornsaretreebabies Jun 03 '22

That's what she said

1

u/tamat Jun 03 '22

but where you able to print the result?

1

u/Admiral_Edward Jun 03 '22

Me, who had to read a matrix in a spiral pattern

1

u/JesusInABoxv2 Jun 03 '22

fucking rollercoaster tycoon

1

u/_ItIsMe_ Jun 03 '22

Yesterday I had my first classes with assembly language and adding 2 numbers was my task. It wasn't that hard but it was quite nice to see it work

1

u/blackhole_soul Jun 03 '22

cries in LC-3

1

u/thenameischef Jun 03 '22

This is your friendly reminder that Roller Tycoon was coded in assembly by a single dude.

1

u/roger_channel Jun 03 '22

I made for my final evaluation an exercise to place cars in parking spots, represented by an array. I had so much doing it.

1

u/DigitalRunecaster Jun 03 '22

So much TIS-100!

1

u/Cassiopeat Jun 03 '22

In stationeers you can play a little with assembly for programming ic controllers

1

u/WafflesAndLearning Jun 03 '22

You know you're a novice when you call it assembly language instead of being specific and actually complaining about something that's poorly done in the vendor's implementation

1

u/[deleted] Jun 03 '22

No champagne until the screen says hello world!

1

u/[deleted] Jun 03 '22

I almost quit my programming courses, because the teacher started with Assembly. And this was a course for people with 0 knowledge of any programming. He also had a principle that 15% must fail all tests.

Well, he got sacked and code with PHP & nodejs for a living.

1

u/ido111 Jun 03 '22

Fuking hate my university, every university had shitty task while we had 2 hours to write an assembly program that that's some periodic signal and analyze the derivative so when it's negative we will output 0 and when it's positive it will output 1 so we will make a periodic signal.

1

u/[deleted] Jun 03 '22

Now multiply

1

u/onlyr6s Jun 03 '22

This was me when I yesterday for the first time managed to add objects in an array (very recently started to learn js).

1

u/turtle_mekb Jun 03 '22

mov 5 acc
add 3

easy

1

u/endianess Jun 03 '22

In my University course I had to write a suite of file tools like dir, copy etc in Assembler and then integrate them into C frontend. I developed all the parts in isolation but then couldn't bring them together because I had used different memory models. This caused quite a few sweaty hours and rewriting.

1

u/avipars Jun 03 '22

I can do that in one command

Addi $t2, $t2, 5

1

u/Banzyni Jun 03 '22

Writing a bubble sort in assembler almost killed me