IDEAL
MODEL small
STACK 100h
DATASEG
;---------------------
; your variables here
;---------------------
number db 169d
prompt db 13d,10d,'Please enter a valid number : $'
lessMsg db 13d,10d,'Value if Less ','$'
moreMsg db 13d,10d,'Value is More ', '$'
equalMsg db 13d,10d,'You have made fine Guess!', '$'
overflowMsg db 13d,10d,'Error - Number out of range!', '$'
retry db 13d,10d,'Retry [y/n] ? ' ,'$'
guess db 0d
errorChk db 0d
CODESEG
start:
mov ax,@data
mov ds, ax
;---------------------
;your code here
;---------------------
MOV ax, 0h
MOV bx, 0h
MOV cx, 0h
MOV dx, 0h
MOV BX, OFFSET guess
MOV [BX], 0d
MOV BX, OFFSET errorChk
MOV [BX], 0d
MOV ax, @data
MOV ds, ax
MOV dx, offset prompt
MOV ah, 9h
INT 21h
MOV cl, 0h
MOV dx, 0h
whil:
CMP cl, 5d
JG endwhile
MOV ah, 1h
INT 21h
CMP al, 0Dh
JE endwhile
SUB al, 30h
MOV dl, al
PUSH dx
INC cl
JMP whil
endwhile:
DEC cl
CMP cl, 02h
JG overflow
MOV BX, OFFSET errorChk
MOV [BX], cl
MOV cl, 0h
while2:
CMP cl,errorChk
JG endwhile2
POP dx
MOV ch, 0h
MOV al, 1d
MOV dh, 10d
while3:
CMP ch, cl
JGE endwhile3
MUL dh
INC ch
JMP while3
endwhile3:
MUL dl
JO overflow
MOV dl, al
ADD dl, guess
JC overflow
MOV BX, OFFSET guess
MOV [BX], dl
INC cl
JMP while2
endwhile2:
MOV ax, @data
MOV ds, ax
MOV dl, number
MOV dh, guess
CMP dh, dl
JC greater
JE equal
JG lower
equal:
MOV dx, offset equalMsg
MOV ah, 9h
INT 21h
JMP exit
greater:
MOV dx, offset moreMsg
MOV ah, 9h
INT 21h
JMP start
lower:
MOV dx, offset lessMsg
MOV ah, 9h
INT 21h
JMP start
overflow:
MOV dx, offset overflowMsg
MOV ah, 9h
INT 21h
JMP start
exit:
retry_while:
MOV dx, offset retry
MOV ah, 9h
INT 21h
MOV ah, 1h
INT 21h
CMP al, 6Eh
JE return_to_DOS
CMP al, 79h
JE restart
JMP retry_while
restart:
JMP start
return_to_DOS:
mov ax,4c00h
int 21h
end start
我谈到的标签是:whil,endwhile,while2,endwhile3,while3,endwhile2,equal,greater,lower,overflow,retry_while,