Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global _start
- section .text
- ; function to print reversed text by dword
- ; text string should end in null
- ; ie 'e','l','p','m','a','x','e',0
- ; would print 'example'
- print:
- ; stores esp pointer for later
- push ebp
- mov ebp, esp
- ; sets eax to first char
- mov eax, esp
- add eax, 8
- ; sets ebx to end-of-string identifier, being 0/null/''
- mov ebx, ''
- ; loop through string, reversing it into the correct order
- mainloop:
- cmp [eax], ebx ; check if end-of-string
- je endloop ; if end of string, quit loop to endloop:
- ; push char and continue to next byte
- push dword [eax]
- add eax, 4
- jmp mainloop
- endloop:
- ; reset start of string
- mov edx, eax
- sub edx, esp
- sar edx, 1
- ; display string
- mov ecx, esp
- mov ebx, 1
- mov eax, 4
- int 0x80
- ; return to program
- mov esp, ebp
- pop ebp
- ret
- _start:
- push dword '' ; set end-of-string, being 0/null/''
- push dword 'H'
- push dword 'e'
- push dword 'l'
- push dword 'l'
- push dword 'o'
- call print ; call to print 'Hello'
- push dword '' ; set end-of-string, being 0/null/''
- push dword 10 ; new line
- push dword 'W'
- push dword 'o'
- push dword 'r'
- push dword 'l'
- push dword 'd'
- push dword '!'
- call print ; call to print newline + 'World!'
- mov eax, 1 ;system call number (sys_exit)
- int 0x80 ;call kernel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement