[net.micro.pc] Small program to print available memory

bmarsh@noscvax.UUCP (William C. Marsh) (09/30/85)

*** REPLACE THIS LINE WITH YOUR CUTE ASSEMBLY PROGRAM ***

Here is a simple assembly program that prints the amount of free
memory in your ms-dos machine.  Follow the rules in the comment
section of the assembly program to make memsiz.com.  Cut at the
dashed line and feed to sh (not csh).

Bill Marsh
bmarsh@nosc
----------------------cut here-----------------------------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	memsiz.asm
# This archive created: Mon Sep 30 11:07:50 1985
export PATH; PATH=/bin:$PATH
if test -f 'memsiz.asm'
then
	echo shar: will not over-write existing file "'memsiz.asm'"
else
cat << \SHAR_EOF > 'memsiz.asm'
;
;	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
SHAR_EOF
fi # end of overwriting check
#	End of shell archive
exit 0
-- 

Bill Marsh, Naval Ocean Systems Center, San Diego, CA
{arpa,mil}net: bmarsh@nosc
uucp: {ihnp4,akgua,decvax,dcdwest,ucbvax}!sdcsvax!noscvax!bmarsh

"If everything seems to be coming your way, you're probably in the wrong lane."