Skip to content

Instantly share code, notes, and snippets.

@codekittie
codekittie / mult.asm
Created December 12, 2020 08:02
asm program to multiple 6 by 5 ~recursively~
global _start
section .text
multiply:
xor rax, rax
cmp rsi, 0
je base_case
dec rsi
call multiply
add rax, rdi
@codekittie
codekittie / first_5.asm
Created December 6, 2020 05:57
Khety's first sola C assembly mixin
global main
extern printf
section .text
main:
mov rax, 1 ; start current number as 1 in rax
mov r8, 5 ; move counter into r8
loop: ; add a label to jump to
@codekittie
codekittie / sum_pos.asm
Created December 6, 2020 04:41
Sum of positives in array
SECTION .text
global positive_sum
; eax = return value (positive sum)
; rdi = pointer to array of ints (4 bytes)
; esi = length of array in rdi
positive_sum:
xor eax, eax
loop:
cmp WORD [rdi], 0 ; check if [rdi] greater than 0
@codekittie
codekittie / stars.asm
Created December 6, 2020 02:49
Print a pyramid of stars
global _start
SECTION .text
_start:
mov r8, 1
loop:
mov rax, 1
mov rdi, 1
mov rsi, star
mov rdx, r8
@codekittie
codekittie / die.asm
Created November 27, 2020 05:41
Reboot machine via syscall
section .text
global _start
_start:
; 169 = reboot
; Followed by magic numbers (see `man reboot.2`)
mov rax, 169
mov rdi, 0fee1deadh
mov rsi, 672274793
@codekittie
codekittie / tnp.asm
Created November 24, 2020 07:17
Khety's whacky number pattern
global _start
section .text
_start:
mov r10, 2
mov r9, 3
mov r8, 3
loop:
@codekittie
codekittie / crtfile.asm
Created November 23, 2020 05:26
Use syscalls(!) to create a file and then exit
global _start
section .data
File_Name: db 'WTH just happened',0
File_Mode: dq 063q
section .text
_start:
mov rax, 85
@codekittie
codekittie / multi2.asm
Created November 20, 2020 00:51
Multiplying 2 numbers in assembly
global _start
section .text
_start:
; multiply two numbers
; we are going to have a loop that lets us loop the amount of times
;that we want to multiply it
mov r8, 0
@codekittie
codekittie / fib.asm
Created November 13, 2020 05:24
Khety's first Linux x86_64 assembly program
global _start
section .text
_start:
mov r8, 0
mov r9, 1
mov r11, 1
loop: