x86 - intel and att syntax

This commit is contained in:
Win 2024-06-10 18:54:05 +07:00
parent 7e8d8fcf4c
commit fcfa860a9a
15 changed files with 104 additions and 2 deletions

View File

@ -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

Binary file not shown.

BIN
risc-v/main.o Normal file

Binary file not shown.

18
risc-v/main.s Normal file
View File

@ -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

BIN
x86/exit_project/exit Executable file

Binary file not shown.

BIN
x86/exit_project/exit.o Normal file

Binary file not shown.

10
x86/exit_project/exit.s Normal file
View File

@ -0,0 +1,10 @@
.section .data
.section .text
.globl _start
_start:
movl $1, %eax
movl $0, %ebx
int $0x80

BIN
x86/maximum/att/maximum Executable file

Binary file not shown.

BIN
x86/maximum/att/maximum.o Normal file

Binary file not shown.

38
x86/maximum/att/maximum.s Normal file
View File

@ -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

View File

@ -0,0 +1,3 @@
default:
as maximum.asm --32 -o maximum.o
gcc -o maximum.elf -m32 maximum.o -nostdlib

BIN
x86/maximum/intel/maximum Executable file

Binary file not shown.

View File

@ -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

BIN
x86/maximum/intel/maximum.elf Executable file

Binary file not shown.

BIN
x86/maximum/intel/maximum.o Normal file

Binary file not shown.