;***************************************************************************
; EG2.ASM
;             This program will allocated a memory block and fill it.
;
;***************************************************************************

.386
.model flat
.stack 200h
.code



fill_message   db ' (hex) bytes allocated.  Now Filling block ...  ',10,13,36



TheStart:                                ; first intruction executed here

;
; Use the Memory Allocation Service and attept to allocate 4GB
;
        mov     edx,-1
        mov     ax,0EE42h
        int     31h                            ; Returns EAX with actual size
        cmp     eax,0
        jnz enfmem
           mov  ah,4ch                         ; Terminate if size is 0
           int  21h
enfmem:

; EDX now equals a near pointer of the memory block and
; EAX equals the number bytes that were allocated




;
; Print the amount of memory that was accualy allocated
;
        push    eax
        push    edx                             ; Save EDX.
        call    print_hex                       ; Print EAX then
        mov     edx,offset fill_message         ; print a message
        mov     ah,9
        int     21h
        pop     edx                             ; restore EDX
        pop     eax


;
; Fill the allocated memory block
;
        mov     edi,edx                         ; EDX = offset
        mov     ecx,eax                         ; EAX = count
        shr     ecx,2
        rep     stosd

;
; Termiate the program
;
        mov   ax,4c00h
        int   21h





;
; A procedure that will print EAX on the screen
;
Print_hex   PROC
        pushad
        mov     digit,eax
	mov     ecx,8
L11:
	rol     digit,4
        mov     al,byte ptr digit
        and     al,0fh
        cmp     al,10
	jb j8
        add      al,'A'-'0'-10
j8:     add     al,'0'
        mov     dl,al
        mov     ah,02h
        int     21h
        loop L11
        popad
        ret

digit   dd      0

print_hex ENDP



END TheStart
