x86 fasm
This commit is contained in:
parent
98a8fa09a9
commit
51f7f0e9b3
Binary file not shown.
|
@ -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
|
Binary file not shown.
|
@ -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
|
|
@ -0,0 +1,3 @@
|
||||||
|
default:
|
||||||
|
as minimum.asm --32 -o minimum.o
|
||||||
|
gcc -o minimum.elf -m32 minimum.o -nostdlib
|
|
@ -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
|
Binary file not shown.
Loading…
Reference in New Issue