diff --git a/x86-64/hello b/x86-64/hello new file mode 100755 index 0000000..cde3d27 Binary files /dev/null and b/x86-64/hello differ diff --git a/x86-64/hello.asm b/x86-64/hello.asm new file mode 100644 index 0000000..68611b4 --- /dev/null +++ b/x86-64/hello.asm @@ -0,0 +1,19 @@ +format ELF64 executable 3 + +segment readable executable + +entry main + +main: + lea rsi, [msg] ; load effective address of msg into rdi + mov rax, 0x01 ; move 1 into rax (write syscall) + mov rdi, 1 ; stdout = 1 + mov rdx, 14 ; add length to rdx register + syscall + + mov rdi, 0 ; 0 return code + mov rax, 0x3c # exit syscall number + syscall + +segment readable writable +msg db "Hello world!", 10, 0 diff --git a/x86-64/minimum/minimum b/x86-64/minimum/minimum new file mode 100755 index 0000000..1a78a2a Binary files /dev/null and b/x86-64/minimum/minimum differ diff --git a/x86-64/minimum/minimum.asm b/x86-64/minimum/minimum.asm new file mode 100644 index 0000000..835f67c --- /dev/null +++ b/x86-64/minimum/minimum.asm @@ -0,0 +1,47 @@ +;############################### +; +; MINIMUM IN X64 +; +;############################## + +; ============================= +; Find smallest number +; rax = current item +; rbx = index of data_items +; rcx = smallest item found +; rdi = return value +; ============================= + +format ELF64 executable 0 + +segment readable executable + +entry main +main: + mov rbx, 0 + mov rax, [data_items + rbx * 8] + mov rcx, rax + +loop_through: + cmp rax, 255 + je exit + inc rbx + + mov rax, [data_items + rbx * 8] + cmp rax, rcx + jge loop_through + + mov rcx, rax + jmp loop_through + +print: + mov rax, 0x01 + mov rdi, 1 + mov esi + +exit: + mov rax, 0x3c + syscall + +segment readable writable + data_items dq 3, 67, 34, 222, 45, 75, 54, 34, 44, 33, 22, 11, 66, 255 diff --git a/x86/minimum/Makefile b/x86/minimum/Makefile new file mode 100644 index 0000000..705b017 --- /dev/null +++ b/x86/minimum/Makefile @@ -0,0 +1,3 @@ +default: + as minimum.asm --32 -o minimum.o + gcc -o minimum.elf -m32 minimum.o -nostdlib diff --git a/x86/minimum/minimum.asm b/x86/minimum/minimum.asm new file mode 100644 index 0000000..edd9eb9 --- /dev/null +++ b/x86/minimum/minimum.asm @@ -0,0 +1,32 @@ +# FIND SMALLEST NUMBER +# edi = index of data_items +# ebx = smallest item found +# eax = current item + +.global _start +.intel_syntax noprefix +.section .text + +_start: + mov edi, 0 # move 0 to edi (first index) + mov eax, [data_items + edi * 4] # move first number to eax + mov ebx, eax # move eax to ebx + +start_loop: + cmp eax, 255 # compare eax to 0 + je loop_exit # if eax == 0, jump to loop_exit + inc edi # increment edi by 1 + + mov eax, [data_items + edi * 4] # move next number to eax + cmp eax, ebx # compare smallest item (ebx) to current item (eax) + jge start_loop # if ebx is greater than eax, jump to start loop + + mov ebx, eax # move eax to ebx + jmp start_loop # jump back to start_loop + +loop_exit: + mov eax, 1 # move 1 to eax (syscall number) + int 0x80 # kernel interrupt + +.section .data + data_items: .long 3, 67, 34, 222, 45, 75, 54, 34, 44, 33, 22, 11, 66, 255 diff --git a/x86/minimum/minimum.elf b/x86/minimum/minimum.elf new file mode 100755 index 0000000..4ba9229 Binary files /dev/null and b/x86/minimum/minimum.elf differ