Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 25th, 2012  |  syntax: None  |  size: 1.33 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. NASM segmentation fault problem
  2. %include "macros.inc"
  3.         section .data
  4. prompt1     db "Enter string: ",0
  5. prompt1len  equ $-prompt1
  6. prompt2     db "The size of string is: ",0
  7. prompt2len  equ $-prompt2
  8.  
  9.         section .bss
  10. string      resb 20
  11.         section .text
  12.             global _start
  13. _start:     str_output prompt1len,prompt1
  14.             str_input string
  15.             mov ebx,string
  16.             call func
  17.             str_output prompt2len,prompt2
  18.             output eax
  19.             exit 0
  20.  
  21. func:
  22.             xor eax,eax
  23. et        **cmp byte [ebx],0h**
  24.             je end
  25.             inc eax
  26.             inc ebx
  27.             jmp et
  28. end         dec eax
  29.             ret
  30.        
  31. %macro exit 1
  32.         mov eax,1
  33.         mov ebx,%1
  34.         int 80h
  35. %endmacro
  36.  
  37. %macro int_input 1
  38.         mov eax,3
  39.         mov ebx,0
  40.         mov ecx,%1
  41.         mov edx,1
  42.         int 80h
  43.         and eax,0Fh
  44.         mov %1,eax
  45. %endmacro
  46.  
  47. %macro str_input 1
  48.         mov eax,3
  49.         mov ebx,1
  50.         mov ecx,%1
  51.         mov edx,20
  52.         int 80h
  53. %    endmacro
  54.  
  55. %macro output 1
  56.         mov eax,%1
  57.         or eax,30h
  58.         mov %1,eax
  59.         mov eax,4
  60.         mov ebx,1
  61.         mov ecx,%1
  62.         mov edx,1
  63.         int 80h
  64. %endmacro
  65.  
  66. %macro str_output 2+
  67.         mov eax,4
  68.         mov ebx,1
  69.         mov ecx,%2
  70.         mov edx,%1
  71.         int 80h
  72. %endmacro
  73.        
  74. mov ebx, offset string