Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .model small
- .stack 100h
- ; ####################
- ; макросы из методички
- mWriteStr macro string
- push ax
- push dx
- mov ah, 09h
- mov dx, offset string
- int 21h
- pop dx
- pop ax
- endm mWriteStr
- mReadAX macro buffer, sz
- local input, startOfConvert, endOfConvert
- push bx
- push cx
- push dx
- input:
- mov [buffer], sz
- mov dx, offset [buffer]
- mov ah, 0Ah
- int 21h
- mov ah, 02h
- mov dl, 0Dh
- int 21h
- mov ah, 02h
- mov dl, 0Ah
- int 21h
- xor ah, ah
- cmp ah, [buffer][1]
- jz input
- xor cx, cx
- mov cl, [buffer][1]
- xor ax, ax
- xor bx, bx
- xor dx, dx
- mov bx, offset [buffer][2]
- cmp [buffer][2], '-'
- jne startOfConvert
- inc bx
- dec cl
- startOfConvert:
- mov dx, 10
- mul dx
- cmp ax, 8000h
- jae input
- mov dl, [bx]
- sub dl, '0'
- add ax, dx
- cmp ax, 8000h
- jae input
- inc bx
- loop startOfConvert
- cmp [buffer][2], '-'
- jne endOfConvert
- neg ax
- endOfConvert:
- pop dx
- pop cx
- pop bx
- endm mReadAX
- mWriteAX macro
- local convert, write
- push ax
- push bx
- push cx
- push dx
- push di
- mov cx, 10
- xor di, di
- or ax, ax
- jns convert
- push ax
- mov dx, "-"
- mov ah, 02h
- int 21h
- pop ax
- neg ax
- convert:
- xor dx, dx
- div cx
- add dl, '0'
- inc di
- push dx
- or ax, ax
- jnz convert
- write:
- pop dx
- mov ah, 02h
- int 21h
- dec di
- jnz write
- pop di
- pop dx
- pop cx
- pop bx
- pop ax
- endm mWriteAX
- ; ####################
- .data
- a dw ?
- x dw ?
- tmp1 dw ?
- tmp2 dw ?
- y1 dw ?
- y2 dw ?
- y dw ?
- msg1 db "input X $"
- msg2 db "input A $"
- msg3 db "answer $"
- endl db 13,10,"$"
- buf db 10 dup(?)
- .code
- start:
- mov ax, @data
- mov ds, ax
- ; read
- mWriteStr msg1
- mReadAX buf, 5
- mov x, ax
- mWriteStr msg2
- mReadAX buf, 5
- mov a, ax
- xor ax, ax
- ; считаем |x|
- mov ax, x
- cmp ax, 0
- jge polozhitelnoe
- neg ax
- polozhitelnoe:
- _Y1: ; считаем Y1
- ; в ax лежит |x|
- ; сравниваем c 4
- cmp ax, 4
- jg bolshe_4 ; если |x| > 4
- ; если |x| <= 4
- mov ax, a ; ax = a
- add ax, 4 ; ax = ax + 4
- mov y1, ax; y1 = ax
- jmp _Y2 ; идём считать y2
- bolshe_4:
- mov ax, x; ax = x
- add ax, x; ax = ax + x
- ; тоже самое, что и ax = x * 2
- mov y1, ax ; y1 = ax
- jmp _Y2 ; идём считать y2
- _Y2: ; считаем Y2
- xor ax, ax
- ; на всякий случай чистим ax
- mov ax, x ; ax = x
- cmp ax, 0 ; проверяем что x = 0
- je raven_0 ; если x = 0 ; равен 0
- ; если x <> 0 ; не равен 0
- mov ax, a ; ax = a
- mov bx, x ; bx = b
- cwd ; надо для правильного знака
- idiv bx ; ax = ax / bx
- mov y2, ax ; y2 = ax
- jmp _Y ; идём считать итоговый Y
- raven_0:
- ; тут просто константа
- mov y2, 9;
- jmp _Y ; идём считать итоговый Y
- _Y: ; считаем итоговый Y
- mov ax, y1 ; ax = y1
- add ax, y2 ; ax = ax + y2
- mov y, ax ; y = ax
- ; печатаем ответ
- mWriteStr msg3
- mWriteAX
- mov ax, 4c00h
- int 21h
- end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement