Advertisement
Guest User

Untitled

a guest
Nov 12th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. section .data
  2. str:    db "This is my ", 0
  3. stt:    db "test string", 0
  4.  
  5.  
  6. section .text
  7. global _start
  8.     _start: ;just a way to test functions
  9.     mov eax, str
  10.     call    _print
  11.     mov eax, stt
  12.     call    _println
  13.     call    _exit
  14.  
  15.  
  16.     _exit: ;clean program exit
  17.     mov eax, 1
  18.     mov ebx, 0
  19.     int 80h
  20.  
  21.  
  22.     _strlen: ;takes a string from the 'eax' register and returns the length of it in 'eax'
  23.     push    ebx
  24.     mov ebx, eax
  25.     __strlen:
  26.     cmp byte [ebx], 0
  27.     jz  ___strlen
  28.     inc ebx
  29.     jmp __strlen
  30.     ___strlen:
  31.     sub ebx, eax
  32.     mov eax, ebx
  33.     pop ebx
  34.     ret
  35.  
  36.    
  37.     _print: ;takes a string from the 'eax' register and prints to stdout
  38.     push    eax
  39.     push    ebx
  40.     push    ecx
  41.     push    edx
  42.     mov ecx, eax
  43.     call    _strlen
  44.     mov ebx, eax
  45.     mov edx, ebx
  46.     mov ebx, 1
  47.     mov eax, 4
  48.     int 80h
  49.     pop edx
  50.     pop ecx
  51.     pop ebx
  52.     pop eax
  53.     ret
  54.  
  55.  
  56.     _println: ;; print with newline
  57.     call    _print
  58.     push    eax
  59.     mov eax, 0ah
  60.     push    eax
  61.     mov eax, esp
  62.     call    _print
  63.     pop eax
  64.     pop eax
  65.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement