Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.                                   format MZ
  2.  
  3. entry     Main: Start
  4.  
  5.  
  6. segment Main
  7. Start:
  8.         call far   API: GetProccessedNum
  9.         mov        bx,dx
  10.         call far   API: GetProccessedNum
  11.         mov        cx, dx
  12.         call far   API: CalculateResult ;result in ax
  13.         mov        dx, ax
  14.         call far   API: OutputSoughtNumber
  15.  
  16.         retf
  17.  
  18.  
  19. segment API
  20.  
  21. CalculateResult:
  22.         mov      ax,bx
  23.         mov      si, 10
  24.         mul      si
  25.         mov      si, ax
  26.         mov      ax, cx
  27.         mul      ax
  28.         mov      cx, 6
  29.         mul      cx
  30.         xor       ax, si
  31.         retf
  32.  
  33. GetProccessedNum:  ; Result in DX
  34.         push     ax
  35.         mov      ax, WorkData
  36.         mov      ds, ax
  37.         mov      ah, 0ah
  38.         mov      dx, input
  39.         int      21h
  40.  
  41.         mov      dh, [input + 1]
  42.         mov      [realSize], dh
  43.         call     ProccessNum
  44.         call     SetNewLine
  45.         pop      ax
  46.         retf
  47.  
  48.  
  49. ProccessNum:    ; Result in DX
  50.         push    cx
  51.         push    bx
  52.         xor     dx, dx
  53.         mov     ax, 1
  54.         mov     ch, 10
  55.         movzx   si, [realSize]
  56.  
  57. LoopDigit:
  58.         xor     bx, bx
  59.         mov     bl, [input + si + 1]
  60.         sub     bl, '0'
  61.         mov     cl, al
  62.         mul     bl
  63.         add     dx, ax
  64.         mov     al, cl
  65.         mul     ch
  66.  
  67.         dec     si
  68.         test    si,si
  69.         jnz     LoopDigit
  70.  
  71.         pop     bx
  72.         pop     cx
  73.         ret
  74.  
  75. SetNewLine:
  76.         push     ax
  77.         push     dx
  78.         mov      ah, 09h
  79.         mov      dx, newLine
  80.         int      21h
  81.         pop      dx
  82.         pop      ax
  83.         ret
  84.  
  85.  
  86.  
  87. OutputSoughtNumber:        ;waits for dx
  88.         mov     ax, WorkData
  89.         mov     ds, ax
  90.         mov     [toOutput],dx
  91.         mov     bh, 10
  92.         xor     ax, ax
  93.         mov     ax, [toOutput]
  94.         test    ax, ax
  95.         jz      NumIsZero
  96.         mov     cx, 0
  97. DivideNum:
  98.         add     cx, 1
  99.         div     bh
  100.         xor     dx, dx
  101.         mov     dl, ah
  102.         push    dx
  103.         xor     ah, ah
  104.         test    ax, ax
  105.         jnz     DivideNum
  106.         jmp     OutputDigit
  107.  
  108. NumIsZero:
  109.         push    0
  110.         mov     cx, 1
  111.  
  112. OutputDigit:
  113.         pop     dx
  114.         add     dx, 30h
  115.         mov     ah, 02h
  116.         int     21h
  117.         loop    OutputDigit
  118.         call    WaitForClick
  119.         retf  ;OutputSoughtNumber ret
  120.  
  121. WaitForClick:
  122.         push     ax
  123.         mov      ah, 08h
  124.         int      21h
  125.         pop      ax
  126.         ret
  127.  
  128.  
  129.  
  130. Segment         WorkData
  131. input            db      4,5 dup(?)
  132. newLine          db      13,10,'$'
  133. realSize         db      ?
  134. toOutput         dw      ?
  135. X       dw      ?
  136. Y       dw      ?
  137. Z       dw      ?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement