123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- %ifndef PRINT_NUMBER_ASM
- %define PRINT_NUMBER_ASM
- %include "syscalls.asm"
- section .bss align=8
- print_num_buf resb 64
- print_num_buf_end:
- section .text
- print_number:
- mov r8, 0b001
- call type_check
-
- ;; extract the number
- shr rax, 3
- ;; fill the buffer up with the decimal version of the number
- ;;; http://tptp.cc/mirrors/siyobik.info/instruction/CWD%252FCDQ%252FCQO.html
- mov rsi, print_num_buf_end
- mov rdi, 0
- mov rbx, 10
- ;; cqo
- .loop:
- mov rdx, 0
- idiv rbx ; rax=quotient, rdx=remainder
- dec rsi
- inc rdi
- add rdx, '0'
- mov byte [rsi],dl
-
- test rax, rax
- jnz .loop
- .done:
- mov rdx, rdi
- ;; print it
- mov rax, sys_write
- mov rdi, 1
- syscall
- ret
- %endif
|