From fcfa860a9afd7a6cca089e3cfbc78c1f7bc085b4 Mon Sep 17 00:00:00 2001 From: winsdominoes Date: Mon, 10 Jun 2024 18:54:05 +0700 Subject: [PATCH] x86 - intel and att syntax --- risc-v/Makefile | 4 ++-- risc-v/hello | Bin 1472 -> 0 bytes risc-v/main.o | Bin 0 -> 1280 bytes risc-v/main.s | 18 ++++++++++++++++ x86/exit_project/exit | Bin 0 -> 4696 bytes x86/exit_project/exit.o | Bin 0 -> 760 bytes x86/exit_project/exit.s | 10 +++++++++ x86/maximum/att/maximum | Bin 0 -> 9040 bytes x86/maximum/att/maximum.o | Bin 0 -> 1096 bytes x86/maximum/att/maximum.s | 38 ++++++++++++++++++++++++++++++++++ x86/maximum/intel/Makefile | 3 +++ x86/maximum/intel/maximum | Bin 0 -> 8708 bytes x86/maximum/intel/maximum.asm | 33 +++++++++++++++++++++++++++++ x86/maximum/intel/maximum.elf | Bin 0 -> 8856 bytes x86/maximum/intel/maximum.o | Bin 0 -> 772 bytes 15 files changed, 104 insertions(+), 2 deletions(-) delete mode 100755 risc-v/hello create mode 100644 risc-v/main.o create mode 100644 risc-v/main.s create mode 100755 x86/exit_project/exit create mode 100644 x86/exit_project/exit.o create mode 100644 x86/exit_project/exit.s create mode 100755 x86/maximum/att/maximum create mode 100644 x86/maximum/att/maximum.o create mode 100644 x86/maximum/att/maximum.s create mode 100644 x86/maximum/intel/Makefile create mode 100755 x86/maximum/intel/maximum create mode 100644 x86/maximum/intel/maximum.asm create mode 100755 x86/maximum/intel/maximum.elf create mode 100644 x86/maximum/intel/maximum.o diff --git a/risc-v/Makefile b/risc-v/Makefile index b0e47f4..2339473 100644 --- a/risc-v/Makefile +++ b/risc-v/Makefile @@ -1,4 +1,4 @@ default: rm -rf hello - riscv64-linux-gnu-as hello.s -o hello.o - riscv64-linux-gnu-gcc -o hello hello.s -nostdlib -static + riscv64-linux-gnu-as main.asm -o main.o + riscv64-linux-gnu-gcc -o main main.asm -nostdlib -static diff --git a/risc-v/hello b/risc-v/hello deleted file mode 100755 index f175cbe7c365b59f07339f0950c50ec80c1c80bb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1472 zcmbtUziSjh6n^(BIVD8`7K)9?6%uesj@%KuT)4d`$f=wnf-vl_Bn$hC-MM&Ls7)l; zC>&^Mqu7|jGG%HT|BSRE*81M=yxi@DwaJ5-@69*gd~OTT`c>U}9!_UXZKaM)1Pj7A<{OR5r*P&X|KjP0C@9&pdy#%%6 z`p;TRr|h=ldEvFkVeHu#JNJ=@-Nf31QV-Kwyw_fHo6)N9o6(9eDBEsEO<_}K5%KX#Euu5h9{!X4Wtt{kQsD44?AL0-@4Nm0>_(!fzbQi zG&hq(B+`f_@_CtK8`1#b1U7({JolwxBFZ?!UCx3~I@(S!)Xbsl**9GqH0g{aXlco6 zhLo{u4y8k7ea^Uw>*ukRl@He`-%q}Wyba$+9&4CTWy~pp>tR8a%Q6cU@;*$jVM1>Z zj~V&hD0+WbN88ML(%gaC|FuGTtLm!J{AKDeE?_%*+fb{>@2P6iDZ5i*sbKw)T2HUb Ibj+^*2Vm@;1^@s6 diff --git a/risc-v/main.o b/risc-v/main.o new file mode 100644 index 0000000000000000000000000000000000000000..3a9cc950ad4aed7bea2e54ee7e5b5adee5436110 GIT binary patch literal 1280 zcmb_a!AiqG5S=te+ly2bD(Intc#_aY@ti7(U=M-^JqRIfQyWQaNVYZh;z#rcJo*V9 z{UpI3a3;IkHrsg83A^*=&CKr3WM0qP7bQ&tDH?pk+>$K7XNlt#RCWe!s6ZKN2Ee9a zz_e^bg8UG@)ACz}FTEfb)^CS#(AxuOU7F&n5?7vjN8UP9(}P_vlpfkd$vxF+*b24>G?E|{Gp0W%vN(`797 zJ0s@Nu>FJ7@eKN#xwoNh<09GRYPQQdC9#8mI9n1@mpDj;P3O}+WnokQNDgojuTI)M zIZ@WRn(gZ39ioTMRP!Ha8F`@QH+gQ9j{=bSZN;JHlPyZkMSckDOK6&v3NE#N;?%cO a%DcGej*JCS@29yc%1_0k&K7bBs`)=nPhh_Q literal 0 HcmV?d00001 diff --git a/risc-v/main.s b/risc-v/main.s new file mode 100644 index 0000000..c9b8ade --- /dev/null +++ b/risc-v/main.s @@ -0,0 +1,18 @@ +.globl __start + +.data +msg: + .string "Hello World!" + .byte 0 +.text + +__start: + LA a0, msg + li a7, 4 + ecall + + j Shutdown + +Shutdown: + li a7, 10 + ecall diff --git a/x86/exit_project/exit b/x86/exit_project/exit new file mode 100755 index 0000000000000000000000000000000000000000..8627193fa1ce0791fa427ba852f31e98d17c0431 GIT binary patch literal 4696 zcmeHLy-LJD5T3;QQBa6rq1faJf`x^Zq){6YL99cL1Z~V6$qILsmcE8>A=vl=_P&7c z;ml^f^OOt1RTi_b`|bDb&d%=F?L3^EpN2s|XdxYwXHn{A;J8WMAcK?~gKe zwE-_g{M*I<9Q!2P>v0On<5q{h)1gzAjhZHFTwXiM$|83;LsbwZ&Fs$QBSu%Zc#Byz zc4cx?-6xZJJSl58qr{a{_v0cfl6{UFa_1NOhWY~P4yZ5aGNH}@p72Dx5#M~9*Ed=^ zuWRTs>Iq7HEOJ8=jI@3-RS~ra{{@Ox BFnRz0 literal 0 HcmV?d00001 diff --git a/x86/exit_project/exit.o b/x86/exit_project/exit.o new file mode 100644 index 0000000000000000000000000000000000000000..5bfb1c24c81d385e93d809a233cb8f1be1271d6c GIT binary patch literal 760 zcmbVIyKcfj5Zp825h(?9k!VOogHHJZa6@PiN|PEH#e#;1>_vhqd{RoJH2H!24<$SC zt*}Ic6WU1`x;N*BIiiqXh=7uRieu+rT9OOsYOjXWB3P!zZ1>}VNX~WPG%nz zk^4nW;exKZLuU}tZ&z(H&pFAM$mhp3Cku(36>+5*rw1ngnQ%gWk>}($TTcCQv-i7f zyGt`ZmT$T*?}i;4#vTX#Wa{>RU!;#(&CE@WR%!ixX|#m*`Um1|3L{||??Jqli<0B6 xGO&;JqJP36P(R)Wv+93FQ}8IXyQBV%L!k48D!!pPVn&h^B|rcG literal 0 HcmV?d00001 diff --git a/x86/exit_project/exit.s b/x86/exit_project/exit.s new file mode 100644 index 0000000..bb0eced --- /dev/null +++ b/x86/exit_project/exit.s @@ -0,0 +1,10 @@ +.section .data + +.section .text + +.globl _start +_start: + movl $1, %eax + movl $0, %ebx + + int $0x80 diff --git a/x86/maximum/att/maximum b/x86/maximum/att/maximum new file mode 100755 index 0000000000000000000000000000000000000000..c462d0a7da923294c92aa99715d43b1bdd3e2b1b GIT binary patch literal 9040 zcmeHNF>4e-6n=NPB#MQrMG$N@7B=c)A$nSbLs1LGCJ5=44Y$Mt_x8A*z@^cEjlssB zV`Q`hSwgoD|Auy!+rGcxt^R7MGWH z^Z}U|1IBX8(fH7bU7z6*Dfj3-X>qX}^KcM&apM4W|`tY3s*AJe2 z+1vm8=@ma)-|sTk#27FJi~(c77%&Em0b{@zFb0ePW55_N2L3w+7O>-6&~wlaP~NxS zgI{0etr(;{d@vk z>jZolnhPFZknY_4*N(u~j=-fVCWC6b%4+EsuE+Bb>mVA>Rz%XQOdFD#va|GFMKVWIi2x`dc}R36`N? z$cxrDXx)R>H^gDlItTSLbodT^jRisFKcN%ON9cu?v9odo4l$l9FZw>x;7;o@f;+8; zh_3f_?~2iO)8HKht{c zF_6N_K9#+Qy`9b^Gvu9=m(Z+)VZX2E2CI?S=YV(2vf)Sx$b;cMS3 z=%5rsto=xP#W1V@J-nb=(BO4ce5YL-LrR`y;SU{DTq|imi>#wA=VcWIMPKQlszK52 zpt5lcsvPP-<;s_;5`~o@(lzeP?tygk21^{@W)?E{r%#W1n)UZmV6a)giSZGHZR9<$FY`-S<`gD|O-I%jeNuCE?B`0C#{L>g4RNv&pgG4PY&H5jLzegbe literal 0 HcmV?d00001 diff --git a/x86/maximum/att/maximum.s b/x86/maximum/att/maximum.s new file mode 100644 index 0000000..13504c7 --- /dev/null +++ b/x86/maximum/att/maximum.s @@ -0,0 +1,38 @@ +# VARIABLES: The registers have the following uses: +# +# %edi - Holds the index of the data item being examined +# %ebx - Largest data item found +# %eax - Current data item +# +# The following memory locations are used: +# +# data_items - contains the item data. A 0 is used to terminate the data +# + +.section .data + +data_items: + .long 3, 67, 34, 222, 45, 75, 54, 34, 44, 33, 22, 11, 66, 0 + +.section .text + +.globl _start +_start: + movl $0, %edi + movl data_items(, %edi, 4), %eax + movl %eax, %ebx + +start_loop: + cmpl $0, %eax + je loop_exit + incl %edi + movl data_items(,%edi,4), %eax + cmpl %ebx, %eax + jle start_loop + + movl %eax, %ebx + jmp start_loop + +loop_exit: + movl $1, %eax + int $0x80 diff --git a/x86/maximum/intel/Makefile b/x86/maximum/intel/Makefile new file mode 100644 index 0000000..d9a879a --- /dev/null +++ b/x86/maximum/intel/Makefile @@ -0,0 +1,3 @@ +default: + as maximum.asm --32 -o maximum.o + gcc -o maximum.elf -m32 maximum.o -nostdlib diff --git a/x86/maximum/intel/maximum b/x86/maximum/intel/maximum new file mode 100755 index 0000000000000000000000000000000000000000..0bdbabcc92669f4cf377104d979615678f70b3ad GIT binary patch literal 8708 zcmeI2KT88a5XC3SsS#14hzLPAgN2|uQUnW2MJ*INu{?SXt^BA!TtdCs7_=(1RL9NcBKpc^mN+^3V`MsuyCOeQqf9rlt^6 z+)u=Q8E9pFLoT})rT63Z_3qPkqrI6QDOz`1NU13SC7=Y9fD%vwNXd*IPy$Lo2`B+2pahhF5>Nt4KnW;;e?lO$Sa>O} z&J|`S#|9RDd8hBm0N%a7eGIY&KMSJLj7%`#JwGfbX&Hwfit{<#(DUB@=X!>9Kl0*x z?YiIc9WU^u>KV_io0=bp>sErm4UE?`;?|geYg9#?;LtZ-1>Q6xzmr6beN%I`8!e~O zs_#{c^{P0g);8jVkK^D!S{`+M5Pyw?GYIf}kHk2GKyx7S3Fj8b0J966OGu0(5VSJH zI?gME?CfaXflFG_k2O3qv79Y(fCc9!_$=$#vp-(Lh1Rh}N^wlbKD1#dJTqL0bZwFO JIHpVLJ^^?LQV9S6 literal 0 HcmV?d00001 diff --git a/x86/maximum/intel/maximum.asm b/x86/maximum/intel/maximum.asm new file mode 100644 index 0000000..7571fbb --- /dev/null +++ b/x86/maximum/intel/maximum.asm @@ -0,0 +1,33 @@ +# edi = index of data_items +# ebx = largest data item found +# eax = current data item + +.global _start +.intel_syntax noprefix +.section .text + +_start: + mov edi, 0 # copy 0 into edi - first addresss + mov eax, [data_items + edi * 4] # move the first number (edi * 4) to eax + mov ebx, eax # move ebx to eax + jmp start_loop + +start_loop: + cmp eax, 0 # check if eax is 0, return value stored in EFLAGS register + je loop_exit # checks EFLAGS if cmp is equal + inc edi # move to the next number (increase index which is edi) + + mov eax, [data_items + edi * 4] # move the next number (edi * 4) to eax + cmp eax, ebx # compare largest item (ebx) to current item (eax) + jle start_loop # if eax is less than ebx - 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' into eax (exit syscall) + int 0x80 # call kernel interrupt to exit program + +.section .data + data_items: + .long 3, 67, 34, 222, 45, 75, 54, 34, 44, 33, 22, 11, 66, 0 diff --git a/x86/maximum/intel/maximum.elf b/x86/maximum/intel/maximum.elf new file mode 100755 index 0000000000000000000000000000000000000000..11292bb8cc995cc6c72a2ac1c9e1ccc429b61d12 GIT binary patch literal 8856 zcmeHNJ&V*(6up_rx+Bv>5D{!LqOhnNwpiS;5ma;pSHUl^3mFnLurnDZZ(tUdb-~8P zM*o37!NS63QLwSG6R{FRthNxl>DF^z<}JfwVXNE=C-*Zq$$4p#cOPF}z2ijVIna#_$+Yo7yl{lmTTx8Bhk40cAiLPzIC%Wk4BF29$ySf`PYuif8@~ zzr(lR@5+;jn4mKaT==s26T#g#{3`yq#ZnbzKp9X5lmTTx8Bhk40cAiLPzIC%Wk4DD z_ZZ+F`4!+K@D*4DZUE;2#<*|a0*(Pq;4<(h;U5AgzWmx_t=-?ZLEoMqa2~))-S#{^ z<1aBj^#knOpM~4TKM95d?Ch@`@Glzp4}5bj^Uv&=nZ4ORK2S=DGbLF`Gm$5oZ1w~N$;-IBGJeRt z(A~dvoKcAfJT9`;{q~LA)}MvlnL`Z{j>KfnPOYJ(0u&vGHqB)D#YW z*s2=wdsW;D`htAUdeKR{Zh{KDiTnQ2MR8cuCTtne++1`eNklgy6Y7h`m2SpSGmK5! zb@9Jn;5WgjmGZ54ug*9}n+JKY3uuR!;9YPXHN0P*gZIIlZ$~SGZ3fodeyhl-ce+O> z7}9MZ9|IX%r>