Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- org 100h
- start:
- ;âûâîä òåêñòà â êîíñîëü
- mov ah,9h
- mov dx, str1
- int 21h
- mov ah, 09h
- mov dx, inputA ;ïðåäëîæåíèå ââîäà À
- int 21h
- mov ah, 0ah
- mov dx, strA ;ââîäèì ïåðâîå ÷èñëî À
- int 21h
- mov bx, dx ;ïîìåùàåì â bx ññûëêó íà ñòðîêó â êà÷åñòâå ïåðåäà÷è ðåãèñòðà êàê ïàðàìåòðà ïðîöåäóðû
- call count_number ;èçâëåêàåì èç ñòðîêè ÷èñëî À
- push ax ;ðåçóëüòàò èç ðåãèñòðà àõ ïîìåùàåì â ñòåê
- mov ah, 02h
- mov dx, 0x0D0A
- int 21h
- mov ah, 09h
- mov dx, inputB ;ïðåäëîæåíèå ââîäà Â
- int 21h
- mov ah, 0ah
- mov dx, strB ;ââîäèì âòîðîå ÷èñëî Â
- int 21h
- mov bx, dx
- call count_number ;èçâëåêàåì èç ñòðîêè ÷èñëî Â
- push ax ;ðåçóëüòàò èç ðåãèñòðà àõ â ñòåê
- ;ïåðåõîä íà íîâóþ ñòðîêó
- mov ah,9h
- mov dx, new_line
- int 21h
- ;âûâîä òåêñòà â êîíñîëü
- mov ah, 9h
- mov dx, str2
- int 21h
- call get_result ;ïîëó÷àåì ðåçóëüòàò âû÷èñëåíèé
- mov ax, [res] ;ïåðåìåùàåì â àõ ðåçóëüòàò äëÿ ïîñëåäóþùåãî âûâîäà îòâåò
- call output_number ;âûâîä îòâåòà
- pop ax ;÷èñòèì ñòåê
- pop ax
- mov ah, 08h
- int 21h ;êîíåö îñíîâíîé ÷àñòè ïðîãðàììû
- ret
- count_number: ;ïðîöåäóðà ïîëó÷åíèÿ ÷èñëà èç ñòðîêè
- xor ax, ax ;îáíóëÿåì àõ
- xor dx, dx ;îáíóëÿåì dx
- add bx, 1h ;ïåðåäâèãàåì àäðåñ ñòðîêè íà 1
- mov cl, [bx] ;çàõâàòûâàåì 1 áàéò, â êîòîðîì íàõîäèòñÿ ôàêòè÷åñêàÿ äëèíà ñòðîêè
- lp: ;öèêë ïîëó÷åíèÿ ÷èñëà
- inc bx ;óâåëè÷èâàåì óêàçàòåëü íà ñòðîêó íà 1
- mul [cm] ;óìíîæàåì íà 10
- add al, [bx] ;ïðèáàâëÿåì öèôðó
- sub ax, '0' ;óáèðàåì êîä '0'
- loop lp ;óìåíüøàåì ðåãèñòð ñõ íà 1, ñðàâíèâàåì ñ íóëåì, åñëè íå íîëü, òî ïîâòîðÿåì öèêë
- ret
- output_number: ;ïðîöåäóðà âûâîäà ÷èñëà íà ýêðàí
- push '*' ;çàïîìèíàåì, ÷òî êîíöîì ÷èñëà â ñòåêå áóäåò ñèìâîë *
- lpt: ;öèêë ðàçáèåíèÿ ÷èñëà íà öèôðû è ïåðåäà÷à åãî â ñòåê
- div [cm] ;äåëåíèå ÷èñëà íà 10, îñòàòîê óõîäèò â dx
- push dx ;äîáàâëÿåì â ñòåê îñòàòîê îò äåëåíèÿ
- xor dx, dx ;î÷èùàåì dx îò óæå çàíåñåííîãî ðåçóëüòàòà
- cmp ax, 0h ;ñðàâíèâàåì ðåçóëüòàò äåëåíèÿ ñ 0
- jne lpt ;åñëè íå 0, òî çàíîâî öèêë
- mov ah, 02h
- mov dx, 0x0D0A
- int 21h
- lpp: ;öèêë âûâîäà ÷èñëà
- pop bx ;âûòàñêèâàåì ÷èñëî èç ñòåêà
- cmp bx, '*' ;åñëè êîíåö ñòåêà
- je endst ;òî âûõîäèì èç öèêëà
- add bx, '0' ;èíà÷å äîáàâëÿåì '0' ÷òîáû ïîëó÷èòü ñèìâîë
- mov ah, 02h
- mov dx, bx ;âûâîäèì ñèìâîë
- int 21h
- jmp lpp ;ïîâòîðÿåì öèêë
- endst: ret ;âûõîäèì
- get_result:
- mov bp, sp ;â ðåãèñòð bp ïåðåäàåì óêàçàòåëü íà ñòåê äëÿ äîñòóïà ê äðóãèì ïåðåìåííûì ñòåêà
- mov ax, [bp+4] ;â ðåãèñòð àõ ïåðåäàåì ïåðåìåííóþ À
- mov bx, [bp+2] ;â ðåãèñòð ax ïåðåäàåì ïåðåìåííóþ Â
- mov cx, ax
- mul cx
- mul cx
- mov cx, ax
- mov ax, bx
- mul ax
- mov bx, ax
- mov ax, cx
- sub ax, bx
- mov [res], ax ;ñîõðàíÿåì ðåçóëüòàò
- ret ;âûõîäèì èç ïðîöåäóðû
- str1 db "We will calculate A^3 - B^2", $0d, $0a, "$"
- str2 db "Register procedure result is $"
- inputA db "Enter number A: $"
- inputB db "Enter number B: $"
- new_line db $0d, $0A, "$"
- strA db 10, 0, 10 dup(?)
- strB db 10, 0, 10 dup(?)
- numA dw 0h
- numB dw 0h
- cm dw 10
- res dw 0h
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement