Advertisement
NB52053

yyyyyyyyy

Sep 8th, 2018
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .model small
  2. .stack 200H
  3. .data
  4.      msg1 DB 10,13,'Enter limit: $'
  5.      msg2 DB 10,13,'Enter the numbers:  $'
  6.      msg3 DB 10,13,'Sum = $'
  7.      newline DB 10,13, ' $'
  8.      sum DW 0
  9.  
  10. .code
  11.     printstring MACRO msg     ;macro definition
  12.  
  13.                 PUSH AX
  14.                 PUSH DX
  15.                 MOV AH,09H
  16.                 MOV DX,offset msg
  17.                 INT 21H
  18.                 POP DX
  19.                 POP AX
  20.             ENDM
  21.  
  22. .startup
  23.  
  24.             printstring msg1          
  25.             CALL readnumtoAX       ;enter the limit
  26.             MOV CX,AX                    ;cx?limit
  27.             printstring newline            
  28.         printstring msg2
  29.        
  30.        
  31.        
  32. label1:      printstring newline
  33.             CALL readnumtoAX       ;enter the no.s
  34.                ADD sum,AX               ;sum=sum+ax
  35.             DEC CX                          ;cx?cx-1
  36.             JNZ label1                
  37.             printstring newline
  38.             printstring msg3            ;print sum
  39.             MOV AX,sum
  40.             CALL displayAX            
  41.        
  42. .exit
  43.  
  44.  
  45.  
  46.  
  47.  readnumtoAX PROC NEAR
  48.                                         ;procedure def. For reading-
  49.             PUSH BX            ; char to ax register    
  50.             PUSH CX
  51.                 MOV CX,10
  52.             MOV BX,00
  53.  back:     MOV AH,01H
  54.                  INT 21H
  55.                  CMP AL,'0'
  56.                   JB skip
  57.                  CMP AL,'9'
  58.                  JA skip
  59.                 SUB AL,'0'
  60.                 PUSH AX
  61.                 MOV AX,BX
  62.                 MUL CX
  63.                 MOV BX,AX
  64.                 POP AX
  65.                 MOV AH,00
  66.                 ADD BX,AX
  67.                 JMP back
  68.      skip:
  69.                  MOV AX,BX
  70.                  POP CX
  71.                  POP BX
  72.                  RET
  73.      readnumtoAX ENDP
  74.  
  75.  
  76. displayAX PROC NEAR
  77.                            ;procedure def. For display
  78.                            ;a character
  79.             PUSH DX
  80.             PUSH CX
  81.             PUSH BX
  82.             PUSH AX
  83.             MOV CX,0
  84. back1:      MOV BX,10
  85.             MOV DX,0
  86.             DIV BX
  87.             PUSH DX
  88.             INC CX
  89.             OR AX,AX
  90.             JNZ back1
  91. back2:
  92.             POP DX
  93.             ADD DL,30H
  94.             MOV AH,02H
  95.             INT 21H
  96.             LOOP back2
  97.             POP AX
  98.             POP BX
  99.             POP CX
  100.             POP DX
  101.             RET
  102. displayAX ENDP
  103.  
  104. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement