Skip to content

Instantly share code, notes, and snippets.

@seisvelas
Last active September 12, 2019 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seisvelas/f4d9fe1ce72109b36f0fd3a26684f44a to your computer and use it in GitHub Desktop.
Save seisvelas/f4d9fe1ce72109b36f0fd3a26684f44a to your computer and use it in GitHub Desktop.
My first recursion in x86
section .data
section .text
global _start
global power
power:
; ro ro fite
push rbp
mov rbp, rsp
mov r12, [rbp+16]
mov r13, [rbp+24]
imul rax, r12
cmp r13, 1 ; if r13==1 return
je return
dec r13
push r13
push r12
call power ; woah recuuuuurrrssiOnN
return:
mov rsp, rbp ; realign the stuck after we f-d it up by pushing
pop rbp
ret
_start:
push 4; exponent
push 3; base (thought was called mantissa but google says base
mov rax, 1
call power
mov ebx, eax
mov rax, 1 ; exit()
int 0x80
@seisvelas
Copy link
Author

Still feel like my intuition for what's going on in the stack is weak. Should I be subtracting from the stack pointer after my function calls to make up for all those pushes? Idfk. Gotta work on open source stuff like rn, shift mind gears from x86/cpu to Python/Cuenca

@A1rPun
Copy link

A1rPun commented Sep 11, 2019

@seisvelas
Copy link
Author

(⌐◥▶◀◤)

I didn't expect to ever receive a comment on this Gist! How did you even find this, haha

@A1rPun
Copy link

A1rPun commented Sep 11, 2019

To be honest, I was looking for esoteric Fibonacci algo's and I found your recursive SQL query. Looked around at your gists and saw ; ro ro fite and I immediately thought of Tenga Toppen and I wanted to post the song 😄.

@seisvelas
Copy link
Author

That's awesome! If you ever want to work on a challenging toy problem together let me know

@A1rPun
Copy link

A1rPun commented Sep 11, 2019

That's a fun idea! I have some fibonacci challenges I would like to tackle in SQL, PL/SQL or PL/pgSQL. I'm not sure which version you used for your gist? I'm having trouble running it because it runs forever in mysql (MariaDB).

On a site note, I also discovered racket by reading your gists. I'm going to try it out once I can fully think in FP programming.

@seisvelas
Copy link
Author

I only tested it in Postgres. I could modify if to be a bit more universal but I generally stick with PostgreSQL!

@seisvelas
Copy link
Author

Also, Racket is extremely fun. The main idea is Language Oriented Programming, where you use extensive macros (including reader macros) to change the language itself to fit the problem. A great introduction to LOP: https://beautifulracket.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment