954,479 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

display the content of a file on the screen

Hello,

I want to display content of a file with the name has been entered by the user, but I have to enter the name of the file when I run the program (eg:. / myprogram test.asm). I would not have to specify the file name each time you run, but whether the user to do so when prompted for the name. I said that reading and viewing work properly. That's what I've done so far:

segment .data 
nom_fichier : db "Entrez le nom du fichier : ", 10
nom_fichier_len equ $-nom_fichier
 bufsize dw      1024

segment .bss
fichier        resb 32
 buf     resb    1024
;; Message qui demande à l'utilisateur d'entrer un nom de fichier
	mov eax, 4
	mov ebx, 1
	mov ecx, nom_fichier
	mov edx, nom_fichier_len
	int 0x80
	
	;; Lecture nom du fichier
	mov eax, 3
	mov ebx, 0
	mov ecx, fichier
	mov edx, 32
	int 0x80

  ; get the filename in ebx 
	pop   ebx
    pop   ebx               
    pop   ebx              
    pop   ebx    
	
  ; ouvrir le fichier - open
    mov   eax,  5           ; ouverture
    mov   ecx,  0           ;   lecture seulement
    int   80h               
  ; lire le fichier - read
    mov     eax,  3         ; lecture
    mov     ebx,  eax       ;   descripteur
    mov     ecx,  buf       ;   *buf,
    mov     edx,  bufsize   ;   *bufsize
    int     80h             

  ; afficher le contenu à l'écran- display
    mov     eax,  4         ; affiche à l'écran
    mov     ebx,  1         
    int     80h


Thanks

roud9
Newbie Poster
1 post since Apr 2011
Reputation Points: 10
Solved Threads: 0
 

Hi,
I think that your code is for a linux system. If I am right, you can read this:
http://board.flatassembler.net/topic.php?t=5361
It seems that at the program start the arguments are in the stack:
[esp] argc.
[esp + 4] argv[0]
[esp + 8] argv[1]
...
This, of course, if you program for 32 bits.

Bon courage.

untio
Light Poster
42 posts since Jan 2011
Reputation Points: 47
Solved Threads: 3
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: