⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 yueshefu.txt

📁 一个汇编语言编写的程序
💻 TXT
字号:
;Yueshefu Program
;*********************
;define data segment
data segment
	 message1 db 'Please enter the number of the people:',10,13,'$'
	 message2 db 'Please enter the position who leaves the cicle:',10,13,'$'
message3 db 'The order of the people is:',10,13,'$'
	 total_number dw ?
	 position_number dw ?
	 leave_number dw ?
	
	 max dw 200
	
	 people_number dw 200 dup(?)
	 temp_number dw 200 dup(?)
	 flag dw 0
	 constant dw 10000,1000,100,10,1
data ends

;define code segment
code segment
;-----------------------
main proc far
	assume cs:code,ds:data
start:
	push ds
	sub ax,ax
	push ax
	
;set DS register to current data segment
	mov ax,data
	mov ds,ax
	
;main part of program goes here
	lea dx,message1
	mov ah,09h
	int 21h
	call decibin
	call crlf
	
	cmp bx,0
	jz exit
	
	cmp bx,max ;if N is larger than 200,exit
	jg exit
	
	mov total_number,bx
	
	;test the value
	mov leave_number,bx
	call print_number
	jmp exit
	
	lea dx,message2
	mov ah,09h
	int 21h
	call decibin
	call crlf
	
	cmp bx,0
	jz exit
	
	cmp bx,max
	jg exit
	
	mov position_number,bx
	
	;set value in people_number array
	mov cx,total_number
	mov ax,0
	mov si,ax
next:
	inc ax
	mov total_number[si],ax
	add si,2
	loop next
	;end of set value
	
	call yueshefu
	
exit:ret

main endp

yueshefu proc near
	
;agreeement :total_number=N,position_number=M,people_number,temp_number
	mov ax,total_number
	cmp ax,1
	je basic_event
	;if N>1 then
	mov cx,position_number
	dec cx
	
	mov si,0;the position of array
	mov ax,0;case if it arrive total_number
search:  ;search the position who should leave the circle
	inc ax
	add si,2
	cmp ax,total_number
	je clear
	jmp forward
clear:
	mov ax,0
	mov si,0
forward:
	loop search
	
	mov ax,people_number[si]
	mov leave_number,ax;get the leave position
	call print_number;//show the value
	
	;put the value of the people_number to temp_number
	mov cx,total_number
	mov si,0
copy:
	mov ax,people_number[si]
	mov temp_number[si],ax
	add si,2
	loop copy
	
	;change the value of array people_number
	dec total_number;total_number=total_number-1
	mov cx,total_number
	
	mov ax,leave_number
	mov di,ax;put the leave positon into di
	
	mov ax,0
	mov si,0
	
change:
	mov ax,total_number
	cmp di,ax
	je clear_di;if di =N,then make di=-2
	;else
	jmp go_forward
clear_di:
	mov di,-2
go_forward:
	mov ax,temp_number[si]
	add di,2
	mov people_number[di],2
	add di,2
	add si,2
	loop change
	jmp digui
	
basic_event:
	mov ax,total_number[0]
	mov leave_number,ax
	call print_number
	jmp exit_yueshefu
digui:
	;di gui use the sub_program : yue she fu 
	call yueshefu
exit_yueshefu:
	ret

yueshefu endp

decibin proc near
	
	mov bx,0
newchar:
	mov ah,1
	int 21h
	sub al,30h
	jl exit1
	cmp al,9d
	jg exit1
	cbw
	
	xchg ax,bx
	mov cx,10d
	mul cx
	xchg ax,bx
	add bx,ax
	
	jmp newchar
	
exit1:	
	ret
decibin endp

print_number proc near
	
	push bx
	push cx
	push si
	push di
	
	mov bx,leave_number
	mov flag,0
	mov cx,5
	lea si,constant
	
dec_div:
	mov ax,bx
	mov dx,0
	div word ptr[si]
	mov bx,dx
	mov dl,al
	
	cmp flag,0
	jnz print1;have not leading zero
	cmp dl,0
	je skip
	mov flag,1
print1:
	add dl,30h
	mov ah,02h
	int 21h
skip:
	add si,2
	loop dec_div
	pop di
	pop si
	pop cx
	pop bx
	ret
print_number endp

crlf proc near
	
	mov dl,0ah
	mov ah,02h
	int 21h
	
	mov dl,0dh
	mov ah,02h
	int 21h
	ret

crlf endp
code ends
	end start

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -