public class Link
{
public static final int LENGTH = 1000;
public static final int STEP = 12;
public static final int START_POS = 0;
public static Node[] node = new Node[LENGTH];
public static int counter = 0;
还记得上个学期的时候用汇编写的Josephus,贴来凑热闹^_^
;//////////////////////////////////////
; Josephu Puzzle
;/////////////////////////////////////
; N saved in DI
; M saved in SI
; S saved in CX,then dispose
;/////////////////////////////////////
.model small
.data
msg1 db 'Plz input N:','$'
msg2 db 'Plz input M:','$'
msg3 db 'Plz input S:','$'
msg4 db 'The sequence is :',13,10,'$'
msg5 db 'Continue(Y/N)?','$'
err_msg db 'Input illegal...Try again...',13,10,'$'
queue db 100 dup(0)
.code
;****************************************************
;----------------------------------------------------
main proc far
start:
mov ax,@data
mov ds,ax
rpt:
call init
call process
call output
lea dx,msg5
mov ah,1
int 21h
cmp al,'y
jz rpt
cmp al,'Y'
jz rpt
;return to DOS
mov ah,4ch
int 21h
main endp
;------------------------------------------------------
process proc near
process endp
;------------------------------------------------------
init proc near
in_N:
lea dx,msg1
call show_msg
sub dx,dx
call decibin
cmp dx,0fffh
jz err_N
cmp bx,0
jz err_N
cmp bx,101
ja err_N
mov di,bx
call crlf
jmp in_M
err_N:
lea dx,err_msg
call show_msg
jmp in_N
in_M:
lea dx,msg2
call show_msg
sub dx,dx
call decibin
cmp dx,0fffh
jz err_M
cmp bx,0
jz err_M
cmp bx,11
ja err_M
mov si,bx
call crlf
jmp in_S
err_M:
lea dx,err_msg
call show_msg
jmp in_M
in_S:
lea dx,msg3
call show_msg
sub dx,dx
call decibin
cmp dx,0fffh
jz err_S
cmp bx,0
jz err_S
cmp bx,di
ja err_S
mov cx,bx
call crlf
jmp exit_init
err_S:
lea dx,err_msg
call show_msg
jmp in_S
exit_init:
ret
init endp
;------------------------------------------------------
show_msg proc near
push ax
mov ah,9
int 21h
pop ax
ret
show_msg endp
;-------------------------------------------------------
crlf proc near
push dx
push ax
mov dl,13
mov ah,2
int 21h
mov dl,10
mov ah,2
int 21h
pop ax
pop dx
ret
crlf endp
;---------------------------------------------------------