home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / memutil / memsiz.asm < prev    next >
Assembly Source File  |  1994-03-04  |  2KB  |  118 lines

  1. ;
  2. ;    Program to print amount of memory available.  Uses max-alloc
  3. ;    field in PSP and segment of PSP to determine amount of memory
  4. ;    free.
  5. ;
  6. ;    Note: this is a .com file.  To assemble a version, use:
  7. ;
  8. ;    masm memsiz;
  9. ;    link memsiz;
  10. ;    exe2bin memsiz.exe memsiz.com
  11. ;    del memsiz.exe
  12. ;
  13. dos    equ    21h        ;equates for system calls
  14. outc    equ    02h        ;output a character
  15. print    equ    09h        ;output a string
  16. term    equ    4c00h        ;termination (exit code = 0)
  17.  
  18. cr    equ    0dh        ;carrage-return
  19. lf    equ    0ah        ;line-feed
  20.  
  21. code    segment
  22.     assume cs:code, ds:code, es:code
  23.  
  24.     org    2h        ;place max segment located in psp
  25. maxseg    dw    ?        ;filled in by loader
  26.  
  27.     org    100h        ;place for com file
  28. main    proc    near
  29.  
  30.     mov    ax,maxseg    ;load max segment into ax
  31.     mov    bx,ds        ;load psp segment into bx
  32.     sub    ax,bx        ;find out available paragraphs
  33.     mov    bx,16        ;set to multiply by 16
  34.     mul    bx        ;I know, I know, a shift is faster...
  35. ;
  36. ;    number of bytes is in dx:ax.  Print this out and exit.
  37. ;
  38.     push    dx        ;save number
  39.     push    ax        ;
  40.     mov    dx,offset mesg    ;point to message
  41.     mov    ah,print    ;set to print it
  42.     int    21h        ;do it
  43.     pop    ax        ;restore number
  44.     pop    dx        ;
  45.     call    ltoa        ;output dx:ax to console
  46.     mov    dx,offset bmesg    ;point to second message
  47.     mov    ah,print    ;print it
  48.     int    dos        ;
  49.     mov    ax,term        ;and exit
  50.     int    dos        ;bye-bye
  51.  
  52. main    endp
  53.  
  54. ltoa    proc    near
  55.  
  56.     mov    bx,1000        ;set to split number
  57.     div    bx        ;divide number
  58.     push    dx        ;save remainder
  59.     call    itoa        ;output as integer
  60.     pop    ax        ;get second half
  61.     call    itoa        ;output it
  62.     ret            ;all done
  63.  
  64. ltoa    endp
  65.  
  66. ;
  67. ;    convert number in ax to decimal.  Number in ax is less
  68. ;    than one-thousand.
  69. ;
  70.  
  71. itoa    proc    near
  72.  
  73.     mov    bx,offset tens    ;point to powers of ten table
  74.     mov    cx,3        ;move count of characters to output
  75. zloop:
  76.     mov    dx,0        ;clear dx
  77.     div    word ptr [bx]    ;divide dx:ax by power of ten
  78.     push    dx        ;save remainder
  79.     call    decout        ;output decimal number
  80.     pop    ax        ;restore remainder to ax
  81.     inc    bx        ;point to next power of ten
  82.     inc    bx        ;
  83.     loop    zloop        ;loop until zero
  84.     ret            ;return
  85.  
  86. itoa    endp
  87.  
  88. ;
  89. ;    decout - output decimal in al to console
  90. ;
  91. decout    proc    near
  92.  
  93.     cmp    al,0        ;is it a zero?
  94.     jnz    ok        ;nope, output it
  95.     cmp    outzero,0    ;have we output something else?
  96.     jz    nope        ;no, suppress leading zeros
  97. ok:    inc    outzero        ;set output true
  98.     add    al,'0'        ;make a 00h a '0'
  99.     mov    dl,al        ;move to dl
  100.     mov    ah,outc        ;set to output character
  101.     int    dos        ;do it
  102. nope:    ret            ;return
  103.  
  104. decout    endp
  105.  
  106. mesg    db    'Available memory = $'
  107. bmesg    db    ' bytes', cr, lf, '$'
  108. outzero    db    0
  109.  
  110. tens    dw    100        ;power of tens table
  111.     dw    10        ;
  112.     dw    1
  113.  
  114.  
  115.  
  116. code    ends
  117.     end    main
  118.