IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

x86 16-bits Assembleur Discussion :

Ecriture dans un fichier avec la fonction 40h de l'int 21h


Sujet :

x86 16-bits Assembleur

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 22
    Points : 18
    Points
    18
    Par défaut Ecriture dans un fichier avec la fonction 40h de l'int 21h
    Je craque ! Bonjours à tous...

    Décidément c'est pas évident pour moi d'écrire dans un fichier existant ! Certainement le fruit d'un manque de pratique ! Voilà :
    j'ai un fichier "titi.txt" et un buffer "mybuf". Je veux envoyer dans titi.txt mes données écrites dans le buffer buf
    (objectif suite à une acquisition de données par une carte hc11..) yo..
    et je m'enpatouille avec mon code d'inspiration billy microsauf :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
     
    .DATA
        mybuf BYTE 10 DUP (' ')
        pstring BYTE 0Dh,0Ah,"enter data: "
        ostring BYTE 0Dh,0Ah,"going to burn titi.txt "
      fic db "titi.txt",0
        abyte BYTE ?
    .CODE
        .STARTUP
        ; prompt user
        mov bx, 1  ; stdout
        mov cx, LENGTHOF pstring
        mov dx, SEG pstring
        mov ds, dx
        mov dx, OFFSET pstring
        mov ah, 40h
        INT 21h
            ; ignore possible errors
     
        ; read data
        mov bx, 0  ; stdin
        mov cx, LENGTHOF mybuf
        mov dx, SEG mybuf
        mov ds, dx
        mov dx, OFFSET mybuf
        mov ah, 3Fh
        INT 21h
            ; ignore possible errors
     
        mov bx, 1  ; stdout
        mov cx, LENGTHOF ostring
        mov dx, SEG ostring
        mov ds, dx
        mov dx, OFFSET ostring
        mov ah, 40h
        INT 21h
            ; ignore possible errors
     
        ;open
     
    mov ah,3dh
    mov al,1
    lea dx,fic ;ds:dx
    int 21h
     
        mov bx, OFFSET fic
        mov cx, LENGTHOF mybuf
        mov dx, SEG mybuf
        mov ds, dx
        mov dx, OFFSET mybuf
        mov ah, 40h
        INT 21h
     
     
    _fin :
    mov ah, 3eh          ; fermeture du fichier
    int 21h
     
    ; clear buffer
        mov bx, 0  ; stdin
        mov cx, 1
        mov dx, SEG abyte
        mov ds, dx
        mov dx, OFFSET abyte
        clearbuf: mov ah, 3Fh
        INT 21h
        mov al, abyte
        cmp al, 0Ah
        jne clearbuf
     
        .EXIT
    END
    Sauriez-vous m'aider à mettre de l'ordre là-dedans ?

  2. #2
    Futur Membre du Club
    Inscrit en
    Novembre 2008
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Novembre 2008
    Messages : 6
    Points : 6
    Points
    6
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    .DATA
        mybuf BYTE 10 DUP (' ')
        pstring BYTE 0Dh,0Ah,"enter data: "
        ostring BYTE 0Dh,0Ah,"going to burn titi.txt "
      fic db "titi.txt",0
        abyte BYTE ?
    .CODE
        .STARTUP
        ; prompt user
        mov bx, 1  ; stdout
        mov cx, LENGTHOF pstring
        mov dx, SEG pstring
        mov ds, dx
        mov dx, OFFSET pstring
        mov ah, 40h
        INT 21h
            ; ignore possible errors
     
        ; read data
        mov bx, 0  ; stdin
        mov cx, LENGTHOF mybuf
        mov dx, SEG mybuf
        mov ds, dx
        mov dx, OFFSET mybuf
        mov ah, 3Fh
        INT 21h
            ; ignore possible errors
     
        mov bx, 1  ; stdout
        mov cx, LENGTHOF ostring
        mov dx, SEG ostring
        mov ds, dx
        mov dx, OFFSET ostring
        mov ah, 40h
        INT 21h
            ; ignore possible errors
     
        ;open
     
    mov ah,3dh
    mov al,1
    lea dx,fic ;ds:dx
    int 21h
    ;////////////////////////////////////////////////////////////////
    ; le pobleme est dans cette partie//////////////////////////
        mov bx, OFFSET fic
        mov cx, LENGTHOF mybuf
        mov dx, SEG mybuf
        mov ds, dx
        mov dx, OFFSET mybuf
        mov ah, 40h
        INT 21h
    ;////////////////////////////////////////////////////////////////
     
     
    _fin :
    mov ah, 3eh          ; fermeture du fichier
    int 21h
     
    ; clear buffer
        mov bx, 0  ; stdin
        mov cx, 1
        mov dx, SEG abyte
        mov ds, dx
        mov dx, OFFSET abyte
        clearbuf: mov ah, 3Fh
        INT 21h
        mov al, abyte
        cmp al, 0Ah
        jne clearbuf
     
        .EXIT
    END
    Une fois le fichier ouvert, il fallait mettre le descripteur dans bx, donc pas mettre l'offset du fichier dans ax.
    Donc :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
        mov bx, ax
        mov cx, LENGTHOF mybuf
        mov dx, SEG mybuf
        mov ds, dx
        mov dx, OFFSET mybuf
        mov ah, 40h
        INT 21h

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 22
    Points : 18
    Points
    18
    Par défaut
    un grand merci a toi fog, ca marche... o poil !
    et dis moi , si je veut les donnees s'ecrivent a la suite a chaque fois que je lance cet exe, que me suggere tu ?
    c.a.d dans le fichier titi.txt,y'a deja qq chose et je veut que ca ecrive a la suite dedans... you get wath i mean ? (faut que je touche ax + qqchose )?

  4. #4
    Membre chevronné
    Avatar de Forthman
    Homme Profil pro
    conception mécanique
    Inscrit en
    Janvier 2005
    Messages
    702
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Tarn et Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : conception mécanique
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2005
    Messages : 702
    Points : 1 905
    Points
    1 905
    Par défaut
    Hello,

    Pour ça tu as la fonction 42h de l'int 21h (42h dans AH )
    qui permet de déplacer le pointeur de fichier

    a+ François

    (edit : le F de fichier )

  5. #5
    Membre à l'essai
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 22
    Points : 18
    Points
    18
    Par défaut [resolu]
    grand merci messieur , il ne me reste + qu'a fouiller...
    merci a tous...

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Ecrire dans un fichier avec une fonction itérative.
    Par katcha95 dans le forum Débuter
    Réponses: 6
    Dernier message: 22/11/2009, 18h40
  2. Ecriture dans un fichier avec une applet Java
    Par foued_scorpion dans le forum Applets
    Réponses: 1
    Dernier message: 25/10/2006, 11h30
  3. Ecriture dans un fichier avec diverses couleurs.
    Par molo2003 dans le forum MFC
    Réponses: 3
    Dernier message: 11/04/2006, 19h23
  4. Réponses: 20
    Dernier message: 25/09/2005, 15h07
  5. Ecriture dans un fichier avec la fonction AWK
    Par tux2005 dans le forum Linux
    Réponses: 2
    Dernier message: 21/07/2005, 10h58

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo