Advertisement
Guest User

Untitled

a guest
May 27th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Name split test
  2.  
  3. global  _main
  4. extern  _printf
  5. extern  _gets
  6. extern  _system
  7.  
  8. section .data
  9.     pause_str   db  'pause', 0
  10.     cls_str     db  'cls', 0
  11.     out_firstname   db  'Your first name is: %s', 10, 0
  12.     out_lastname    db  'Your last name is: %s', 10, 0
  13.     prompt      db  'What is your first and last name?', 10, '> ', 0
  14.  
  15. section .bss
  16.     input_buffer    resb 50 ; char input_buffer[50];
  17.     firstname   resd 1  ; char *firstname;
  18.     lastname    resd 1  ; char *lastname;
  19.  
  20. section .text
  21.  
  22. _splitNames:
  23.     mov ebx, [esp + 4];
  24.     loopstart:
  25.         cmp byte [ebx], 0
  26.         je  loopend
  27.         cmp byte [ebx], ' '
  28.         jne notspace
  29.             mov byte [ebx], 0
  30.             inc ebx
  31.             mov eax, ebx
  32.             mov ebx, dword [esp + 12]
  33.             mov dword [ebx], eax
  34.             jmp loopend
  35.         notspace:
  36.         inc ebx
  37.         jmp loopstart
  38.     loopend:
  39.     mov eax, dword [esp + 4]
  40.     mov ebx, dword [esp + 8]
  41.     mov dword [ebx], eax
  42.     ret
  43.        
  44.  
  45. _main:
  46.     push    prompt
  47.     call    _printf
  48.     add esp, 4
  49.    
  50.     push    input_buffer
  51.     call    _gets
  52.     add esp, 4
  53.    
  54.     push    lastname
  55.     push    firstname
  56.     push    input_buffer
  57.     call    _splitNames
  58.     add esp, 12
  59.    
  60.     push    dword [firstname]
  61.     push    out_firstname
  62.     call    _printf
  63.     add esp, 8
  64.    
  65.     push    dword [lastname]
  66.     push    out_lastname
  67.     call    _printf
  68.     add esp, 8
  69.    
  70.     push    pause_str
  71.     call    _system
  72.     add esp, 4
  73.  
  74.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement