Advertisement
anticlown

Assembler.Lab.6(full)

May 23rd, 2023 (edited)
605
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. segment Main
  6. ;==========================================================
  7. ;раздел переменных и констант
  8. TenConst      dw      10
  9. TwoConst      dw      2
  10. X             dw      4
  11. Y             dw      4
  12. Z             dw      5
  13. MessageTaskInfo          db      'Enter three 2-bytes numbers X, Y, Z.', 10, 13, 'Program calculates expression 2*X^2 + Y^2 and ROL to number of bytes of Z$'
  14. MessageStack             db      10, 13, 'Using Stack and Call: $'
  15. MessageRegisters         db      10, 13, 'Using Registers and FarCall: $'
  16. messageGlobalValues      db      10, 13, 'Using Global Values and FarCall: $'
  17. ;==========================================================
  18. Start:
  19.         push cs
  20.         pop ds
  21.  
  22.         xor     ax, ax
  23.         push    MessageTaskInfo
  24.         call    MessageProcedure
  25.  
  26. ;===============================================
  27. ;=      передача через стек + ближний вызов    =
  28. ;===============================================
  29.  
  30.         push    MessageStack
  31.         call    MessageProcedure
  32.  
  33.         push    [X]
  34.         push    [Y]
  35.         push    [Z]
  36.         call    StackProcedure
  37.  
  38.         push    ax
  39.         call    OutputProcedure
  40.  
  41. ;=================================================
  42. ;=      передача через регистры + дальний вызов  =
  43. ;=================================================
  44.  
  45.         push    MessageRegisters
  46.         call    MessageProcedure
  47.  
  48.         mov     ax, [X]
  49.         mov     dx, [Y]
  50.         mov     cx, [Z]
  51.         mov     bx, [TwoConst]
  52.         call    far Procedures: RegistersProcedure
  53.  
  54.         push    ax
  55.         call    OutputProcedure
  56.  
  57. ;===================================================
  58. ;=      передача через переменные + дальний вызов  =
  59. ;===================================================
  60.  
  61.         push    messageGlobalValues
  62.         call    MessageProcedure
  63.  
  64.         call    far Procedures: GlobalValuesProcedure
  65.  
  66.         push    ax
  67.         call    OutputProcedure
  68.  
  69.         mov     ax, 0C01h
  70.         int     21h
  71.         mov     ah, 4ch
  72.         int     21h
  73.  
  74. ;===========================
  75. ;=      Dурка имени Проце  =
  76. ;===========================
  77. ;       Общие проце дуры
  78. ;===========================
  79. ;  для вывода сообщения
  80. MessageProcedure:
  81.         push    bp
  82.         mov     bp, sp
  83.         mov     dx, [bp + 4]
  84.         mov     ah, 09h
  85.         int     21h
  86.         pop     bp
  87.         ret     2
  88.  
  89. ;  для вывода значения (начинаем думая что значение знаковое)
  90. OutputProcedure:
  91.         push    bp
  92.         mov     bp, sp
  93.         mov     ax, [bp + 4]
  94.         test    ax, ax
  95.         jns     IfUnsigned
  96.         mov     cx, ax
  97.         mov     ah, 02h
  98.         mov     dx, '-'
  99.         int     21h
  100.         mov     ax, cx
  101.         neg     ax
  102.  
  103. ;обнуляем регистр cx для того, чтобы потом записать в него нужное количество итераций
  104. IfUnsigned:
  105.         xor     cx, cx
  106.  
  107. ;занос значения в стек посимвольно
  108. PushingProcess:
  109.         xor     dx, dx
  110.         div     [TenConst]
  111.         add     dx, '0'
  112.         push    dx
  113.         inc     cx
  114.  
  115.         test    ax, ax
  116.         jnz     PushingProcess
  117.  
  118. ;вывод значения посимвольно
  119. PopingProcess:
  120.         pop     dx
  121.         mov     ah, 02h
  122.         int     21h
  123.         loop    PopingProcess
  124.         pop     bp
  125.         ret     2
  126.  
  127. ;1)процедура для стека
  128.       ; push    [X]
  129.       ; push    [Y]
  130.       ; push    [Z]
  131. StackProcedure:
  132.         push    bp
  133.         mov     bp, sp
  134.  
  135.         mov     ax, [bp + 8]
  136.         mul     ax
  137.         mul     [TwoConst]
  138.         mov     bx, ax
  139.  
  140.         mov     ax, [bp + 6]
  141.         mul     ax
  142.         add     ax, bx
  143.         xor   di, di
  144.         mov  cx, [bp + 4]
  145.  
  146.         .countOfBytes:
  147.                 sar  cx, 1
  148.                 inc  di
  149.                 cmp  cx, 0
  150.                 jnz  StackProcedure.countOfBytes
  151.                 mov     cx, di
  152.  
  153.         .RotatingLeft:
  154.                 rol     ax, 1
  155.                 loop    StackProcedure.RotatingLeft
  156.  
  157.                 pop     bp
  158.                 ret     6
  159.  
  160. ;==================================
  161. segment Procedures
  162. ;==================================
  163. ;2)для регистров
  164. RegistersProcedure:
  165.         mov     di, dx
  166.         mul     ax
  167.         mul     bx
  168.         mov     bx, ax
  169.         mov     ax, di
  170.         mul     ax
  171.         add     ax, bx
  172.         mov     bx, cx
  173.         xor     cx, cx
  174.         xor     di, di
  175.         mov     cx, bx
  176. @@:
  177.         sar  cx, 1
  178.         inc  di
  179.         cmp  cx, 0
  180.         jnz  @B
  181.  
  182.         mov     cx, di
  183. @@:
  184.         rol     ax, 1
  185.         loop    @B
  186.  
  187. retf
  188.  
  189. ;3)для глобальных переменных
  190. GlobalValuesProcedure:
  191.         mov     ax, [X]
  192.         mul     ax
  193.         mul     [TwoConst]
  194.         mov     bx, ax
  195.         mov     ax, [Y]
  196.         mul     ax
  197.  
  198.         add     ax, bx
  199.         xor     cx, cx
  200.         xor     di, di
  201.         mov     cx, [Z]
  202. @@:
  203.         sar     cx, 1
  204.         inc     di
  205.         cmp     cx, 0
  206.         jnz     @B
  207.  
  208.         mov     cx, di
  209.  
  210. @@:
  211.         rol     ax, 1
  212.         loop    @B
  213.  
  214. retf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement