Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- INCLUDE "EMU8086.INC"
- .MODEL SMALL
- .STACK 100H
- .DATA
- SUM DW 0
- TEMP DB ?
- INPUT DW ?
- OUTPUT DW ?
- COUNT DB 0
- DIVISOR DW 2
- CNT DW ?
- .CODE
- INDEC PROC ;FOR DECIMAL INPUT (STRING DIGITS TO DECIMAL)
- MOV AH,1
- INT 21H
- L1:
- SUB AL,48
- XOR AH,AH
- MOV INPUT, AX
- MOV AX,SUM
- MOV BX,10
- MUL BX
- ADD AX,INPUT
- MOV SUM, AX
- MOV AH,1
- INT 21H
- CMP AL, 13
- JNE L1
- RET
- INDEC ENDP
- OUTDEC PROC ;FOR DECIMAL OUTPUT (FORM INTEGER TO STRING)
- MOV AX,OUTPUT
- MOV BP,SP
- L2:
- XOR AX,AX
- XOR DX,DX
- MOV AX,OUTPUT
- MOV BX,10
- DIV BX
- MOV OUTPUT,AX
- ADD DX,48
- PUSH DX
- CMP OUTPUT,0
- JNE L2
- RE:
- POP DX
- MOV AH,2
- INT 21H
- CMP SP,BP
- JNE RE
- RET
- OUTDEC ENDP
- MAIN PROC
- MOV AX, @DATA
- MOV DS, AX
- CALL INDEC
- PRINTN
- MOV AX,SUM
- LOOP1:
- MOV BX,DIVISOR
- XOR DX,DX
- DIV BX
- CMP DX,0
- JE NEXT
- INC DIVISOR
- MOV AX,SUM
- JMP LOOP1
- NEXT:
- MOV CX,0
- MOV CNT,CX
- LOOP2:
- MOV SUM,AX
- INC CNT
- XOR DX,DX
- DIV BX
- CMP DX,0
- JE LOOP2
- MOV OUTPUT,BX
- CALL OUTDEC
- PRINT " "
- MOV CX,CNT
- MOV OUTPUT,CX
- CALL OUTDEC
- PRINTN
- INC DIVISOR
- MOV AX,SUM
- CMP DIVISOR,AX
- JG EXIT
- JMP LOOP1
- EXIT:
- MOV AH, 4CH
- INT 21H
- ENDP MAIN
- END MAIN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement