From 51f7f0e9b37ecd13367a69613d748f8d2f313d9c Mon Sep 17 00:00:00 2001 From: winsdominoes Date: Tue, 11 Jun 2024 13:42:37 +0700 Subject: [PATCH] x86 fasm --- x86-64/hello | Bin 0 -> 236 bytes x86-64/hello.asm | 19 +++++++++++++++ x86-64/minimum/minimum | Bin 0 -> 347 bytes x86-64/minimum/minimum.asm | 47 +++++++++++++++++++++++++++++++++++++ x86/minimum/Makefile | 3 +++ x86/minimum/minimum.asm | 32 +++++++++++++++++++++++++ x86/minimum/minimum.elf | Bin 0 -> 8856 bytes 7 files changed, 101 insertions(+) create mode 100755 x86-64/hello create mode 100644 x86-64/hello.asm create mode 100755 x86-64/minimum/minimum create mode 100644 x86-64/minimum/minimum.asm create mode 100644 x86/minimum/Makefile create mode 100644 x86/minimum/minimum.asm create mode 100755 x86/minimum/minimum.elf diff --git a/x86-64/hello b/x86-64/hello new file mode 100755 index 0000000000000000000000000000000000000000..cde3d27b764170c2f60253d6cf0e78d134f9ec75 GIT binary patch literal 236 zcmb<-^>JfjWMpQ50wxAK21X!z1A_xt1VVzDaKeGXf`JJt4^qntmjN*xpgahD56Xkl z3<3}VkUlmbhKb)3Z~#ldXg)BHfdNLt^m+7}ssoMiIDPJfjWMqH=CI&kO5N`v616T+`f|+o_fx&`-2`Ud#%Llw$gV78E z5CM=rHXw$HzZP%+OTg#?Fpq%&M#J=Z96t<_@#to`3sUOQdCKU( K1f@aF0RaHw6(uzQ literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..4ba92295c743de4abf8e1006bc3fcb8444ce7e96 GIT binary patch literal 8856 zcmeHNJ&V*(6up_rxFZWPf{36+#t&G~4K55i7AvUe6s|TRSO{T;1PyE^!{iO@7UFix zvMh+dz#rfbun~oAw6NR4%1%MVLaD!8md6vx)bi_mLwOU=uD+eGI4qoxAttXU%M$X};Y1)%v|Ne*f_K zsmjt9)|>!%Ppt98d&?LeLn;#+riwD43@8K2fHI&AC1KcCO0h|Ut0gJ$G;1a+X_wAd&abO;}4)7JH%d*C6;hb)&_t_w zJ`f(FWGyukMZKbkY)Ybp)lmIdBrMi5)9pcy-~UvFQ&1C2cf|* zA0$JwE}==*jD)r$@B44$B#P#M3Sj3Qpw9wMIFmpL0as_|9^iB4!HKK8h5*;X&Qg$1 z%u{d;ow#-CAV8bzZ`Ua(XE5keTpcy<%}G1JGQnYg&Q9>UxP%-AY%gfayP$lptb>E= RcNF$?-F#Ezjw_m~`vVDNdV~M~ literal 0 HcmV?d00001