Advertisement
qberik

Untitled

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