Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .model small
- .stack 200H
- .data
- msg1 DB 10,13,'Enter limit: $'
- msg2 DB 10,13,'Enter the numbers: $'
- msg3 DB 10,13,'Sum = $'
- newline DB 10,13, ' $'
- sum DW 0
- .code
- printstring MACRO msg ;macro definition
- PUSH AX
- PUSH DX
- MOV AH,09H
- MOV DX,offset msg
- INT 21H
- POP DX
- POP AX
- ENDM
- .startup
- printstring msg1
- CALL readnumtoAX ;enter the limit
- MOV CX,AX ;cx?limit
- printstring newline
- printstring msg2
- label1: printstring newline
- CALL readnumtoAX ;enter the no.s
- ADD sum,AX ;sum=sum+ax
- DEC CX ;cx?cx-1
- JNZ label1
- printstring newline
- printstring msg3 ;print sum
- MOV AX,sum
- CALL displayAX
- .exit
- readnumtoAX PROC NEAR
- ;procedure def. For reading-
- PUSH BX ; char to ax register
- PUSH CX
- MOV CX,10
- MOV BX,00
- back: MOV AH,01H
- INT 21H
- CMP AL,'0'
- JB skip
- CMP AL,'9'
- JA skip
- SUB AL,'0'
- PUSH AX
- MOV AX,BX
- MUL CX
- MOV BX,AX
- POP AX
- MOV AH,00
- ADD BX,AX
- JMP back
- skip:
- MOV AX,BX
- POP CX
- POP BX
- RET
- readnumtoAX ENDP
- displayAX PROC NEAR
- ;procedure def. For display
- ;a character
- PUSH DX
- PUSH CX
- PUSH BX
- PUSH AX
- MOV CX,0
- back1: MOV BX,10
- MOV DX,0
- DIV BX
- PUSH DX
- INC CX
- OR AX,AX
- JNZ back1
- back2:
- POP DX
- ADD DL,30H
- MOV AH,02H
- INT 21H
- LOOP back2
- POP AX
- POP BX
- POP CX
- POP DX
- RET
- displayAX ENDP
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement