;============================================================================	
;FileName       :DOS_SEG.ASM
;Function       :fasm example of writing multi-segment EXE program through HLL
;               :procedures
;Complier       :FASM   DOS_SEG.ASM     DOS_SEG.EXE
;Author		:Kenneth Zheng (Zheng Hongwen) 
;Date           :March 03th,2004 19:25:00 A.M. 
;Nationality	:China
;Notice		:None
;============================================================================
FORMAT		MZ
ENTRY 		main:start		; program entry point
STACK		100h			; stack size
;============================================================================
include         'private\dos.inc'
;============================================================================
segment main				; main program segment
  start:
  IF 0
        ;a>=4 && a<=6
        .if     eax>=4
                .if     eax<=6
                xor     eax,eax
                .endif
        .endif

        ;a>=4 || a<=6
        .if     eax>=4
                @@:
                xor     eax,eax
        .elseif eax<=6
                jmp     @b
        .endif
        ;x=(a<b)?4:6;
        mov     ebx,6
        cmp     eax,5
        cmovl   ebx,eax
END IF
        ;call    extra:dummy_proc
        ccall	test_proc,1234h
        mov	ax,'F'
        call    extra:write_char_f,cs,ax
        call    extra:write_text,text,hello
	mov	ax,4C00h
	int	21h
proc 	test_proc c uses eax ebx dx, \
		    test_para:WORD
        local test_local:WORD, hello1[10]:BYTE
	mov	ax,[test_para]
	mov	[test_local],ax
	mov	bx,[test_local]
	
	mov	al,[hello2]
	ret
endp	

hello2 db 'xxxx'
;============================================================================
segment text
  hello DB	0Dh,0Ah,09h,'Hello world! --Test HLL procedures on DOS platform'
        DB      0Dh,0Ah,09h,"Author:Kenneth Zheng Date:March 03th, 2004"
	DB	0Dh,0Ah,24h
;============================================================================	
segment extra
;----------------------------------------------------------------------------
proc_far write_text str_seg,str_offset
	local local_proc:WORD
	push	ds
	mov	ax,[str_seg]
	mov	ds,ax
	mov	dx,[str_offset]
	mov	ah,9h
	int	21h
	mov	ax,write_char_n
	mov	[local_proc],ax
	mov	ax,'N'
	call	[local_proc],ax
	pop	ds
	ret
endp		
;----------------------------------------------------------------------------
proc	write_char_n char
	push	ds
	pusha
	mov	ax,cs
	mov	ds,ax
	mov	ah,2
	mov	dx,[char]
	xor	dh,dh
	int	21h
	popa
	pop	ds
        ret
endp	
;----------------------------------------------------------------------------
proc_far write_char_f char_seg,char
	push	ds
	pusha
	mov	ax,[char_seg]
	mov	ds,ax
	mov	ah,2
	mov	dx,[char]
	xor	dh,dh
	int	21h
	popa
	pop	ds
	ret
endp	

proc_far dummy_proc
	local local_proc:WORD
	mov	ax,[local_proc]
	ret
endp
;============================================================================
