Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- format MZ
- entry Main:Start
- ;==========================================================
- segment Main
- ;==========================================================
- ;раздел переменных и констант
- TenConst dw 10
- TwoConst dw 2
- X dw 4
- Y dw 4
- Z dw 5
- 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$'
- MessageStack db 10, 13, 'Using Stack and Call: $'
- MessageRegisters db 10, 13, 'Using Registers and FarCall: $'
- messageGlobalValues db 10, 13, 'Using Global Values and FarCall: $'
- ;==========================================================
- Start:
- push cs
- pop ds
- xor ax, ax
- push MessageTaskInfo
- call MessageProcedure
- ;===============================================
- ;= передача через стек + ближний вызов =
- ;===============================================
- push MessageStack
- call MessageProcedure
- push [X]
- push [Y]
- push [Z]
- call StackProcedure
- push ax
- call OutputProcedure
- ;=================================================
- ;= передача через регистры + дальний вызов =
- ;=================================================
- push MessageRegisters
- call MessageProcedure
- mov ax, [X]
- mov dx, [Y]
- mov cx, [Z]
- mov bx, [TwoConst]
- call far Procedures: RegistersProcedure
- push ax
- call OutputProcedure
- ;===================================================
- ;= передача через переменные + дальний вызов =
- ;===================================================
- push messageGlobalValues
- call MessageProcedure
- call far Procedures: GlobalValuesProcedure
- push ax
- call OutputProcedure
- mov ax, 0C01h
- int 21h
- mov ah, 4ch
- int 21h
- ;===========================
- ;= Dурка имени Проце =
- ;===========================
- ; Общие проце дуры
- ;===========================
- ; для вывода сообщения
- MessageProcedure:
- push bp
- mov bp, sp
- mov dx, [bp + 4]
- mov ah, 09h
- int 21h
- pop bp
- ret 2
- ; для вывода значения (начинаем думая что значение знаковое)
- OutputProcedure:
- push bp
- mov bp, sp
- mov ax, [bp + 4]
- test ax, ax
- jns IfUnsigned
- mov cx, ax
- mov ah, 02h
- mov dx, '-'
- int 21h
- mov ax, cx
- neg ax
- ;обнуляем регистр cx для того, чтобы потом записать в него нужное количество итераций
- IfUnsigned:
- xor cx, cx
- ;занос значения в стек посимвольно
- PushingProcess:
- xor dx, dx
- div [TenConst]
- add dx, '0'
- push dx
- inc cx
- test ax, ax
- jnz PushingProcess
- ;вывод значения посимвольно
- PopingProcess:
- pop dx
- mov ah, 02h
- int 21h
- loop PopingProcess
- pop bp
- ret 2
- ;1)процедура для стека
- ; push [X]
- ; push [Y]
- ; push [Z]
- StackProcedure:
- push bp
- mov bp, sp
- mov ax, [bp + 8]
- mul ax
- mul [TwoConst]
- mov bx, ax
- mov ax, [bp + 6]
- mul ax
- add ax, bx
- xor di, di
- mov cx, [bp + 4]
- .countOfBytes:
- sar cx, 1
- inc di
- cmp cx, 0
- jnz StackProcedure.countOfBytes
- mov cx, di
- .RotatingLeft:
- rol ax, 1
- loop StackProcedure.RotatingLeft
- pop bp
- ret 6
- ;==================================
- segment Procedures
- ;==================================
- ;2)для регистров
- RegistersProcedure:
- mov di, dx
- mul ax
- mul bx
- mov bx, ax
- mov ax, di
- mul ax
- add ax, bx
- mov bx, cx
- xor cx, cx
- xor di, di
- mov cx, bx
- @@:
- sar cx, 1
- inc di
- cmp cx, 0
- jnz @B
- mov cx, di
- @@:
- rol ax, 1
- loop @B
- retf
- ;3)для глобальных переменных
- GlobalValuesProcedure:
- mov ax, [X]
- mul ax
- mul [TwoConst]
- mov bx, ax
- mov ax, [Y]
- mul ax
- add ax, bx
- xor cx, cx
- xor di, di
- mov cx, [Z]
- @@:
- sar cx, 1
- inc di
- cmp cx, 0
- jnz @B
- mov cx, di
- @@:
- rol ax, 1
- loop @B
- retf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement