Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; a silly PID displaying program v0.06
- %macro newstr 2
- %strlen cnt%1 %2
- %1: db %2
- %endmacro
- %macro print 1
- mov eax, 4
- mov ebx, 1
- mov ecx, %1
- mov edx, cnt%1
- int 80h
- %endmacro
- %macro pidval 2
- mov eax,%1 ; get PID or PPID
- int 80h
- mov esi,%2+4 ; start here (pointer) esi is faster than ebx?
- call txtloop
- %endmacro
- section .data ; define constants...
- newstr pids,'pid: '
- pid: db 0,0,0,0,0
- cntpid: equ 5
- newstr ppids,'ppid: '
- ppid: db 0,0,0,0,0
- cntppid: equ 5
- tab: db 9
- cnttab: equ 1
- foot: db 10,0
- cntfoot: equ 2
- section .bss ; define variables
- section .foo ; this section can be an arbitrary name, but traditionally it's .text
- global _start ; this label must be defined...
- _start: ; this label must exist
- mov edi,10 ; for mod 10 later on
- pidval 20,pid
- pidval 64,ppid
- print pids
- print pid
- print tab
- print ppids
- print ppid
- print foot
- mov eax,1 ; exit
- mov ebx,0
- int 80h
- txtloop:
- cmp eax,0 ; is eax zero yet?
- jle .finish ; if it is jump outta here
- mov edx,0 ; assume remainder of zero
- div edi ; divide by edi and return the remainder (mod) (multiply is faster??)
- add edx,48 ; ascii text please (add 48 or 0x30) one byte per char... not unicode
- mov [esi],dl ; last character = this value we have just calculated
- dec esi ; decremement pointer by 1
- jmp txtloop
- .finish:
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement