home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1993 May
/
SIMTEL_0593.ISO
/
msdos
/
memutil
/
memsiz.asm
< prev
next >
Wrap
Assembly Source File
|
1985-10-01
|
3KB
|
118 lines
;
; Program to print amount of memory available. Uses max-alloc
; field in PSP and segment of PSP to determine amount of memory
; free.
;
; Note: this is a .com file. To assemble a version, use:
;
; masm memsiz;
; link memsiz;
; exe2bin memsiz.exe memsiz.com
; del memsiz.exe
;
dos equ 21h ;equates for system calls
outc equ 02h ;output a character
print equ 09h ;output a string
term equ 4c00h ;termination (exit code = 0)
cr equ 0dh ;carrage-return
lf equ 0ah ;line-feed
code segment
assume cs:code, ds:code, es:code
org 2h ;place max segment located in psp
maxseg dw ? ;filled in by loader
org 100h ;place for com file
main proc near
mov ax,maxseg ;load max segment into ax
mov bx,ds ;load psp segment into bx
sub ax,bx ;find out available paragraphs
mov bx,16 ;set to multiply by 16
mul bx ;I know, I know, a shift is faster...
;
; number of bytes is in dx:ax. Print this out and exit.
;
push dx ;save number
push ax ;
mov dx,offset mesg ;point to message
mov ah,print ;set to print it
int 21h ;do it
pop ax ;restore number
pop dx ;
call ltoa ;output dx:ax to console
mov dx,offset bmesg ;point to second message
mov ah,print ;print it
int dos ;
mov ax,term ;and exit
int dos ;bye-bye
main endp
ltoa proc near
mov bx,1000 ;set to split number
div bx ;divide number
push dx ;save remainder
call itoa ;output as integer
pop ax ;get second half
call itoa ;output it
ret ;all done
ltoa endp
;
; convert number in ax to decimal. Number in ax is less
; than one-thousand.
;
itoa proc near
mov bx,offset tens ;point to powers of ten table
mov cx,3 ;move count of characters to output
zloop:
mov dx,0 ;clear dx
div word ptr [bx] ;divide dx:ax by power of ten
push dx ;save remainder
call decout ;output decimal number
pop ax ;restore remainder to ax
inc bx ;point to next power of ten
inc bx ;
loop zloop ;loop until zero
ret ;return
itoa endp
;
; decout - output decimal in al to console
;
decout proc near
cmp al,0 ;is it a zero?
jnz ok ;nope, output it
cmp outzero,0 ;have we output something else?
jz nope ;no, suppress leading zeros
ok: inc outzero ;set output true
add al,'0' ;make a 00h a '0'
mov dl,al ;move to dl
mov ah,outc ;set to output character
int dos ;do it
nope: ret ;return
decout endp
mesg db 'Available memory = $'
bmesg db ' bytes', cr, lf, '$'
outzero db 0
tens dw 100 ;power of tens table
dw 10 ;
dw 1
code ends
end main