Advertisement
qberik

Untitled

Dec 26th, 2022
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. .model small
  2. .stack 100h
  3.  
  4. ; МАКСРОСЫ ИЗ МЕТОДИЧКИ
  5. ;------------------------------макрос ввода значений
  6. mReadAX MACRO buf, sz
  7. local input, startOfConvert, endofConvert
  8. push bx
  9. push cx
  10. push dx
  11.  
  12. input:
  13. mov [buf], sz
  14. mov dx, offset [buf]
  15. mov ah, 0ah
  16. int 21h
  17.  
  18. mov ah, 02h
  19. mov dl, 0Dh
  20. int 21h
  21.  
  22. mov ah, 02h
  23. mov dl, 0Ah
  24. int 21h
  25.  
  26. xor ah, ah
  27. cmp ah, [buf][1]
  28. jz input
  29.  
  30. xor cx, cx
  31. mov cl, [buf][1]
  32.  
  33. xor ax, ax
  34. xor bx, bx
  35. xor dx, dx
  36. mov bx, offset [buf][2]
  37.  
  38. cmp [buf][2], "-"
  39. jne startOfConvert
  40. inc bx
  41. dec cl
  42.  
  43. startOfConvert:
  44. mov dx, 10
  45. mul dx
  46. cmp ax, 8000h
  47. jae input
  48.  
  49. mov dl, [bx]
  50. sub dl, "0"
  51.  
  52. add ax, dx
  53. cmp ax, 8000h
  54. jae input
  55.  
  56. inc bx
  57. loop startOfConvert
  58.  
  59. cmp [buf][2], "-"
  60. jne endofConvert
  61. neg ax
  62.  
  63. endofConvert:
  64. pop dx
  65. pop cx
  66. pop bx
  67.  
  68. endm mReadAX
  69.  
  70.  
  71.  
  72. ;------------------------------макрос вывода сообщений на экран
  73. Print MACRO str
  74. push ax
  75. push dx
  76.  
  77. mov ah, 09h
  78. mov dx, offset str
  79. int 21h
  80.  
  81. pop dx
  82. pop ax
  83. ENDM Print
  84.  
  85. ;------------------------------макрос вывода результата
  86. mWriteAx macro
  87. local convert, write
  88. push ax
  89. push bx
  90. push cx
  91. push dx
  92. push di
  93.  
  94. mov cx, 10
  95. xor di, di
  96.  
  97. or ax, ax
  98. jns convert
  99.  
  100. push ax
  101. mov dx, "-"
  102. mov ah, 02h
  103. int 21h
  104.  
  105. pop ax
  106. neg ax
  107.  
  108. convert:
  109. xor dx, dx
  110. div cx
  111. add dl, "0"
  112. inc di
  113. push dx
  114. or ax, ax
  115. jnz convert
  116.  
  117. write:
  118. pop dx
  119. mov ah, 02h
  120. int 21h
  121. dec di
  122. jnz write
  123.  
  124. pop di
  125. pop dx
  126. pop cx
  127. pop bx
  128. pop ax
  129.  
  130. endm mWriteAx
  131.  
  132.  
  133.  
  134. .data
  135.  
  136. a db ?
  137. b db ?
  138. x db ?
  139.  
  140. text_in_a db "Input a $"
  141. text_in_b db "Input b $"
  142. text_in_x db "Input x $"
  143. text_res db "Result $"
  144. endl db 13,10,"$"
  145.  
  146. buf db 10 dup(?)
  147.  
  148. .code
  149. start:
  150. mov ax, @data
  151. mov ds, ax
  152.  
  153.  
  154. Print text_in_a
  155. mReadAX buf, 5
  156. mov a, al
  157. Print text_in_b
  158. mReadAX buf, 5
  159. mov b, al
  160. Print text_in_x
  161. mReadAX buf, 5
  162. mov x, al
  163.  
  164.  
  165. xor ax, ax
  166. xor bx, bx
  167. xor cx, cx
  168. xor dx, dx
  169. xor si, si
  170. xor di, di
  171.  
  172. mov al, x
  173. mov bl, x
  174. imul bl
  175. mov cx, ax
  176.  
  177.  
  178. xor ax, ax
  179. mov al, a
  180. mov bl, x
  181. imul bl
  182.  
  183. sub cx, ax
  184. mov ax, cx
  185.  
  186. xor bx, bx
  187. mov bl, b
  188. add bl, 2
  189. idiv bx
  190. mov cx, ax
  191.  
  192. xor ax,ax
  193. mov al, a
  194. mov bl, a
  195. imul bl
  196. imul bl
  197. sub cx, ax
  198.  
  199.  
  200. mov ax, cx
  201. Print text_res
  202. mWriteAx
  203.  
  204. mov ax, 4c00h
  205. int 21h
  206.  
  207. end start
  208.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement