home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / DIVERSEN / DOS32V3B / EXAMPLES / EG2.ASM < prev    next >
Assembly Source File  |  1995-02-12  |  2KB  |  98 lines

  1. ;***************************************************************************
  2. ; EG2.ASM
  3. ;             This program will allocated a memory block and fill it.
  4. ;
  5. ;***************************************************************************
  6.  
  7. .386
  8. .model flat
  9. .stack 200h
  10. .code
  11.  
  12.  
  13.  
  14. fill_message   db ' (hex) bytes allocated.  Now Filling block ...  ',10,13,36
  15.  
  16.  
  17.  
  18. TheStart:                                ; first intruction executed here
  19.  
  20. ;
  21. ; Use the Memory Allocation Service and attept to allocate 4GB
  22. ;
  23.         mov     edx,-1
  24.         mov     ax,0EE42h
  25.         int     31h                            ; Returns EAX with actual size
  26.         cmp     eax,0
  27.         jnz enfmem
  28.            mov  ah,4ch                         ; Terminate if size is 0
  29.            int  21h
  30. enfmem:
  31.  
  32. ; EDX now equals a near pointer of the memory block and
  33. ; EAX equals the number bytes that were allocated
  34.  
  35.  
  36.  
  37.  
  38. ;
  39. ; Print the amount of memory that was accualy allocated
  40. ;
  41.         push    eax
  42.         push    edx                             ; Save EDX.
  43.         call    print_hex                       ; Print EAX then
  44.         mov     edx,offset fill_message         ; print a message
  45.         mov     ah,9
  46.         int     21h
  47.         pop     edx                             ; restore EDX
  48.         pop     eax
  49.  
  50.  
  51. ;
  52. ; Fill the allocated memory block
  53. ;
  54.         mov     edi,edx                         ; EDX = offset
  55.         mov     ecx,eax                         ; EAX = count
  56.         shr     ecx,2
  57.         rep     stosd
  58.  
  59. ;
  60. ; Termiate the program
  61. ;
  62.         mov   ax,4c00h
  63.         int   21h
  64.  
  65.  
  66.  
  67.  
  68.  
  69. ;
  70. ; A procedure that will print EAX on the screen
  71. ;
  72. Print_hex   PROC
  73.         pushad
  74.         mov     digit,eax
  75.     mov     ecx,8
  76. L11:
  77.     rol     digit,4
  78.         mov     al,byte ptr digit
  79.         and     al,0fh
  80.         cmp     al,10
  81.     jb j8
  82.         add      al,'A'-'0'-10
  83. j8:     add     al,'0'
  84.         mov     dl,al
  85.         mov     ah,02h
  86.         int     21h
  87.         loop L11
  88.         popad
  89.         ret
  90.  
  91. digit   dd      0
  92.  
  93. print_hex ENDP
  94.  
  95.  
  96.  
  97. END TheStart
  98.