Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; You may customize this and other start-up templates;
- ; The location of this template is c:\emu8086\inc\0_com_template.txt
- org 100h
- CALL READ
- MOV DH,AL ;
- SUB DH,30H ; DH = N
- MOV DL,0AH
- CALL PRINT
- MOV DL,0DH
- CALL PRINT
- ; *** INITIALIZATION ***
- MOV [701],0 ;I in 301
- MOV [702],0 ;J in 302
- MOV [703],0 ;K in 303
- MOV BH,DH ;SPACE = BH
- MOV CX,0 ; INIT CX =0
- LOOPX: MOV BL,1 ;BL = C
- MOV [701],CL;301 = I
- MOV CL,BH
- MOV DL,' ' ;LOOP FOR SPACE
- LOOPS: CALL PRINT
- LOOP LOOPS
- DEC BH ;SPACE--
- MOV CL,0 ;J=0
- LOOPP: MOV DL,BL ;PRINT C
- CALL PRINTINT
- MOV DL,' '
- CALL PRINT
- MOV AL,[701]; AL = I
- SUB AL,CL ; AL = I-J
- MUL BL ; AX = AL*BL = C*(I-J)
- MOV BL,CL ; BL = J
- INC BL ; BL = J+1
- DIV BL ; AL = AX/BL = C*(I-J)/(J+1)
- MOV BL,AL
- INC CL ;=;
- CMP CL,[701]
- JNG LOOPP
- MOV DL,0AH
- CALL PRINT
- MOV DL,0DH
- CALL PRINT
- INC [701] ;=;
- MOV CL,[701]
- CMP CL,DH ;=;
- JL LOOPX
- RET
- PRINT: MOV AH,2H
- INT 21H
- RET
- READ: MOV AH,1H
- INT 21H
- RET
- PRINTINT:
- ; DL = some integer
- CMP DL, 0
- JNE PINT1
- MOV DL, '0'
- JMP PRINT
- PINT1: ; store context
- PUSH AX
- PUSH BX
- PUSH CX
- MOV AL, DL
- XOR AH, AH ; AX = num
- XOR BX, BX ; a counter
- MOV DL, 10
- PINT2: ; while (num != 0)
- CMP AX, 0
- JE PINT3
- DIV DL ; AL = AX/10 = num/10
- ; AH = AX%10 = num%10
- MOV 800[BX], AH ; store the digit
- INC BX ; increase the counter
- XOR AH, AH ; keep AX = num
- JMP PINT2
- PINT3: ; now print the characters stored in the buffer
- CMP BX, 0
- JE PINT4
- DEC BX
- MOV DL, 800[BX]
- ADD DL, '0'
- CALL PRINT
- JMP PINT3
- PINT4: ; restore context
- POP CX
- POP BX
- POP AX
- RET
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement