xiranda/test.asm

112 lines
3.4 KiB
NASM
Raw Normal View History

2024-03-31 22:58:48 -04:00
linux_read_system_call = 0
linux_write_system_call = 1
linux_open_system_call = 2
linux_close_system_call = 3
linux_exit_system_call = 60
standard_input = 0
standard_output = 1
format ELF64 executable 3
segment readable executable
main:
mov [echo_0], text_data ; text);
call echo ; echo (
loop_1:
cmp [main_x], 51
jnb loop_1e
xor rdx, rdx
mov eax, [main_x]
mov ebx, 15
idiv rbx
cmp edx, 0
jne n3
mov [echo_0], fb
call echo
jmp n0
n3:
xor rdx, rdx
mov eax, [main_x]
mov ebx, 3
idiv rbx
cmp edx, 0
jne n1
mov [echo_0], f
call echo
jmp n0
n1:
xor rdx, rdx
mov eax, [main_x]
mov ebx, 5
idiv rbx
cmp edx, 0
jne n2
mov [echo_0], b
call echo
jmp n0
n2:
mov [echo_0], n
call echo
n0:
inc [main_x]
jmp loop_1
loop_1e:
;
mov rax, linux_exit_system_call ; <main> return;;
xor rdi, rdi
syscall
;~string_length (character * text):
;~natural length = 0;
;~loop (* (text + length++));
;~return (length);;
string_length: ; string_length
mov [string_length_length], 0 ; length = 0;
mov rax, [string_length_0] ; text
loop_0: ; loop_0
cmp byte [rax], 0 ; (* (text + length)) != '\0'
je loop_0e
inc rax ; text + length
inc [string_length_length] ; length++
jmp loop_0 ; if not go loop_0
loop_0e:
xor rax, rax
mov eax, [string_length_length] ; return (length);
ret ; ;
;~echo (character * text):
;~system (linux_write_system_call, standard_output, text, string_length (text));
;~return;;
echo: ; echo )
mov rax, [echo_0] ; |
mov [string_length_0], rax ; |
call string_length ; |
mov rdx, rax ; | string_length (text)
mov rsi, [echo_0] ; text
mov rdi, standard_output ; standard_output
mov rax, linux_write_system_call ; linux_write_system_call
syscall ; system (
xor rax, rax ; return;;
ret ;
segment readable writable
; variable
string_length_length dd 0 ; natural length = 0;
main_x dd 1 ; integer x = 0;
; function
echo_0 dq 0 ; character * text
string_length_0 dq 0 ; character * text
; data
text_data db 'Heyo world!', 10, 0
fb db 'fizzbuzz', 10, 0
f db 'fizz', 10, 0
b db 'buzz', 10, 0
n db 'number', 10, 0