Ðåôåòåêà.ðó / Èíôîðìàòèêà è ïðîãðàì-èå

Ëàáîðàòîðíàÿ ðàáîòà: Âûïîëíåíèå àðèôìåòè÷åñêèõ îïåðàöèé íàä ÷èñëàìè ñ ôèêñèðîâàííîé çàïÿòîé

Öåëü: îçíàêîìèòüñÿ ñ êîìàíäàìè àðèôìåòè÷åñêèõ îïåðàöèé, ââîäîì äàííûõ ñ êëàâèàòóðû è âûâîäîì äàííûõ íà ýêðàí.

Çàäàíèå: íàïèñàòü ïðîãðàììó ââîäà ñ êëàâèàòóðû äâóõ ÷èñåë â 9-ðè÷íîé ñèñòåìå ñ÷èñëåíèÿ ðàçìåðîì ñ ñëîâî, âûïîëíåíèÿ íàä íèìè äåëåíèÿ è âûâîäà ðåçóëüòàòà â èñõîäíîé ñèñòåìå ñ÷èñëåíèÿ. Ïðîãðàììà äîëæíà ïðåäóñìàòðèâàòü êîíòðîëü ââîäèìîé èíôîðìàöèè, êîíòðîëü äèàïàçîíà ÷èñåë è ðåçóëüòàòà îïåðàöèè (ïåðåïîëíåíèå, íåâîçìîæíîñòü äåëåíèÿ).

Ïðîãðàììà:

;-----------ËÀÁÎÐÀÒÎÐÍÀß ÐÀÁÎÒÀ ¹3

.MODEL SMALL

.STACK 100H

.186

.DATA

S1 DB 'ÂÂÅÄÈÒÅ ÄÅËÈÌÎÅ Â ÄÅÂßÒÈÐÈ×ÍÎÉ ÑÈÑÒÅÌÅ'

DB ' Ñ×ÈÑËÅÍÈß (ÎÒ -48848 ÄÎ 1Î8806): ',10,13,'$'

S2 DB 'ÂÂÅÄÈÒÅ ÄÅËÈÒÅËÜ Â ÄÅÂßÒÈÐÈ×ÍÎÉ ÑÈÑÒÅÌÅ'

DB ' Ñ×ÈÑËÅÍÈß (ÎÒ -48848 ÄÎ 1Î8806): ',10,13,'$'

S3 DB 'ÍÅÂÅÐÍÀß ÇÀÏÈÑÜ ×ÈÑËÀ  ÄÅÂßÒÈÐÈ×ÍÎÉ'

DB ' ÑÈÑÒÅÌÅ Ñ×ÈÑËÅÍÈß ÈÇ ÇÀÄÀÍÍÎÃÎ ÄÈÀÏÀÇÎÍÀ.','$'

S4 DB 'ÄÅËÅÍÈÅ ÍÅÂÎÇÌÎÆÍÎ: ÄÅËÈÒÅËÜ ÐÀÂÅÍ ÍÓËÞ.','$'

S5 DB 'ÄÅËÅÍÈÅ ÍÅÂÎÇÌÎÆÍÎ: ÄÅËÈÒÅËÜ ÁÎËÜØÅ ÄÅËÈÌÎÃÎ.','$'

S6 DB 'ÎÑÒÀÒÎÊ: ',10,13,'$'

S7 DB '×ÀÑÒÍÎÅ: ',10,13,'$'

L DB '48848' ;ÌÈÍÈÌÀËÜÍÎÅ ×ÈÑËÎ

H DB '108806' ;ÌÀÊÑÈÌÀËÜÍÎÅ ×ÈÑËÎ

SX DB 12 DUP('x') ;ÄÅËÈÌÎÅ

SY DB 12 DUP('y') ;ÄÅËÈÒÅËÜ

SZ DB 8 DUP('0'),'$' ;×ÀÑÒÍÎÅ

.CODE

BEGIN: MOV AX, @DATA

MOV DS, AX

;-----------Î×ÈÑÒÊÀ ÁÓÔÅÐÀ ÊËÀÂÈÀÒÓÐÛ

START: CLI ;ÇÀÏÐÅÒ ÏÐÅÐÛÂÀÍÈÉ

SUB AX, AX

MOV ES, AX

MOV AL, ES:[41AH]

MOV ES:[41CH], AL

STI ;ÐÀÇÐÅØÅÍÈÅ ÏÐÅÐÛÂÀÍÈÉ

;-----------Î×ÈÑÒÊÀ ÝÊÐÀÍÀ

CLD

MOV AX, 0B800H

MOV ES, AX

MOV DI, 0

MOV AL, 32

MOV AH, 7

MOV CX, 2000

REP STOSW

;-----------ÓÑÒÀÍÎÂÊÀ ÊÓÐÑÎÐÀ Â ËÅÂÛÉ ÂÅÐÕÍÈÉ ÓÃÎË ÝÊÐÀÍÀ

MOV AH, 2 ;ÍÎÌÅÐ ÔÓÍÊÖÈÈ

MOV BH, 0 ;ÍÎÌÅÐ ÑÒÐÀÍÈÖÛ

MOV DH, 0 ;ÑÒÐÎÊÀ

MOV DL, 0 ;ÑÒÎËÁÅÖ

INT 10H ;ÏÎÇÈÖÈÎÍÈÐÎÂÀÍÈÅ ÊÓÐÑÎÐÀ

;-----------ÂÛÂÎÄ ÏÐÈÃËÀØÅÍÈß ÂÂÎÄÀ ÄÅËÈÌÎÃÎ

LEA DX, S1

MOV AH, 9

INT 21H

;-----------ÂÂÎÄ ÄÅËÈÌÎÃÎ

LEA DX, SX

MOV BX, DX

MOV [BX], BYTE PTR 9 ;ÏÐÅÄÏÎËÀÃÀÅÌÀß ÄËÈÍÀ ÑÒÐÎÊÈ

MOV AH, 0AH

INT 21H

;-----------ÓÑÒÀÍÎÂÊÀ ÊÓÐÑÎÐÀ

MOV AH, 2 ;ÍÎÌÅÐ ÔÓÍÊÖÈÈ

MOV BH, 0 ;ÍÎÌÅÐ ÑÒÐÀÍÈÖÛ

MOV DH, 2 ;ÑÒÐÎÊÀ

MOV DL, 0 ;ÑÒÎËÁÅÖ

INT 10H ;ÏÎÇÈÖÈÎÍÈÐÎÂÀÍÈÅ ÊÓÐÑÎÐÀ

;-----------ÏÐÎÂÅÐÊÀ ÏÐÀÂÈËÜÍÎÑÒÈ ÂÂÎÄÀ ÄÅËÈÌÎÃÎ

LEA DX, SX

MOV BX, DX

CALL CONTROL ;ÏÐÎÂÅÐÊÀ ÏÐÀÂÈËÜÍÎÑÒÈ ÂÂÎÄÀ

MOV AL, [BX]

CMP AL, '0'

JE ZERO1 ;×ÈÑËÎ ÂÂÅÄÅÍÎ ÍÅÂÅÐÍÎ

JMP NEAR PTR DELITEL

ZERO1: LEA DX, S3

MOV AH, 9

INT 21H

;===========ÎÆÈÄÀÍÈÅ ÍÀÆÀÒÈß ÊËÀÂÈØÈ

MOV AH, 7

INT 21H

JMP NEAR PTR START

;-----------ÂÛÂÎÄ ÏÐÈÃËÀØÅÍÈß ÂÂÎÄÀ ÄÅËÈÒÅËß

DELITEL: LEA DX, S2

MOV AH, 9

INT 21H

;-----------ÂÂÎÄ ÄÅËÈÒÅËß

INPUT: LEA DX, SY

MOV BX, DX

MOV [BX], BYTE PTR 9 ;ÏÐÅÄÏÎËÀÃÀÅÌÀß ÄËÈÍÀ ÑÒÐÎÊÈ

MOV AH, 0AH

INT 21H

;-----------ÓÑÒÀÍÎÂÊÀ ÊÓÐÑÎÐÀ

MOV AH, 2 ;ÍÎÌÅÐ ÔÓÍÊÖÈÈ

MOV BH, 0 ;ÍÎÌÅÐ ÑÒÐÀÍÈÖÛ

MOV DH, 4 ;ÑÒÐÎÊÀ

MOV DL, 0 ;ÑÒÎËÁÅÖ

INT 10H ;ÏÎÇÈÖÈÎÍÈÐÎÂÀÍÈÅ ÊÓÐÑÎÐÀ

;-----------ÏÐÎÂÅÐÊÀ ÏÐÀÂÈËÜÍÎÑÒÈ ÂÂÎÄÀ ÄÅËÈÒÅËß

LEA DX, SY

MOV BX, DX

CALL CONTROL ;ÏÐÎÂÅÐÊÀ ÏÐÀÂÈËÜÍÎÑÒÈ ÂÂÎÄÀ

CMP [BX], BYTE PTR '0'

JE ZERO2 ;×ÈÑËÎ ÂÂÅÄÅÍÎ ÍÅÂÅÐÍÎ

JMP NEAR PTR OK

ZERO2: LEA DX, S3

MOV AH, 9

INT 21H

;===========ÎÆÈÄÀÍÈÅ ÍÀÆÀÒÈß ÊËÀÂÈØÈ

MOV AH, 7

INT 21H

;-----------Î×ÈÑÒÊÀ ÁÓÔÅÐÀ ÊËÀÂÈÀÒÓÐÛ

CLI

SUB AX, AX

MOV ES, AX

MOV AL, ES:[41AH]

MOV ES:[41CH], AL

STI

;-----------Î×ÈÑÒÊÀ ÝÊÐÀÍÀ

CLD

MOV AX, 0B800H

MOV ES, AX

MOV DI, 480

MOV AL, 32

MOV AH, 7

MOV CX, 480

REP STOSW

;-----------ÓÑÒÀÍÎÂÊÀ ÊÓÐÑÎÐÀ

MOV AH, 2 ;ÍÎÌÅÐ ÔÓÍÊÖÈÈ

MOV BH, 0 ;ÍÎÌÅÐ ÑÒÐÀÍÈÖÛ

MOV DH, 3 ;ÑÒÐÎÊÀ

MOV DL, 0 ;ÑÒÎËÁÅÖ

INT 10H ;ÏÎÇÈÖÈÎÍÈÐÎÂÀÍÈÅ ÊÓÐÑÎÐÀ

JMP NEAR PTR INPUT

;-----------ÓÑÒÀÍÎÂÊÀ ÊÓÐÑÎÐÀ

OK: MOV AH, 2 ;ÍÎÌÅÐ ÔÓÍÊÖÈÈ

MOV BH, 0 ;ÍÎÌÅÐ ÑÒÐÀÍÈÖÛ

MOV DH, 4 ;ÑÒÐÎÊÀ

MOV DL, 0 ;ÑÒÎËÁÅÖ

INT 10H ;ÏÎÇÈÖÈÎÍÈÐÎÂÀÍÈÅ ÊÓÐÑÎÐÀ

;-----------ÏÐÎÂÅÐÊÀ ÂÎÇÌÎÆÍÎÑÒÈ ÄÅËÅÍÈß

LEA BX, SX

CALL CTRL0

MOV AH, [BX]

LEA BX, SY

CALL CTRL0

MOV AL, [BX]

CMP AL, '0'

JE NULL

JMP N_NULL

;-----------ÄÅËÈÒÅËÜ ÐÀÂÅÍ ÍÓËÞ

NULL: LEA DX, S4

MOV AH, 9

INT 21H

JMP NEAR PTR ENDPROG

;-----------ÄÅËÈÒÅËÜ ÍÅ ÐÀÂÅÍ ÍÓËÞ

N_NULL: CMP AH, '0'

JNE DELENIE

;-----------ÄÅËÈÌÎÅ ÐÀÂÍÎ ÍÓËÞ

LEA DX, S7

MOV AH, 9

INT 21H

LEA BX, SZ

MOV [BX], BYTE PTR '0'

INC BX

MOV [BX], BYTE PTR 10

INC BX

MOV [BX], BYTE PTR 13

INC BX

MOV [BX], BYTE PTR '$'

LEA DX, SZ

MOV AH, 9

INT 21H

LEA DX, S6

MOV AH, 9

INT 21H

LEA DX, SZ

MOV AH, 9

INT 21H

JMP NEAR PTR ENDPROG

;-----------ÄÅËÈÌÎÅ È ÄÅËÈÒÅËÜ ÍÅ ÐÀÂÍÛ ÍÓËÞ

DELENIE: LEA SI, SX

LEA DI, SY

CALL COMPARE

CMP [SI], BYTE PTR 1

JE POSSIBLE

;-----------ÄÅËÈÒÅËÜ ÁÎËÜØÅ ÄÅËÈÌÎÃÎ

LEA DX, S5

MOV AH, 9

INT 21H

JMP NEAR PTR ENDPROG

;-----------ÍÀ×ÈÍÀÅÒÑß ÄÅËÅÍÈÅ

POSSIBLE: MOV BX, 7 ;BX - ÈÍÄÅÊÑ ÄËß ×ÀÑÒÍÎÃÎ

;----------- ÑÕ - ×ÈÑËÎ ÐÀÇÐßÄΠÄÅËÈÒÅËß

AGAIN: MOV CL, SY[1] ;CX - ×ÈÑËÎ ÐÀÇÐÀÄΠÄÅËÈÒÅËß

MOV CH, 0

;-----------DI - ÍÀ ÌËÀÄØÈÉ ÐÀÇÐßÄ ÄÅËÈÒÅËß

MOV DI, CX ;DI - ÈÍÄÅÊÑ ÄËß ÄÅËÈÒÅËß

INC DI

;-----------ÓÄÀËÅÍÈÅ ÂÅÄÓÙÈÕ ÍÓËÅÉ ÄÅËÈÒÅËß

MOV SI, 2 ;SI - ÈÍÄÅÊÑ ÄËß ÄÅËÈÌÎÃÎ

MOV AL, SY[SI]

CMP AL, '-'

JNE BEFORE_C1

INC SI

DEC CX

BEFORE_C1: MOV AL, SY[SI]

CMP AL, '0'

JE SS1

JMP LBLL

SS1: INC SI

DEC CX

JMP BEFORE_C1

;-----------SI - ÍÀ ÌËÀÄØÈÉ ÐÀÇÐßÄ ÄÅËÈÌÎÃÎ

LBLL: MOV AL, SX[1]

CBW ;ÀÍ - ÄËß ÇÀÏÈÑÈ ÏÅÐÅÍÎÑÀ

MOV SI, AX

INC SI

;-----------ÍÀ×ÀËÎ ÖÈÊËÀ ÄÅËÅÍÈß

;===========ÑÐÀÂÍÅÍÈÅ ÖÈÔÐ ÐÀÇÐßÄÀ ÄÅËÈÌÎÃÎ È ÄÅËÈÒÅËß

C1: MOV AL, SX[SI]

CMP AL, SY[DI]

JAE NEXT

;===========ÖÈÔÐÀ ÄÅËÈÌÎÃÎ ÌÅÍÜØÅ ÖÈÔÐÛ ÄÅËÈÒÅËß

ADD AL, 9 ;ÇÀ¨Ì ÅÄÈÍÈÖÛ

SUB AL, SY[DI] ;ÂÛ×ÈÒÀÍÈÅ

ADD AL, '0' ;ÏÅÐÅÂÎÄ ÖÈÔÐÛ Â ÅÅ ÊÎÄ

SUB AL, AH ;ÂÛ×ÈÒÀÍÈÅ ÏÅÐÅÍÎÑÀ

MOV SX[SI], AL ;ÐÅÇÓËÜÒÀÒ - ÍÀ ÌÅÑÒÎ ÐÀÇÐßÄÀ ÄÅËÈÌÎÃÎ

MOV AH, 1 ;ÇÀÏÈÑÜ ÇÀ¨ÌÀ

JMP NEAR PTR DECREM ;ÍÀ ÊÎÍÅÖ ÖÈÊËÀ

;===========ÖÈÔÐÀ ÄÅËÈÌÎÃÎ ÁÎËÜØÅ ÖÈÔÐÛ ÄÅËÈÒÅËß

NEXT: SUB AL, SY[DI] ;ÂÛ×ÈÒÀÍÈÅ

SUB AL, AH ;ÂÛ×ÈÒÀÍÈÅ ÏÅÐÅÍÎÑÀ

MOV AH, 0 ;ÇÀ¨ÌÀ ÍÅÒ

ADD AL, '0' ;ÏÅÐÅÂÎÄ ÖÈÔÐÛ Â ÅÅ ÊÎÄ

MOV SX[SI], AL ;ÐÅÇÓËÜÒÀÒ - ÍÀ ÌÅÑÒÎ ÐÀÇÐßÄÀ ÄÅËÈÌÎÃÎ

;-----------SI, DI - ÍÀ ÁÎËÅÅ ÑÒÀÐØÈÉ ÐÀÇÐßÄ

DECREM: DEC SI

DEC DI

LOOP C1 ;ÍÀ ÍÀ×ÀËÎ ÖÈÊËÀ ÄÅËÅÍÈß

;-----------ÁÛË ËÈ ÇÀ¨Ì ÈËÈ ÍÅÒ

CMP AH, 1

JNE SRAVN

;-----------ÇÀ¨Ì ÁÛË

AGAIN1: CMP SX[SI], '0' ;ÑÐÀÂÍÅÍÈÅ ÖÈÔÐÛ ÐÀÇÐßÄÀ Ñ ÍÓ˨Ì

JE C2

DEC SX[SI]

JMP SRAVN

;-----------ÖÈÔÐÀ ÐÀÇÐßÄÀ ÄÅËÈÒÅËß ÐÀÂÍÀ ÍÓËÞ

C2: MOV SX[SI], '8'

DEC SI ;ÍÀ ÁÎËÅÅ ÑÒÀÐØÈÉ ÐÀÇÐßÄ

JMP AGAIN1 ;ÍÀ ÑÐÀÂÍÅÍÈÅ ÖÈÔÐÛ ÐÀÇÐßÄÀ Ñ ÍÓ˨Ì

;===========ÔÎÐÌÈÐÎÂÀÍÈÅ ×ÀÑÒÍÎÃÎ

;-----------ÅÑÒÜ ËÈ ÏÅÐÅÍÎÑ ÏÐÈ ÓÂÅËÈ×ÅÍÈÈ ×ÀÑÒÍÎÃÎ ÍÀ ÅÄÈÍÈÖÓ

SRAVN: CMP SZ[BX], '8'

JE PERENOS

;-----------ÏÅÐÅÍÎÑÀ ÍÅÒ

ADD SZ[BX], 1 ;ÓÂÅËÈ×ÅÍÈÅ ×ÀÑÒÍÎÃÎ ÍÀ ÅÄÈÍÈÖÓ

MOV BX, 7 ;ÂÕ - ÍÀ ÌËÀÄØÈÉ ÐÀÇÐßÄ

JMP DEL ;ÍÀ ÑÐÀÂÍÅÍÈÅ ÄÅËÈÌÎÃÎ È ÄÅËÈÒÅËß

;-----------ÏÅÐÅÍÎÑ ÅÑÒÜ

PERENOS: MOV SZ[BX], '0' ; ÄÀÍÍÛÉ ÐÀÇÐßÄ - ÍÓËÜ

DEC BX ;ÓÂÅËÈ×ÅÍÈÅ ÐÀÇÐßÄÀ

JMP SRAVN ;ÍÀ ÑÐÀÂÍÅÍÈÅ ÐÀÇÐßÄÀ Ñ "8"

;===========ÑÐÀÂÍÅÍÈÅ ÄÅËÈÌÎÃÎ È ÄÅËÈÒÅËß

DEL: LEA SI, SX

LEA DI, SY

CALL COMPARE

MOV AL, [SI]

CMP AL, 1

JNE QUIT ;ÄÅËÅÍÈÅ ÇÀÂÅÐØÅÍÎ

JMP NEAR PTR AGAIN ;ÄÅËÅÍÈÅ ÏÐÎÄÎËÆÀÅÒÑß

;-----------ÎÏÐÅÄÅËÅÍÈÅ ÇÍÀÊÀ ×ÀÑÒÍÎÃÎ

QUIT: MOV AH, SX[2]

MOV AL, SY[2]

;-----------ÂÛßÑÍÅÍÈÅ ÇÍÀÊÀ ÄÅËÈÌÎÃÎ

CMP AH, '-'

JE SX_

JMP N_SX_

;-----------ÄÅËÈÌÎÅ - ÎÒÐÈÖÀÒÅËÜÍÎÅ

SX_: CMP AH, AL ;ÑÐÀÂÍÅÍÈÅ ÇÍÀÊÀ ÄÅËÈÌÎÃÎ È ÄÅËÈÒÅß

JE OUTP ;ÍÀ ÂÛÂÎÄ ÎÑÒÀÒÊÀ

;-----------ÄÅËÈÒÅËÜ - ÏÎËÎÆÈÒÅËÜÍÛÉ

;===========ÓÄÀËÅÍÈÅ ÂÅÄÓÙÈÕ ÍÓËÅÉ Â ×ÀÑÒÍÎÌ

SY_: MOV BX, 0

SRCH: CMP SZ[BX], '0'

JE DALEE

JMP STOP

DALEE: INC BX

JMP SRCH

;-----------ÇÀÏÈÑÜ ÌÈÍÓÑÀ ÏÅÐÅÄ ÑÒÀÐØÈÌ ÐÀÇÐßÄÎÌ ×ÀÑÒÍÎÃÎ

STOP: DEC BX

MOV SZ[BX], '-'

JMP OUTP ;ÍÀ ÂÛÂÎÄ ÎÑÒÀÒÊÀ

;-----------ÄÅËÈÌÎÅ ÏÎËÎÆÈÒÅËÜÍÎÅ

N_SX_: CMP AL, '-' ;ÄÅËÈÒÅËÜ ÎÒÐÈÖÀÒÅËÜÍÛÉ?

JE SY_ ;×ÀÑÒÍÎÅ ÎÒÐÈÖÀÒÅËÜÍÎÅ

;-----------ÂÛÂÎÄ ×ÀÑÒÍÎÃÎ

;===========ÂÛÂÎÄ ÎÑÒÀÒÊÀ

;-----------ÂÛÂÎÄ ÑÒÐÎÊÈ "ÎÑÒÀÒÎÊ:"

OUTP: LEA DX, S6

MOV AH, 9

INT 21H

;ÇÀÏÈÑÜ Â ÊÎÍÅÖ ÎÑÒÀÒÊÀ ÑÈÌÂÎËÎÂ 10, 13 È "$"

MOV BH, 0

MOV BL, SX[1]

ADD BX, 2 ;ÂÕ - ÇÀ ÌËÀÄØÈÉ ÐÀÇÐßÄ

MOV SX[BX], 10

INC BX

MOV SX[BX], 13

INC BX

MOV SX[BX], '$'

;-----------ÓÄÀËÅÍÈÅ ÂÅÄÓÙÈÕ ÍÓËÅÉ ÎÑÒÀÒÊÀ

MOV AH, '0'

LEA BX, SX ;ÂÕ - ÓÊÀÇÛÂÀÅÒ ÍÀ ÎÑÒÀÒÎÊ

INC BX

INC BX

MOV AL, [BX]

CMP AL, '-'

JE MN

JMP N_MN

MN: MOV AH, '-'

INC BX

N_MN: MOV AL, [BX]

CMP AL, '0'

JE EQ1

JMP NEQ1

EQ1: INC BX

JMP N_MN

NEQ1: MOV AL, [BX]

DEC BX

CMP AL, 10

JE N_NUL

MOV [BX], AH

CMP AH, '-'

JE EQQ

JMP NEQQ

EQQ: MOV DX, BX

JMP LBL

NEQQ: INC BX

MOV AL, [BX]

CMP AL, 10

JE NUL

JMP N_NUL

NUL: DEC BX

N_NUL: MOV DX, BX

LBL: MOV AH, 9

INT 21H

;===========ÂÛÂÎÄ ×ÀÑÒÍÎÃÎ

LEA DX, S7

MOV AH, 9

INT 21H

LEA BX, SZ

Q: MOV AL, [BX]

CMP AL, '0'

JE SM3

JMP OUTPUT

SM3: INC BX

JMP Q

OUTPUT: MOV DX, BX

MOV AH, 9

INT 21H

;-----------ÂÛÕÎÄ ÈÇ ÏÐÎÃÐÀÌÌÛ

ENDPROG: MOV AH, 4CH

INT 21H

;===========ÏÐÎÖÅÄÓÐÀ CONTROL - ×ÈÑËÎ ÄÅÂßÒÈÐÈ×ÍÎÅ?

CONTROL PROC

PUSHA ;ÑÎÕÐÀÍÅÍÈÅ ÐÅÃÈÑÒÐÎÂ Â ÑÒÅÊÅ

MOV BX, DX

INC BX

MOV AL, [BX]

MOV AH, 0

MOV CX, AX

;-----------ßÂËßÅÒÑß ËÈ ÑÒÐÎÊÀ ÏÓÑÒÎÉ?

CMP AL, 0

JE ERR1 ;ßÂËßÅÒÑß

;-----------ÏÐÎÂÅÐÊÀ ÄËÈÍÛ ÑÒÐÎÊÈ

CMP AL, 6

JA ERR1 ;×ÈÑËÎ ÂÂÅÄÅÍÎ ÍÅÂÅÐÍÎ

INC BX

MOV AH, [BX]

CMP AH, '-'

JE MINUS

JMP NEAR PTR FOR1

MINUS: INC BX ;×ÈÑËÎ ÎÒÐÈÖÀÒÅËÜÍÎÅ

DEC CX

;-----------ÂÂÅÄÅÍÍÎÅ ×ÈÑËÎ ÄÅÂßÒÈÐÈ×ÍÎÅ?

FOR1: MOV AH, [BX]

CMP AH, '9'

JB N1

ERR1: JMP NEAR PTR ERROR ;×ÈÑËÎ ÂÂÅÄÅÍÎ ÍÅÂÅÐÍÎ

N1: CMP AH, '0'

JB ERR1 ;×ÈÑËÎ ÂÂÅÄÅÍÎ ÍÅÂÅÐÍÎ

INC BX

LOOP FOR1

MOV [BX], BYTE PTR '$' ;ÄËß ÂÛÂÎÄÀ ÑÒÐÎÊÈ

CMP AL, 6

JNE RETURN ;ÅÑËÈ ÄËÈÍÀ ×ÈÑËÀ ÌÅÍÜØÅ 6

MOV BX, DX

INC BX

MOV AH, 0

MOV CX, AX

INC BX

MOV AH, [BX]

CMP AH, '-'

JE M1 ;×ÈÑËÎ ÎÒÐÈÖÀÒÅËÜÍÎÅ

LEA DI, H ;×ÈÑËÎ ÏÎËÎÆÈÒÅËÜÍÎÅ

JMP FOR2

M1: INC BX

DEC CX

LEA DI, L

;ÂÕÎÄÈÒ ËÈ ×ÈÑËÎ Â ÇÀÄÀÍÍÛÉ ÄÈÀÏÀÇÎÍ?

FOR2: MOV AH, [BX]

CMP AH, [DI]

JA ERROR ;×ÈÑËÎ ÂÂÅÄÅÍÎ ÍÅÂÅÐÍÎ

JB RETURN ;×ÈÑËÎ ÂÂÅÄÅÍÎ ÏÐÀÂÈËÜÍÎ

INC BX

INC DI

LOOP FOR2

JMP RETURN

ERROR: MOV BX, DX

MOV [BX], BYTE PTR '0'

RETURN: POPA ;ÂÎÑÑÒÀÍÎÂËÅÍÈÅ ÐÅÃÈÑÒÐÎÂ

RET

CONTROL ENDP

;===========ÏÐÎÖÅÄÓÐÀ CTRL0 - ÝÒÎ ÍÓËÜ?

CTRL0 PROC

PUSHA

MOV SI, 1

MOV CL, [BX+SI]

MOV CH, 0

INC SI

MOV AL, [BX+SI]

CMP AL, '-'

JE MIN

JMP CYCLE

MIN: INC SI

DEC CX

CYCLE: MOV AL, [BX+SI]

CMP AL, '0'

JNE FINISH

INC SI

LOOP CYCLE

MOV SI, 0

MOV AL, '0'

MOV [BX+SI], AL

FINISH: POPA

RET

CTRL0 ENDP

;===========ÏÐÎÖÅÄÓÐÀ COMPARE - ÑÐÀÂÍÅÍÈÅ ÄÂÓÕ ×ÈÑÅË

COMPARE PROC

PUSHA

INC SI

INC DI

MOV AH, [SI]

MOV AL, [DI]

INC SI

INC DI

CMP BYTE PTR [SI], '-'

JE NEGAT1

JMP POZIT1

NEGAT1: DEC AH

INC SI

POZIT1: CMP BYTE PTR [DI], '-'

JE NEGAT2

JMP POZIT2

NEGAT2: DEC AL

INC DI

POZIT2: MOV BL, [SI]

CMP BL, '0'

JE SM

JMP DI0

SM: INC SI

DEC AH

JMP POZIT2

DI0: MOV BL, [DI]

CMP BL, '0'

JE SM1

JMP SRAV1

SM1: INC DI

DEC AL

JMP DI0

SRAV1: CMP AH, AL

JA ABOVE

JB BELOW

JMP EQUAL

ABOVE: LEA SI, SX

MOV [SI], BYTE PTR 1

JMP NEAR PTR END1

BELOW: LEA SI, SX

MOV [SI], BYTE PTR -1

JMP NEAR PTR END1

EQUAL: MOV CL, AL

MOV CH, 0

FOR3: MOV AH, [SI]

CMP AH, [DI]

JA ABOVE

JB BELOW

INC SI

INC DI

LOOP FOR3

JMP ABOVE

END1: POPA

RET

COMPARE ENDP

END BEGIN


18


Ïîõîæèå ðàáîòû:

  1. Îáùàÿ òåðìèíîëîãèÿ ïðîãðàììèðîâàíèÿ
  2. • Àðõèòåêòóðà ÝÂÌ
  3. • Ïðåäñòàâëåíèå ÷èñëåííîé èíôîðìàöèè â ÝÂÌ. Ñèñòåìû ñ÷èñëåíèÿ
  4. • Àðèôìåòè÷åñêèå îñíîâû ÖÂÌ
  5. • Óñòðîéñòâî ÏÊ
  6. •  ... Ñòðóêòóðà àëó äëÿ óìíëæåíèÿ ÷èñåë ñ ôèêñèðîâàííîé çàïÿòîé
  7. • Ëàáîðàòîðíàÿ ðàáîòà ïî èíôîðìàòèêå ( çàäàíèÿ )
  8. • Óñòðîéñòâî äåëåíèÿ 16-òè ðàçðÿäíûõ ÷èñåë ñ ïëàâàþùåé çàïÿòîé
  9. • Àðèôìåòè÷åñêèå îïåðàöèè ñ BCD ÷èñëàìè
  10. • Öèôðîâûå àâòîìàòû
  11. • Ëàáîðàòîðíàÿ ðàáîòà ïî èíôîðìàòèêå ( ïðàêòèêà )
  12. • ×èñëîâàÿ è íå÷èñëîâàÿ îáðàáîòêà èíôîðìàöèè
  13. • Óñòðîéñòâî äåëåíèÿ 16-òè ðàçðÿäíûõ ÷èñåë ñ ïëàâàþùåé çàïÿòîé
  14. • Àðèôìåòè÷åñêèå îñíîâû ÖÂÌ
  15. • Ðàçðàáîòêà ñõåìû áëîêà àðèôìåòèêî-ëîãè÷åñêîãî ...
  16. • Äåëåíèå áåç âîññòàíîâëåíèÿ îñòàòêà ñî ñäâèãîì îñòàòêà
  17. • Ìèêðîïðîöåññîðíûå ñðåäñòâà è ñèñòåìû
  18. • Ñòðóêòóðíàÿ ñõåìà ÝÂÌ
  19. • Ïðîãðàììèðîâàíèå àðèôìåòè÷åñêèõ çàäà÷ íà ...
Ðåôåòåêà ðó refoteka@gmail.com