mclangc/a.nasm
2023-03-13 02:00:26 +02:00

68 lines
1.1 KiB
NASM

global _start
segment .text
print:
mov r9, -3689348814741910323
sub rsp, 40
mov BYTE [rsp+31], 10
lea rcx, [rsp+30]
.L2:
mov rax, rdi
lea r8, [rsp+32]
mul r9
mov rax, rdi
sub r8, rcx
shr rdx, 3
lea rsi, [rdx+rdx*4]
add rsi, rsi
sub rax, rsi
add eax, 48
mov BYTE [rcx], al
mov rax, rdi
mov rdi, rdx
mov rdx, rcx
sub rcx, 1
cmp rax, 9
ja .L2
lea rax, [rsp+32]
mov edi, 1
sub rdx, rax
xor eax, eax
lea rsi, [rsp+32+rdx]
mov rdx, r8
mov rax, 1
syscall
add rsp, 40
ret
_start:
; -- PUSH 35
mov rax, 35
push rax
; -- PUSH 34
mov rax, 34
push rax
; -- PLUS
pop rax
pop rbx
add rax, rbx
push rax
; -- PRINT
pop rdi
call print
; -- PUSH 500
mov rax, 500
push rax
; -- PUSH 80
mov rax, 80
push rax
; -- MINUS
pop rax
pop rbx
sub rbx, rax
push rbx
; -- PRINT
pop rdi
call print
mov rax, 60
mov rdi, 0
syscall