Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- org 100h
- mov cx, 10
- NumberGuess:
- call GetProccessedNum
- call CheckInput
- cmp bx, 0
- jne InputError
- cmp dl, [toGuess]
- ja SoughtLower
- jb SoughtBigger
- je Guessed
- InputError:
- add cx, 1
- ReturnPoint:
- dec cx
- jz NotGuessed
- jnz NumberGuess
- CheckInput: ; if no input error bx = 0, else bx = 1
- mov bx, 0
- cmp dx, 100
- ja @F
- cmp dx, 1
- jb @F
- movzx si, [realSize]
- CheckSymbol:
- cmp [input + si + 1], 30h
- jb @F
- cmp [input + si + 1], 39h
- ja @F
- dec si
- test si, si
- jnz CheckSymbol
- jz NoErrors
- @@:
- mov ah, 09h
- mov bx, dx
- mov dx, WrongInputCap
- int 21h
- call SetNewLine
- mov dx, bx
- mov bx, 1
- NoErrors:
- ret
- SoughtLower:
- mov ah, 09h
- mov dx, SoughtLowerCap
- int 21h
- call SetNewLine
- jmp ReturnPoint
- SoughtBigger:
- mov ah, 09h
- mov dx, SoughtBiggerCap
- int 21h
- call SetNewLine
- jmp ReturnPoint
- Guessed:
- mov ah, 09h
- mov dx, GuessedCap
- int 21h
- call SetNewLine
- jmp WaitForClick
- NotGuessed:
- mov ah, 09h
- mov dx, NotGuessedCap
- int 21h
- call SetNewLine
- call OutputSoughtNumber
- jmp WaitForClick
- GetProccessedNum: ; Result in DX
- push ax
- mov ah, 0ah
- mov dx, input
- int 21h
- mov dh, [input + 1]
- mov [realSize], dh
- call ProccessNum
- pop ax
- ret
- ProccessNum: ; Result in DX
- push cx
- push bx
- xor dx, dx
- mov ax, 1
- mov ch, 10
- movzx si, [realSize]
- LoopDigit:
- xor bx, bx
- mov bl, [input + si + 1]
- sub bl, '0'
- mov cl, al
- mul bl
- add dx, ax
- mov al, cl
- mul ch
- dec si
- test si,si
- jnz LoopDigit
- pop bx
- pop cx
- ret
- OutputSoughtNumber:
- mov bh, 10
- xor ax, ax
- mov al, [toGuess]
- test al, al
- jz NumIsZero
- mov cx, 0
- DivideNum:
- add cx, 1
- div bh
- xor dx, dx
- mov dl, ah
- push dx
- xor ah, ah
- test ax, ax
- jnz DivideNum
- jmp OutputDigit
- NumIsZero:
- push 0
- mov cx, 1
- OutputDigit:
- pop dx
- add dx, 30h
- mov ah, 02h
- int 21h
- loop OutputDigit
- ret ;OutputSoughtNumber ret
- SetNewLine:
- push ax
- mov ah, 09h
- mov dx, newLine
- int 21h
- pop ax
- ret
- WaitForClick:
- push ax
- mov ah, 08h
- int 21h
- pop ax
- ret
- input db 4,5 dup(?)
- newLine db 13,10,'$'
- realSize db ?
- toGuess db 100
- SoughtLowerCap db 'Sought number is Lower$'
- SoughtBiggerCap db 'Sought number is Bigger$'
- GuessedCap db "You've just guessed the number!$"
- NotGuessedCap db "You haven't guessed. Tries are over :(",13,10,'Number: $'
- WrongInputCap db 'Wrong input. Not considered as a try$'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement