;[]-------------------------------------------------------------------------[]
;|	Program name: 2_3_2.ASM                                              |
;|	Image   file: 2_3_2.COM                                              |
;|	Note        : This is not a TSR program.                             |
;|                    It can show the memory informations.                   |
;|                    You can rename this program to MEMORY.ASM.             |
;[]-------------------------------------------------------------------------[]


cseg	segment				; program beginning
	assume	cs:cseg,ds:cseg
	org	100H
start:
	jmp	initialize

;------- Data area ---------------------

hextab	db	'0123456789ABCDEF'
msg1	db	'PSP SEGMENT ADDRESS : $'
msg2	db	'FREE   MEMORY  SIZE : $'
msg3	db	'TOTAL  MEMORY  SIZE : $'
msg4	db	' PARA.$'

;------- Macro area --------------------

print	macro	msg			; use dos function call to print msg
	mov	ah,09H
	lea	dx,msg
	int	21H
	endm

;------- Subroutine --------------------

dchar	proc	near			; display character
	mov	bh,1
	mov	ah,0EH
	int	10H
	ret
dchar	endp

dbyte	proc	near			; display byte
	push	ax
	shr	al,1
	shr	al,1
	shr	al,1
	shr	al,1
	and	ax,000FH
	mov	si,ax
	mov	al,cs:hextab[si]
	call	dchar
	pop	si
	and	si,000FH
	mov	al,cs:hextab[si]
	call	dchar
	ret
dbyte	endp

dsword	proc	near			; display short word
	push	ax
	mov	al,ah
	call	dbyte
	pop	ax
	call	dbyte
	ret
dsword	endp

dreturn	proc	near			; display return
	mov	al,0AH
	call	dchar
	mov	al,0DH
	call	dchar
	ret
dreturn	endp

;------ Main program -------------------

initialize:

	print	msg1			; display 'PSP SEGMENT ADDRESS'
	mov	ax,ds			; get PSP segment address
	call	dsword			; show PSP address in hex
	call	dreturn

	print	msg2			; display 'FREE MEMORY SIZE'
	mov	ax,es			; get PSP  segment address
	sub	ax,1			; get MCB2 segmemt address
	mov	es,ax			; let es point to the segment of MCB2
	mov	bx,3			; es:bx point to the 3rd byte of MCB2
	mov	ax,es:[bx]		; get the controlled size of MCB2
	call	dsword			; display the size value
	print	msg4			; display 'PARA'
	call	dreturn

	print	msg3			; display 'TOTAL MEMORY SIZE'
	mov	ax,ds			; get PSP segment address
	mov	bx,3			; es:bx point to the 3rd byte of MCB2
	add	ax,es:[bx]		; add the controlled size of MCB2
	call	dsword			; display total memory size
	print	msg4			; display 'PARA'
	call	dreturn

	int	20H

cseg	ends
	end	start

