카테고리

asm (27) bootloader_x86_grub (1) C (92) compile (11) config (76) CPP (13) CSS (1) debugging (7) gimp (1) Go (1) html (1) Java (1) JavaScript (1) kernel (19) LibreOffice (3) Linux system progamming (21) MFC (1) opencv (4) OpenGL (1) PHP (1) Python (4) qemu (29) shell (3) socket (7) troubleshooting (2) ubuntu18.04 (2) windows (1)

2018/12/28

asm 서브루틴

section .data
text db "Hello, World!",10,0
text2 db "World?",10,0

Section .text
global _start

_start:
mov rax, text
call _print

mov rax, text2
call _print

mov rax, 60
mov rdi, 0
syscall

;input: rax as pointer to string
;output: print string at rax
_print:
push rax
mov rbx, 0
_printLoop:
inc rax
inc rbx
mov cl,  [rax]
cmp cl, 0
jne _printLoop

mov rax, 1
mov rdi, 1
pop rsi
mov rdx, rbx
syscall

ret

; nasm -f elf64 05_SubRoutine.asm -o 05_SubRoutine.o
; ld 05_SubRoutine.o -o 05_SubRoutine
; ./05_SubRoutine

댓글 없음:

댓글 쓰기