Advertisement
Guest User

evenOdd

a guest
Apr 19th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         org     100h
  2.  
  3. Welcome:
  4.         mov     ah, 09h
  5.         mov     dx, strWelcome
  6.         int     21h
  7.         call    NewLine
  8.  
  9.         movzx   eax, [number]
  10.         call    OPNum
  11.         mov     ah, 09h
  12.         test    [number], 0001h
  13.         jz      @Even
  14.         mov     dx, strOdd
  15.         int     21h
  16.         jmp     EchoWait
  17. @Even:
  18.         mov     dx, strEven
  19.         int     21h
  20.  
  21. EchoWait:
  22.         mov     ax, 0c08h       ;like "readln;" in delphi
  23.         int     21h
  24.         test    al,al
  25.         jnz     Skip
  26.         mov     ah, 08h
  27.         int     21h
  28. Skip:
  29.         ret
  30.  
  31.  
  32. ;================================================
  33. strWelcome      db      "Hello!$"
  34. strNewLine      db      $0a, $0d, "$"
  35. strEven         db      " is even$"
  36. strOdd          db      " is odd$"
  37. number          db      201
  38.  
  39. NewLine:
  40.         mov     ah, 09h
  41.         mov     dx, strNewLine
  42.         int     21h
  43. ret
  44.  
  45. OPNum:
  46.         push    si
  47.         push    bx
  48.         push    cx
  49.         cmp     eax,0
  50.         jns     .noneg
  51.         push    dx
  52.         push    ax
  53.         mov     ah, 02h
  54.         mov     dl, '-'
  55.         int     21h
  56.         pop     ax
  57.         pop     dx
  58.         neg     eax
  59.  
  60. .noneg:
  61.         mov     si, 0
  62.         mov     ebx, 10
  63. .Diving:
  64.         xor     edx, edx
  65.         div     ebx
  66.         push    dx
  67.         inc     si
  68.         cmp     eax, 0
  69.         jnz     .Diving
  70.  
  71.         mov     ah, 02h
  72.         mov     cx, si
  73. .OPa:
  74.         pop     dx
  75.         add     dl, 30h
  76.         int     21h
  77.         loop    .OPa
  78.  
  79.         pop     cx
  80.         pop     bx
  81.         pop     si
  82. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement