Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- section .data
- str: db "This is my ", 0
- stt: db "test string", 0
- section .text
- global _start
- _start: ;just a way to test functions
- mov eax, str
- call _print
- mov eax, stt
- call _println
- call _exit
- _exit: ;clean program exit
- mov eax, 1
- mov ebx, 0
- int 80h
- _strlen: ;takes a string from the 'eax' register and returns the length of it in 'eax'
- push ebx
- mov ebx, eax
- __strlen:
- cmp byte [ebx], 0
- jz ___strlen
- inc ebx
- jmp __strlen
- ___strlen:
- sub ebx, eax
- mov eax, ebx
- pop ebx
- ret
- _print: ;takes a string from the 'eax' register and prints to stdout
- push eax
- push ebx
- push ecx
- push edx
- mov ecx, eax
- call _strlen
- mov ebx, eax
- mov edx, ebx
- mov ebx, 1
- mov eax, 4
- int 80h
- pop edx
- pop ecx
- pop ebx
- pop eax
- ret
- _println: ;; print with newline
- call _print
- push eax
- mov eax, 0ah
- push eax
- mov eax, esp
- call _print
- pop eax
- pop eax
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement