Polynomial added (assembly language implementation of the list)

xiaoxiao2021-03-06  38

Masm 5.0, Win98

Input two polynomials, then display the polynomial addition results. (With static array technology)

Poly.asm

Maxlen = 16

ELEM STRUC INDEX DW 0 BASE DW 0 Next DW 0 ELEM ENDS

DSEG Segment Para Public 'Data' MSG1 DB 'Create List Ha', 0DH, 0AH, 24H MSG2 DB 'Create List HB', 0DH, 0AH, 24h MSG3 DB 'HA = $' MSG4 DB 'HB = $' MSG5 DB ' Input NE: $ 'MSG6 DB' Input NF: $ 'MSG7 DB' HC = $ 'MSG8 DB' Continue (Y / N) $ 'Inbuf DB Maxlen,?, Maxlen Dup (0) Outbuf DB Maxlen DUP (?) Lista DW 0 Listb DW 0 LISTC DW 0 VAL16 DW 1000 DW 1000 DW 100 DW 10 DW 1 HA ELEM 30 DUP (<>) HB ELEM 15 DUP (<>) DSEG Ends

Public Poly Cseg Segment Public PUBLIC 'CODE' Assume CS: CSEG, DS: DSEG, ES: DSEG

Poly Proc Far Start: MOV AX, DSEG MOV DS, AX; MOV DX, OFFSET MSG1 Call Dispmsg Mov BX, Offset Ha Call Create Mov Lista, Bx; Create Ha Call Newl; Mov DX, Offset MSG2 Call Dispmsg Mov BX, Offset HB CALL CREATE MOV lISTB, BX; CREATE HB CALL NEWL; MOV DX, OFFSET MSG3 CALL DISPMSG MOV BX, LISTA CALL SHOWL CALL NEWL; DISPLAY THE HA; MOV DX, OFFSET MSG4 CALL DISPMSG MOV BX, lISTB CALL SHOWL CALL NEWL; DISPLAY THE HB ;; Create The HC = HA HB MOV AX, DS MOV ES, AX MOV BX, Lista Mov Di, Offset HA 15 * 6; Offset Space Mov Si, Listb AddHB: MOV AX, [Si] .index MOV [ Di ] .Index, AX MOV AX, [Si] .Base Mov [Di] .base, Ax Call AddIn, [Si] .Next CMP Si, 0 JZ HBover Add Di, 6 JMP ADDHB HBOVER: MOV DX, OFFSET MSG7 Call newl; dispmsg the hc; call newl retpoly endp; ---------------------------------------------------------------------------------------------------------------------------------------- -; OUTPUT = AX GetNum Proc Push DX Push BX MOV DX, OFFSET INBUF MOV AH, 0AH INT 21H MOV BX, OFFSET INBUF 1 Call ID2B Pop BX Pop DX Retgetnum ENDP;

-----------------------------------; Proc: additem: add a element int; input = bx (Head), Di (newItem); Output = BX (HEAD) AddItem Proc Push BX; Workptr = Head Front = Head MOV BP, BX; (Workptr-> Index> NewItem-> Index && Wrokptr! = 0) MOV AX, [DI] .index Find1: CMP [Si] .index, Ax; Workptr-> Index> NewItem-> Index JG Cont1 JMP Done1 Cont1: Or Si, Si JNE Cont2 JMP Usual Cont2: MOV BP, Si; BP = Front (Node *) MOV SI, [Si] .Next JMP Find1 Done1: CMP [Si] .index, AX JNE INDEXNE MOV AX, [DI] .Base Add [Si] .base, AX JMP Addok Indexne: CMP Si, BX JZ IsHead JMP Usual IsHext: MOV [Di] .Next, Bx; NewTime-> Next = Head Mov BX, DI; Head = NewItem JMP Addokusual: MOV [Di] .next, Si; Newitme-Next = Workptr Mov DS: [BP] .next, Di; Front-> Next = NewItemadDok: Pop Di Pop Si Pop Bp RetaddItem ENDP; --------- ----------------------------; Input = bx; Output = BP (1 = NULL, 0! = Null) Create Proc Push DX Push CX; MOV DI, BX MOV DX, OFFSET MSG5 Call Dispmsg Call GetNum Call Newl MOV CX, AX MOV DX, OFFSET MSG6 Call Dispmsg Call GetNum Call Newl; First Index =

0? OR CX, CX jnz firstn0 or ax, ax; first base = 0? Jnz firstn0 jmp over1firstn0: MOV [di] .index, cx mov [di] .base, ax mov [di] .next, 0 Add di, 6CONGET: MOV DX, OFFSET MSG5 CALL DISPMSG CALL GETNUM CALL NEWL MOV CX, AX MOV DX, OFFSET MSG6 Call Dispmsg Call GetNum Call Newl OR CX, CX JNZ ITEMN0 OR AX, AX JZ OVER1 ITEMN0: MOV [Di] .index, CX MOV [DI] .base, AX Call AddItem Add Di, 6 JMP Content over1: POP CX Pop DX Retcreate Endp; ------------------------- ------------; OUTPUT = AXSHOWNUM PROC PUSH BX OR AX, AX JE AX0 MOV BX, OFFSET OUTBUF CALL IB2A MOV DX, BX CALL DISPMSG JMP SHOWOK AX0: MOV DL, '0' Call Echo Showok: POP BX RetShownum Endp; ---------------------------------------------------------------------------------------------------------------- -; Output = bx (head) showl proc push si push di; null handling cmp [bx] .index, 0 JNE DOSHOW CMP [BX] .base, 0 JNE DOSHOW MOV DL, '0' Call Echo Jmp Over2doshow: Mov Si , BxConshow: CMP Si, 0 JZ over2 MOV AX, [Si] .Base Call shownum Mov DL, 'X' Call Echo Mov DL, '^'

Call Echo Mov AX, [Si] .index Call shownum CMP [Si] .Next, 0 JZ NOTPOS MOV DI, [Si] .Next CMP [Di] .base, 0 JL Notpos Mov DL, ' ' Call echonotpos: MOV Si, [Si] .Next Jmp Conshi Over2: Pop Di Pop Si Retshowl Endp; ---------------------------------------------------------------------------------------------------------------------------------------------------- -----; Proc: ID2B; Input = DS: bx; Output = AX ID2B Proc Push BX Push CX Push DX Push Di Push Si XOR DI, DI CMP BYTE PTR [BX 1], '-' JZ IS_S JMP NOT_S IS_S: MOV DI, 1; FLAG MOV CL, BYTE PTR [BX] DEC CL Inc BX MOV BYTE PTR [BX], Cl NOT_S: MOV CL, BYTE PTR [BX] Inc BX XOR CH, CH MOV SI, Offset Val16 MOV AX, 5 SUB AX, CX Add Ax, Ax Add Si, Ax; Si Point To the 'EA' XO R AX, AXLOOPER1: MOV CL, BYTE PTR [BX] xor Ch, Ch Inc BX SUB CX, 30H JCXZ NEXT1; LAB1: Add Ax, [Si] Loop Lab1Next1: Add Si, 2 CMP Si, Offset Val16 8 Jbe Looper1

CMP DI, 1 JZ IS_S2 JMP OK IS_S2: NEG AX OK: POP Si Pop Di Pop DX POP CX Pop BX Ret 2b Endp; ---------------------- ------------; Proc: IB2A; Input = (AX), DS: BX (bufhead); OUTPUT = DS: BX IB2A Proc Push AX Push CX Push DX Push Si Inc BX XOR CX, CX Test Ah, 80H JS IS_S3 JMP NOT_S3 IS_S3: MOV CX, 1 Neg Ax Not_S3: Push CX XOR DI, DI MOV SI, Offset Val16

LAB3: XOR CL, Cl, Cl, Cl, Cl, Cl, Cl, Cl, Cl, Cl, Cl, 2FH MOV BYTE PTR [BX] [DI], Cl Inc DI Add Ax, [Si] Add Si, 2 CMP Si , Offset Val16 8 Jbe Lab3 MOV BYTE PTR [BX 5], '$' CALL CUT0; -------------------- POP CX CMP CX, 1 ; '-'? JZ IS_S4 JMP NOT_S4 IS_S4: DEC BX MOV BYTE PTR [BX], '-' NOT_S4: POP Si Pop DX Pop CX Pop AX RET IB2A ENDP; ------------- -------------------; Proc: Dispmsg: Print A String in The Consoledispmsg Proc Push Ax Mov AH, 9 INT 21H POP AX Retdispmsg Endp; ------ ---------------------------; PORC: Newl: Print a line-feed newl proc push ax push dx Mov DL, 0DH MOV AH, 2 INT 21h MOV DL, 0AH MOV AH, 2 INT 21H POP DX POP AX RET NEWL ENDP; --------------------------------; proc: cut0; input = DS: BX (NUMSTR Head); OUTPUT = Cut The '0's in The Frontcut0 Proc Push Ax Lab: MOV Al, [BX] CMP AL, 30H JZ GoON1 JMP OK2 GoON1: Inc BX JMP LAB OK2: POP AX RET CUT0 ENDP; --------------------------; Proc: Echo: Print a Character in The Consolecho Proc Push Ax Mov AH, 2 INT 21h Pop Ax Retecho Endp ; --------------------------- CSEG Ends end

转载请注明原文地址:https://www.9cbs.com/read-59331.html

New Post(0)