📄 1.asm
字号:
stack Segment stack
dw 100 dup(?)
stack ends
data Segment
str DB 'WARNING :DIVIDE BY ZERO!',0AH,0DH,'$'
str0 DB 'the_cock_is',0AH,0DH,'$'
str1 DB 'the_rabbit_is',0AH,0DH,'$'
str2 DB 'the_cock_is',0AH,0DH,'$'
str3 DB 'the_rabbit_is',0AH,0DH,'$'
bufp db 0
buflen db 255
actlen db 0
buf db 255 DUP(13)
z dw 0
kk1 dw 1
head dw ?
foot dw ?
cock dw ?
rabbit dw ?
n dw ?
data ends
code Segment para
assume cs:code,ds:data,ss:stack
printf_int proc near
push AX
push SI
push DX
push CX
push BX
sub SI, SI
cmp AX, 8000H
jb printf_int_if_end
mov BX, AX
mov AH, 2
mov DL, 2DH
int 21H
mov AX, BX
neg AX
printf_int_if_end:
sub CX, CX
mov BX, 000AH
printf_int_while_start1:
cmp AX, 0000H
jna printf_int_while_end1
sub DX, DX
idiv BX
push DX
inc CX
jmp printf_int_while_start1
printf_int_while_end1:
cmp CX, 0000H
jnz printf_int_if_end2
sub DX, DX
push DX
inc CX
printf_int_if_end2:
mov AH, 2
printf_int_output:
pop DX
add DL, 30H
int 21H
loop printf_int_output
pop BX
pop CX
pop DX
pop SI
pop AX
ret
printf_int endp
scanf_int proc near
push BX
push CX
push DX
push DI
xor CX, CX
xor BX, BX
mov BL, bufp
mov CL, buf[BX]
scanf_int_while_cmp_start1:
cmp CL, 32
je scanf_int_while_start1
cmp CL, 9
je scanf_int_while_start1
cmp CL, 13
jne scanf_int_while_end1
scanf_int_while_start1:
cmp CL, 13
je scanf_int_if_end
inc BX
mov CL, buf[BX]
scanf_int_if_end:
scanf_int_while_start0:
cmp CL, 13
jne scanf_int_while_end0
call scanf_line
xor BX, BX
mov CL, buf[BX]
jmp scanf_int_while_start0
scanf_int_while_end0:
jmp scanf_int_while_cmp_start1
scanf_int_while_end1:
xor SI, SI
cmp CL, '-'
jne scanf_int_if_end1
inc SI
inc BX
mov CL, buf[BX]
cmp CL, 30H
jb scanf_int_if_start2
cmp CL, 39H
jna scanf_int_if_end2
scanf_int_if_start2:
dec BX
scanf_int_if_end2:
scanf_int_if_end1:
xor AX, AX
mov DI, 10
scanf_int_while_cmp_start2:
cmp CL, 30H
jb scanf_int_while_end2
cmp CL, 39H
ja scanf_int_while_end2
imul DI
sub CX, 30H
add AX, CX
inc BX
mov CL, buf[BX]
jmp scanf_int_while_cmp_start2
scanf_int_while_end2:
mov bufp, BL
cmp SI, 0
je scanf_int_if_end3
neg AX ; AX = -AX
scanf_int_if_end3:
pop DI
pop DX
pop CX
pop BX
ret
scanf_int endp
scanf_line proc near
push AX
push DX
lea DX, buflen
mov AH, 0AH
int 21H
mov AH, 2
mov DL, 10
int 21H
pop DX
pop AX
ret
scanf_line endp
main proc far
MOV AX, data
MOV DS, AX
MOV AX, stack
MOV SS, AX
PUSH BP
MOV BP, SP
MOV AX, z
MOV n, AX
call scanf_int
MOV head, AX
call scanf_int
MOV foot, AX
MOV AX, kk1
MOV cock, AX
L0:
MOV AX, cock
MOV BX, head
CMP AX, BX
JNS L2
MOV AX, head
MOV BX, cock
SUB AX, BX
PUSH AX
POP rabbit
MOV AX, cock
MOV BX, 2
IMUL BX
PUSH AX
MOV AX, rabbit
MOV BX, 4
IMUL BX
PUSH AX
POP AX
POP BX
ADD AX, BX
PUSH AX
POP AX
MOV BX, foot
CMP AX, BX
JNZ L4
mov ah ,9
mov dx ,offset str0
int 21h
MOV AX, cock
call printf_int
mov ah ,9
mov dx ,offset str1
int 21h
MOV AX, rabbit
call printf_int
MOV AX, n
MOV BX, 1
ADD AX, BX
PUSH AX
POP n
JMP L3
L4:
L3:
MOV AX, cock
MOV BX, 1
ADD AX, BX
PUSH AX
POP cock
JMP L0
L2:
MOV AX, n
MOV BX, 0
CMP AX, BX
JNZ L6
mov ah ,9
mov dx ,offset str2
int 21h
MOV AX, 0
call printf_int
mov ah ,9
mov dx ,offset str3
int 21h
MOV AX, 0
call printf_int
JMP L5
L6:
L5:
MOV SP, BP
POP BP
MOV AX, 4C00h
INT 21h
main endp
code ends
End main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -