www.pudn.com > Demo_asm_80x86.rar > Joseph.asm


;****************************************************** 
;* 文件名:Joseph.asm 
;* 创建日期:2001.7.30 
;* 作者:陈文尧 
;* 功能:测试未来汇编队列库函数 
;* 备注:1.本程序是由本人大学时代的C++程序(约瑟夫环)改编 
;*      2.原来C++程序是用循环链表实现的,现在用队列模拟 
;*      3.本程序的问题描述如下: 
;*            N个人围坐一圈,每人持一密码(正整数)。开始 
;*        选一报数上限M(正整数),从第一人开始报数,到M时 
;*        停止。报M的人出列,把他的密码作为新的M值,从他 
;*        的下一个人开始从1报数,如此下去,直到全部出列 
;****************************************************** 
include system.inc 
include queue.inc 
;****************************************************** 
;* 以下代码由汇编专家产生,不要随便修改 
;****************************************************** 
.CODE 
	ifdef __COM__ 
		org	100h 
	endif 
@@Start: 
;------------------------------------------------------ 
; 初始化数据段 
;------------------------------------------------------ 
	InitDS	cs 
;------------------------------------------------------ 
; 释放多余内存 
;------------------------------------------------------ 
	ModifyMemory	;xxx 
;------------------------------------------------------ 
; 调用主函数 
;------------------------------------------------------ 
	call	main 
;------------------------------------------------------ 
; 正常返回DOS 
;------------------------------------------------------ 
@@Exit: 
	ReturnDos 
 
;++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
;+ 主函数,加入实现程序功能的代码 
;++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
main	proc 
	LibCall		CreateQueue,,04h 
	 
	DisplayMessage	msg1 
	LibCall		GetInteger 
	mov			bx,ax 
	 
	DisplayMessage	msg2 
	LibCall		GetInteger 
	mov			di,ax 
	 
	sub			si,si 
@Input: 
	inc			si 
	DisplayMessage	msg3 
	LibCall		PutInteger,si 
	DisplayMessage	msg4 
	LibCall		GetInteger 
	mov			node.password,ax 
	mov			node.sequence,si 
	LibCall		EnQueue,, 
	cmp			si,di 
	jb			@Input 
 
	DisplayMessage	msg5 
	 
@Next: 
	LibCall		DeQueue,, 
	dec			bx 
	jz			@Print 
	LibCall		EnQueue,, 
	jmp			@Next 
@Print: 
	mov			bx,node.password 
	LibCall		PutInteger,node.sequence 
	LibCall		QueueLength, 
	or			ax,ax 
	jz			short	@Return 
	LibCall		PutChar,',' 
	jmp			@Next 
	 
@Return: 
	;事实上到这里,队列已空,不调用ClearQueue也可以 
	LibCall		ClearQueue, 
	; 
	ret 
main	endp 
 
SNODE		struc 
		password	dw	? 
		sequence	dw	? 
		ends 
 
node		SNODE		?		 
ring		FQUEUE	<> 
msg1		db		'输入报数上限值:$' 
msg2		db		'输入人数:$' 
msg3		db		'输入第$' 
msg4		db		'人的密码:$' 
msg5		db		'出列循序如下:$' 
;****************************************************** 
;* 标志程序结束并指定程序入口 
;****************************************************** 
	end	@@Start