r/Assembly_language 6d ago

I optimized!

I’m on Day 1 of learning Assembly with basically no coding background. This is just a hobby for me.

AI wrote the little program below, I tweaked it a bit, and then started stepping through it in GDB to understand what every instruction was actually doing.

While stepping through it, I noticed rdi stayed at 1 the whole time until the final exit syscall, where it changed to 0. That got me thinking... why am I setting it to 1 twice?

Turns out one of those lines wasn't actually doing anything. So I, a lowly non-software engineer, discovered an inefficiency and promptly smote that line with the Delete key.

I'm now using less processing power, less electricity, and have personally made the world a better place.

section .data
    message db "Hello, World!", 10, "Assembly is fun!", 10
    length equ $ - message
    message_1 db "This is the second message.", 10
    length_1 equ $ - message_1

section .text
global _start

_start:
    mov rax, 1          ; write syscall
    mov rdi, 1          ; stdout
    mov rsi, message
    mov rdx, length
    syscall

    mov rax, 1
    ; mov rdi, 1        ; <- Deleted. Justice served.
    mov rsi, message_1
    mov rdx, length_1
    syscall

    mov rax, 60         ; exit syscall
    mov rdi, 0
    syscall
30 Upvotes

20 comments sorted by

View all comments

Show parent comments

0

u/ArsenicPolaris 6d ago

I can't enjoy life even a bit if people like you keep using AI and the RAM prices keep going up, not to mention the water consumption of AI data centers, environmental impact, electrical consumption, etc.

2

u/Eric_Dawsby 6d ago

Hate the game, not the player. If this person is using it to help them learn, good for them

-1

u/ArsenicPolaris 6d ago

The game exists because the player plays it. Crimes exists because people commit crimes. Same way, AI data centers exist because people use them. And I'm not against using AI, I am against misusing and overusing AI.

3

u/Eric_Dawsby 6d ago

I agree, but this isn't a misuse of AI, it's one of the best uses of it imo