Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. TITLE LAB4
  2. data segment  
  3. check db 'AYE BRAT'
  4. enteer db 10, 13, '$'
  5. firstNum db 'First operand x1: $'
  6. secondNum db 'Second operand x2: $'
  7. answer db 'The answer is : $'
  8. error db 'incorrect number$'
  9.  
  10. buff db 6,7 dup(?)
  11.  
  12. x1 dw ?
  13. x2 dw ?
  14.  
  15. a2 dw 4
  16. a3 dw 5
  17. b1 dw 1
  18. b3 dw 10
  19.  
  20. data ends  
  21.  
  22. code2 segment
  23.  
  24.  
  25.  
  26. assume cs:code2
  27.  
  28. ;--------------------------------------------------
  29. function proc far
  30.  
  31. lea dx,check
  32. mov ah, 09
  33. int 21h
  34.  
  35. pop cx
  36. pop bx
  37. pop ax
  38.  
  39. mul bx
  40.  
  41. push ax
  42.  
  43. mov ax,bx
  44. mul cx
  45. mov dx,ax
  46.  
  47. pop ax
  48.  
  49. add ax,dx
  50. add ax,cx
  51.  
  52. push ax
  53.  
  54. ret
  55. function endp
  56. ;---------------------------------------------------
  57. code2 ends
  58.  
  59.  
  60. ;---------------------------------------------------------------------------------------
  61.  
  62. code segment
  63.  
  64. assume cs:code,ds:data,es:code2
  65.  
  66. begin:
  67. mov ax, data
  68. mov ds, ax
  69. xor ax, ax
  70.  
  71. mov ax, code2
  72. mov es, ax
  73. xor ax, ax
  74.  
  75.  
  76. ;---------------------------------------
  77. ;first Num x1
  78. lea dx,firstNum
  79. mov ah, 09
  80. int 21h
  81.  
  82. call InputInt
  83. mov [x1],ax
  84.  
  85. xor ax,ax
  86.  
  87. ;second Num x2
  88.  
  89. lea dx,secondNum
  90. mov ah, 09
  91. int 21h
  92.  
  93. call InputInt
  94. mov [x2],ax
  95.  
  96. xor ax,ax
  97.  
  98. mov ax,[x1]
  99. mov bx,[a2]
  100. mov cx,[a3]
  101. push ax
  102. push bx
  103. push cx
  104. call far ptr function
  105.  
  106. mov di,ax
  107.  
  108. mov ax,[b1]
  109. mov bx,[x2]
  110. mov cx,[b3]
  111. push ax
  112. push bx
  113. push cx
  114. call far ptr function
  115.  
  116. sub ax,di
  117.  
  118. push ax
  119.  
  120. lea dx,answer
  121. mov ah, 09
  122. int 21h
  123.  
  124. pop ax
  125. call OutInt
  126.  
  127. lea dx,enteer
  128. mov ah, 09
  129. int 21h
  130. ;---------------------------------------EXIT   
  131.     mov ax, 4c00h
  132.     int 21h      
  133. ;---------------------------------------Proc:
  134. ;---------------------------------------Input
  135. InputInt proc
  136.  push bx
  137.  push cx
  138.  push dx
  139.  push di
  140.  push si
  141.  mov ah, 0Ah
  142.  xor di, di
  143.  lea dx, buff
  144.  int 21h
  145.  mov dl, 0Ah
  146.  mov ah, 02
  147.  int 21h
  148.  
  149.  xor ax,ax
  150.  mov bx,10
  151.  lea si, buff+2
  152. ii2:
  153.  mov cl, [si]
  154.  cmp cl, 0Dh ; 0Dh -- carriage return
  155.  jz endin ; if zero or equal
  156.  cmp cl, '0'
  157.  jb er ; if smaller
  158.  cmp cl, '9'
  159.  ja er ; if greater
  160.  sub cl, '0'
  161.  mul bx
  162.  add ax, cx
  163.  inc si
  164.  jmp ii2
  165. er:
  166.  lea dx, error
  167.  mov ah, 09
  168.  int 21h
  169.  int 20h
  170. endin:
  171.  pop si
  172.  pop di
  173.  
  174.  pop dx
  175.  pop cx
  176.  pop bx
  177.  ret
  178.  
  179. InputInt endp
  180.  
  181. ;----------------------------------------Output
  182.  
  183. OutInt proc
  184.  xor cx,cx
  185.  mov bx, 10
  186. oi2:
  187.  xor dx,dx
  188.  div bx
  189.  push dx
  190.  inc cx
  191.  test ax,ax
  192.  jnz oi2
  193.  
  194.  mov ah,02h
  195.  
  196. oi3:
  197.  pop dx
  198.  add dl, '0'
  199.  int 21h
  200.  loop oi3
  201.  ret
  202.  
  203. OutInt endp
  204. ;---------------------------------------------------
  205. code ends
  206. ;---------------------------------------------------
  207.  
  208. END begin
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement