Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; strn (string const) macro is overloaded to take 1 or 2 args
- ; the address and optionally the number of chars to output
- ; (default 1)
- %macro strn 1
- mov eax, 4
- mov ebx, 1
- mov ecx, %1
- mov edx, 1
- int 0x80
- %endmacro
- %macro strn 2
- mov eax, 4
- mov ebx, 1
- mov ecx, %1
- mov edx, %2
- int 0x80
- %endmacro
- section .data
- nwln db 0xa ; newline
- abet db "abcdefghijklmnopqrstuvwxyz" ; alphabet
- ablen equ $ - abet ; alphabet len
- section .bss
- section .text
- global _start
- _start:
- sub esp, 32 ; grow stack by 32-bytes
- xor ecx, ecx ; zero ecx
- mov cl, ablen ; set count register to ablen
- mov esi, abet ; address of source in esi
- mov edi, esp ; address of dest in edi
- rep movsb ; copy string to stack at esp
- strn abet, ablen ; output string from abet
- strn nwln ; output newline
- strn esp, ablen ; output string from copy
- strn nwln ; output newline
- lea esi, [abet + 14] ; address of 15th, 'o' from abet
- strn esi ; output char
- strn nwln ; output newline
- lea esi, [esp + 14] ; address of 15th, 'o' from copy
- strn esi ; output char
- strn nwln ; output newline
- lea esi, [esp + ablen - 1] ; load addr of 'z' in esi
- prnchar: ; print from copy in reverse
- strn esi ; print char at esi
- dec esi ; decrement address
- cmp esi, esp ; compare to esp
- jge prnchar ; loop through esi == esp
- strn nwln ; output newline
- mov esi, esp ; load copy to esi
- eachchar: ; print every other char
- strn esi ; print char at esi
- inc esi ; increment address at esi
- mov al, 0 ; load 0 in al
- cmp al, byte[esi] ; compare byte
- je exit32 ; if end, jump to exit32
- inc esi ; skip to next char
- cmp al, byte[esi] ; compare byte
- jne eachchar ; repeat until nul-char reached
- exit32:
- strn nwln ; output newline
- add esp, 32 ; restore stack pointer address
- xor ebx, ebx ; set zero exit code
- mov eax, 1 ; syscall __NR_exit 1 (0x1 hex)
- int 0x80 ; call kernel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement