Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; a silly PID displaying program v0.06 
  2.  
  3. %macro  newstr  2
  4.     %strlen cnt%1 %2
  5.     %1:     db %2
  6. %endmacro
  7.  
  8. %macro  print   1
  9.     mov eax, 4
  10.     mov ebx, 1
  11.     mov ecx, %1
  12.     mov edx, cnt%1
  13.     int 80h
  14. %endmacro
  15.  
  16. %macro  pidval  2
  17.     mov     eax,%1      ; get PID or PPID  
  18.     int     80h
  19.     mov esi,%2+4    ; start here (pointer) esi is faster than ebx?
  20.     call    txtloop
  21. %endmacro
  22.  
  23. section .data           ; define constants...
  24.     newstr  pids,'pid: '
  25.     pid:    db 0,0,0,0,0
  26.     cntpid: equ 5
  27.     newstr  ppids,'ppid: '
  28.     ppid:   db 0,0,0,0,0
  29.     cntppid: equ 5
  30.     tab:    db 9
  31.     cnttab: equ 1
  32.     foot:   db 10,0
  33.     cntfoot: equ 2
  34.  
  35. section .bss            ; define variables
  36.  
  37. section .foo            ; this section can be an arbitrary name, but traditionally it's .text
  38.     global _start       ; this label must be defined...
  39.  
  40. _start:             ; this label must exist
  41.     mov edi,10      ; for mod 10 later on  
  42.     pidval  20,pid     
  43.     pidval  64,ppid    
  44.     print   pids
  45.     print   pid
  46.     print   tab
  47.     print   ppids
  48.     print   ppid
  49.     print   foot
  50.     mov     eax,1       ; exit
  51.     mov     ebx,0  
  52.     int     80h
  53.  
  54. txtloop:
  55.     cmp     eax,0       ; is eax zero yet? 
  56.     jle .finish     ; if it is jump outta here
  57.     mov edx,0       ; assume remainder of zero
  58.     div edi     ; divide by edi and return the remainder (mod) (multiply is faster??)
  59.     add edx,48      ; ascii text please (add 48 or 0x30) one byte per char... not unicode
  60.     mov [esi],dl    ; last character = this value we have just calculated
  61.     dec esi     ; decremement pointer by 1
  62.     jmp txtloop
  63. .finish:
  64.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement