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

Assembleur Discussion :

Allocation dynamique de mémoire en asm


Sujet :

Assembleur

  1. #1
    Membre expérimenté
    Avatar de narmataru
    Profil pro
    Inscrit en
    Décembre 2002
    Messages
    1 548
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Décembre 2002
    Messages : 1 548
    Points : 1 680
    Points
    1 680
    Par défaut Allocation dynamique de mémoire en asm
    Bonjour,
    Comme vous l'avez vu dans le sujet, j'aurais voulu savoir s'il était possible d'affecter dynamiquement de la mémoire en assembleur ?
    Peut-être existe-t-il une interruption système qui le permet ou ....
    merci...

  2. #2
    Membre éclairé
    Profil pro
    Inscrit en
    Juillet 2002
    Messages
    842
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2002
    Messages : 842
    Points : 696
    Points
    696
    Par défaut
    dépendant de l'os spécifie pour quel os dans ta question.

    Blustuff.

  3. #3
    Membre expérimenté
    Avatar de narmataru
    Profil pro
    Inscrit en
    Décembre 2002
    Messages
    1 548
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Décembre 2002
    Messages : 1 548
    Points : 1 680
    Points
    1 680
    Par défaut
    Dans un premier temps se serait pour windows 95.
    Pour linux j'ai vu qu'il y avait la librairie libasm, mais je ne comprend pas tout (et en plus je n'ai pas pris le temps ce qui n'arrange rien :c)

    Ou est-ce que je pourrais trouver de la doc sur la gestion de la mémoire en asm dans un environnment avec OS (ie avec gestion des processus et donc allocation de la mémoire par l'Os)

    Sinon, si je lance directement à partir du bios, je ne pense pas avoir besoin d'allocation de mémoire vu que j'y accède directement sans contrôle ?? vrai ???

    merci pour tout :c)

  4. #4
    Membre habitué

    Inscrit en
    Avril 2002
    Messages
    32
    Détails du profil
    Informations forums :
    Inscription : Avril 2002
    Messages : 32
    Points : 150
    Points
    150
    Par défaut
    Sous DOS on utilise 48h et 4Ah de l'interruption 21h...

  5. #5
    Membre éclairé
    Profil pro
    Inscrit en
    Juillet 2002
    Messages
    842
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2002
    Messages : 842
    Points : 696
    Points
    696
    Par défaut
    Pour windows, il faut appeller la fonction GlobalAlloc :

    The GlobalAlloc function allocates the specified number of bytes from the heap. In the linear Win32 API environment, there is no difference between the local heap and the global heap.

    HGLOBAL GlobalAlloc(

    UINT uFlags, // object allocation attributes
    DWORD dwBytes // number of bytes to allocate
    );


    Parameters

    uFlags

    Specifies how to allocate memory. If zero is specified, the default is GMEM_FIXED. Except for the incompatible combinations that are specifically noted, any combination of the following flags can be used. To indicate whether the function allocates fixed or movable memory, specify one of the first four flags:

    Flag Meaning
    GMEM_FIXED Allocates fixed memory. This flag cannot be combined with the GMEM_MOVEABLE or GMEM_DISCARDABLE flag. The return value is a pointer to the memory block. To access the memory, the calling process simply casts the return value to a pointer.
    GMEM_MOVEABLE Allocates movable memory. This flag cannot be combined with the GMEM_FIXED flag. The return value is the handle of the memory object. The handle is a 32-bit quantity that is private to the calling process. To translate the handle into a pointer, use the GlobalLock function.
    GPTR Combines the GMEM_FIXED and GMEM_ZEROINIT flags.
    GHND Combines the GMEM_MOVEABLE and GMEM_ZEROINIT flags.
    GMEM_DDESHARE Allocates memory to be used by the dynamic data exchange (DDE) functions for a DDE conversation. Unlike Windows version 3. x, this memory is not shared globally. However, this flag is available for compatibility purposes. It may be used by some applications to enhance the performance of DDE operations and should, therefore, be specified if the memory is to be used for DDE. Only processes that use DDE or the clipboard for interprocess communications should specify this flag.
    GMEM_DISCARDABLE Allocates discardable memory. This flag cannot be combined with the GMEM_FIXED flag. Some Win32-based applications may ignore this flag.
    GMEM_LOWER Ignored. This flag is provided only for compatibility with Windows version 3. x.
    GMEM_NOCOMPACT Does not compact or discard memory to satisfy the allocation request.
    GMEM_NODISCARD Does not discard memory to satisfy the allocation request.
    GMEM_NOT_BANKED Ignored. This flag is provided only for compatibility with Windows version 3. x.
    GMEM_NOTIFY Ignored. This flag is provided only for compatibility with Windows version 3. x.
    GMEM_SHARE Same as the GMEM_DDESHARE flag.
    GMEM_ZEROINIT Initializes memory contents to zero.


    dwBytes

    Specifies the number of bytes to allocate. If this parameter is zero and the uFlags parameter specifies the GMEM_MOVEABLE flag, the function returns a handle to a memory object that is marked as discarded.



    Return Values

    If the function succeeds, the return value is the handle of the newly allocated memory object.
    If the function fails, the return value is NULL. To get extended error information, call GetLastError.

    Remarks

    If the heap does not contain sufficient free space to satisfy the request, GlobalAlloc returns NULL.
    Because NULL is used to indicate an error, virtual address zero is never allocated. It is, therefore, easy to detect the use of a NULL pointer.
    All memory is created with execute access; no special function is required to execute dynamically generated code.
    Memory allocated with this function is guaranteed to be aligned on an 8-byte boundary.
    The GlobalAlloc and LocalAlloc functions are limited to a combined total of 65,536 handles for GMEM_MOVEABLE and LMEM_MOVEABLE memory per process. This limitation does not apply to GMEM_FIXED or LMEM_FIXED memory.

    If this function succeeds, it allocates at least the amount of memory requested. If the actual amount allocated is greater than the amount requested, the process can use the entire amount. To determine the actual number of bytes allocated, use the GlobalSize function.

    pour Dos Benoit t'as donné la réponse.


    Blustuff.

  6. #6
    Membre expérimenté
    Avatar de narmataru
    Profil pro
    Inscrit en
    Décembre 2002
    Messages
    1 548
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Décembre 2002
    Messages : 1 548
    Points : 1 680
    Points
    1 680
    Par défaut
    merci beaucoup :c)
    Le seul problème c'est que pour windows j'ai pas beaucoup de compétence...Il me semble que pour appeler la fonction que tu dis il faut que je fasse : invoke laFonction
    c'est bien ça ?[/b]

  7. #7
    Membre éclairé
    Profil pro
    Inscrit en
    Juillet 2002
    Messages
    842
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2002
    Messages : 842
    Points : 696
    Points
    696
    Par défaut
    oui en gros si tu veux appeller la fonction

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    a = GlobalAlloc(GMEM_FIXED, 1000);
    tu dois faire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    mov eax, 1000
    push eax
    push GMEM_FIXED
    call GlobalAlloc
    mov a, eax
    Ce qui reviens exactement au même que

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    invoke GlobalAlloc, GMEM_FIXED, 1000
    mov a, eax
    sauf que pour utiliser invoke, il faut définir un prototype. JE te le donen de tête mais je suis plus très sur :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    GlobalAlloc PROTO uFlags:DOWRD, dwBytes:DWORD
    tu dois placer cette déclaration de prototype avant tout utilisation de invoke pour la fonction GloballAlloc


    Blustuff.

  8. #8
    Membre expérimenté
    Avatar de narmataru
    Profil pro
    Inscrit en
    Décembre 2002
    Messages
    1 548
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Décembre 2002
    Messages : 1 548
    Points : 1 680
    Points
    1 680
    Par défaut
    ok, c'est noté :D merci beaucoup .....

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

Discussions similaires

  1. Allocation dynamique et mémoire virutelle
    Par mambo dans le forum Visual C++
    Réponses: 1
    Dernier message: 31/05/2007, 09h46
  2. probleme d'allocation dynamique de mémoire
    Par Blo0d4x3 dans le forum C
    Réponses: 2
    Dernier message: 13/03/2007, 07h53
  3. Allocation dynamique de mémoire : Limitations ?
    Par rulianf dans le forum C++
    Réponses: 5
    Dernier message: 22/03/2006, 17h03
  4. Allocation dynamique de mémoire
    Par cd090580 dans le forum Autres éditeurs
    Réponses: 7
    Dernier message: 12/11/2005, 11h17
  5. [VC++/ASM] Allocation dynamique de mémoire ?
    Par Magus (Dave) dans le forum x86 32-bits / 64-bits
    Réponses: 7
    Dernier message: 21/12/2004, 15h05

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