fork download
  1. section .data
  2.  
  3. msg: db "The number of command line arguments is "
  4. len equ $ - msg ;length of our dear string
  5. char db 'character'
  6. charlen db $ - char
  7. ;
  8. SECTION .bss
  9. cline:resb 81 ;space to hold command line arguments for output for argc
  10. result:resb 20 ;space to hold command line arguments for output for argv[0]
  11. ;
  12.  
  13. section .text
  14. global main ;must be declared for using gcc
  15. ;
  16. main: ;tell linker entry point
  17. ;
  18. mov ecx,0 ;count output characters
  19. pop eax ;reject this 32 bits
  20. pop eax : ;get argc
  21. add al, 30H ;convert integer to ascii
  22. mov edi, cline ;put char in output buffer cline
  23. mov byte[edi],al ;move argc into edi memory address
  24. inc ecx ;increment char count
  25. inc edi ;increment pointer to o/p buffer
  26. mov al, 0aH ;LF to end line
  27. mov byte[edi],al ;put it at end of output line
  28. inc ecx ;increment output char count
  29.  
  30. pop eax ;get argv[0]
  31. cmp eax,0
  32. jz message
  33. add eax,0
  34. add al, 30H ;convert integer to ascii
  35. mov edi, result ;put char in output buffer result
  36. mov byte[edi],al ;move argv[0] into edi memory address
  37. inc ecx ;increment output char count
  38. inc edi ;increment pointer to o/p buffer
  39.  
  40. message:
  41. mov edx,len ;length of string to write
  42. mov ecx,msg ;addr of string
  43. mov ebx, 1 ;file descriptor 1 = stdout
  44. mov eax, 4 ;"write" system call
  45. int 0x80 ;call the kernel
  46. ;
  47.  
  48. pop edx ;restore char count into edx for system call
  49. mov ecx,cline ;address of string
  50. mov ebx, 1 ;file descriptor 1=stdout
  51. mov eax, 4 ;"write" system call
  52. int 0x80 ;call the kernel
  53.  
  54. ;
  55. mov edx,charlen ;length of string to write
  56. mov ecx,char ;addr of string
  57. mov ebx, 1 ;file descriptor 1 = stdout
  58. mov eax, 4 ;"write" system call
  59. int 0x80 ;call the kernel
  60. ;
  61. pop edx ;restore char count into edx for system call
  62. mov ecx,result ;address of string
  63. mov ebx, 1 ;file descriptor 1=stdout
  64. mov eax, 4 ;"write" system call
  65. int 0x80 ;call the kernel
  66. ;
  67.  
  68. mov ebx, 0 ;exit with error code 0
  69. mov eax, 1 ;"exit" system call
  70. int 0x80 ;call the kernel
Success #stdin #stdout 0s 5292KB
stdin
-0 database database.cpp
stdout
The number of command line arguments is