home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0000 - 0009 / ibm0000-0009 / ibm0003.tar / ibm0003 / SRCR215.ZIP / SAMPLE.ASM < prev    next >
Encoding:
Assembly Source File  |  1988-05-25  |  2.0 KB  |  89 lines

  1. cseg    segment para public 'code'
  2. org    100h
  3.  
  4.     ; This program is used to display the total and available memory.
  5.     ; To generate this program, use the following:
  6.     ;    MASM SAMPLE;
  7.     ;    LINK SAMPLE,SAMPLE,SAMPLE/M;
  8.     ;    EXE2BIN SAMPLE.EXE SAMPLE.COM
  9.     ;    DEL SAMPLE.OBJ
  10.     ;    DEL SAMPLE.EXE
  11.  
  12. sample    proc far
  13.  
  14.     assume cs:cseg,ds:cseg,ss:nothing,es:nothing
  15.  
  16.     jmp short start     ; go to the start
  17.  
  18. public    sample, total, tmemory, avail, amemory, totmem, fremem, start, dosret
  19. public    getmem, convert, conloop, display
  20.  
  21. total    db 'Total memory: '
  22. tmemory db '000 KB    '
  23. avail    db 'Memory available: '
  24. amemory db '000 KB','$'
  25. totmem    dw 0            ; total memory size
  26. fremem    dw 0            ; free memory size
  27.  
  28. start:    call getmem        ; get memory size
  29.  
  30.     mov ax,totmem        ; total memory
  31.     mov di,offset tmemory
  32.     call convert        ; convert to ascii
  33.  
  34.     mov ax,fremem        ; free (available) memory
  35.     mov di,offset amemory
  36.     call convert        ; convert to ascii
  37.  
  38.     call display        ; display the answers
  39.  
  40. dosret: int 20h         ; return to dos
  41.  
  42. getmem    proc near        ; get memory size
  43.     mov cl,6        ; shift count
  44.     mov si,2        ; point to top of memory in psp
  45.     mov ax,[si]        ; get top of memory
  46.  
  47.     shr ax,cl        ; convert to KB
  48.     mov totmem,ax        ; and save total memory
  49.  
  50.     mov bx,cs        ; get current segment
  51.     shr bx,cl        ; convert to KB
  52.     sub ax,bx        ; subtract from total memory to get
  53.     mov fremem,ax        ; free memory
  54.     ret
  55. getmem    endp
  56.  
  57. convert proc near        ; convert number to ascii
  58.     ; ax = number, di = output buffer pointer
  59.     push ax         ; save number
  60.     mov al,' '
  61.     mov cx,3
  62.     rep stosb        ; clear 3 bytes
  63.     pop ax            ; restore number
  64.  
  65.     mov cx,10        ; divisor
  66.  
  67. conloop:xor dx,dx        ; clear remainder
  68.     div cx            ; divide by 10
  69.     add dl,30h        ; convert to ascii
  70.     dec di            ; back up 1 byte
  71.     mov [di],dl        ; save ascii number
  72.  
  73.     cmp ax,0        ; done?
  74.     jnz conloop        ; no
  75.  
  76.     ret
  77. convert endp
  78.  
  79. display proc near        ; display memory sizes
  80.     mov ah,9        ; display string
  81.     mov dx,offset total    ; start of message
  82.     int 21h         ; let dos display it
  83.     ret
  84. display endp
  85.  
  86. sample    endp
  87. cseg    ends
  88. end    sample
  89.