Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. org 100h
  2.  
  3.        mov      cx, 10
  4. NumberGuess:
  5.        call     GetProccessedNum
  6.        call     CheckInput
  7.        cmp      bx, 0
  8.        jne      InputError
  9.        cmp      dl, [toGuess]
  10.        ja       SoughtLower
  11.        jb       SoughtBigger
  12.        je       Guessed
  13. InputError:
  14.        add      cx, 1
  15.  
  16. ReturnPoint:
  17.        dec      cx
  18.        jz       NotGuessed
  19.        jnz      NumberGuess
  20.  
  21. CheckInput:    ; if  no input error bx = 0, else bx = 1
  22.        mov      bx, 0
  23.        cmp      dx, 100
  24.        ja       @F
  25.        cmp      dx, 1
  26.        jb       @F
  27.        movzx    si, [realSize]
  28. CheckSymbol:
  29.        cmp      [input + si + 1], 30h
  30.        jb       @F
  31.        cmp      [input + si + 1], 39h
  32.        ja       @F
  33.        dec      si
  34.        test     si, si
  35.        jnz      CheckSymbol
  36.        jz       NoErrors
  37. @@:
  38.        mov      ah, 09h
  39.        mov      bx, dx
  40.        mov      dx, WrongInputCap
  41.        int      21h
  42.        call     SetNewLine
  43.        mov      dx, bx
  44.        mov      bx, 1
  45. NoErrors:
  46.  
  47.        ret
  48.  
  49. SoughtLower:
  50.        mov      ah, 09h
  51.        mov      dx, SoughtLowerCap
  52.        int      21h
  53.        call     SetNewLine
  54.        jmp      ReturnPoint
  55.  
  56. SoughtBigger:
  57.        mov      ah, 09h
  58.        mov      dx, SoughtBiggerCap
  59.        int      21h
  60.        call     SetNewLine
  61.        jmp      ReturnPoint
  62.  
  63. Guessed:
  64.        mov      ah, 09h
  65.        mov      dx, GuessedCap
  66.        int      21h
  67.        call     SetNewLine
  68.        jmp      WaitForClick
  69.  
  70. NotGuessed:
  71.        mov      ah, 09h
  72.        mov      dx, NotGuessedCap
  73.        int      21h
  74.        call     SetNewLine
  75.        call     OutputSoughtNumber
  76.        jmp      WaitForClick
  77.  
  78.  
  79. GetProccessedNum:  ; Result in DX
  80.         push     ax
  81.         mov      ah, 0ah
  82.         mov      dx, input
  83.         int      21h
  84.         mov      dh, [input + 1]
  85.         mov      [realSize], dh
  86.         call     ProccessNum
  87.         pop      ax
  88.         ret
  89.  
  90.  
  91. ProccessNum:    ; Result in DX
  92.         push    cx
  93.         push    bx
  94.         xor     dx, dx
  95.         mov     ax, 1
  96.         mov     ch, 10
  97.         movzx   si, [realSize]
  98.  
  99. LoopDigit:
  100.         xor     bx, bx
  101.         mov     bl, [input + si + 1]
  102.         sub     bl, '0'
  103.         mov     cl, al
  104.         mul     bl
  105.         add     dx, ax
  106.         mov     al, cl
  107.         mul     ch
  108.  
  109.         dec     si
  110.         test    si,si
  111.         jnz     LoopDigit
  112.  
  113.         pop     bx
  114.         pop     cx
  115.         ret
  116.  
  117.  
  118. OutputSoughtNumber:
  119.         mov     bh, 10
  120.         xor     ax, ax
  121.         mov     al, [toGuess]
  122.         test    al, al
  123.         jz      NumIsZero
  124.         mov     cx, 0
  125. DivideNum:
  126.         add     cx, 1
  127.         div     bh
  128.         xor     dx, dx
  129.         mov     dl, ah
  130.         push    dx
  131.         xor     ah, ah
  132.         test    ax, ax
  133.         jnz     DivideNum
  134.         jmp     OutputDigit
  135.  
  136. NumIsZero:
  137.         push    0
  138.         mov     cx, 1
  139.  
  140. OutputDigit:
  141.         pop     dx
  142.         add     dx, 30h
  143.         mov     ah, 02h
  144.         int     21h
  145.         loop    OutputDigit
  146.  
  147.         ret  ;OutputSoughtNumber ret
  148.  
  149. SetNewLine:
  150.         push     ax
  151.         mov      ah, 09h
  152.         mov      dx, newLine
  153.         int      21h
  154.         pop      ax
  155.         ret
  156.  
  157. WaitForClick:
  158.         push     ax
  159.         mov      ah, 08h
  160.         int      21h
  161.         pop      ax
  162.         ret
  163.  
  164.  
  165. input            db      4,5 dup(?)
  166. newLine          db      13,10,'$'
  167. realSize         db      ?
  168. toGuess          db      100
  169. SoughtLowerCap   db      'Sought number is Lower$'
  170. SoughtBiggerCap  db      'Sought number is Bigger$'
  171. GuessedCap       db      "You've just guessed the number!$"
  172. NotGuessedCap    db      "You haven't guessed. Tries are over :(",13,10,'Number: $'
  173. WrongInputCap    db      'Wrong input. Not considered as a try$'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement