Advertisement
iocoder

pascal

Dec 10th, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; You may customize this and other start-up templates;
  2. ; The location of this template is c:\emu8086\inc\0_com_template.txt
  3.  
  4. org 100h
  5.  
  6.         CALL    READ
  7.         MOV     DH,AL   ;
  8.         SUB     DH,30H  ; DH = N
  9.        
  10.         MOV     DL,0AH  
  11.         CALL    PRINT
  12.         MOV     DL,0DH
  13.         CALL    PRINT
  14.        
  15.         ; *** INITIALIZATION ***
  16.         MOV     [701],0 ;I in 301
  17.         MOV     [702],0 ;J in 302
  18.         MOV     [703],0 ;K in 303
  19.         MOV     BH,DH   ;SPACE = BH
  20.        
  21.         MOV     CX,0    ; INIT CX =0
  22.        
  23.        
  24. LOOPX:  MOV     BL,1    ;BL = C
  25.         MOV     [701],CL;301 = I
  26.        
  27.         MOV     CL,BH
  28.        
  29.         MOV     DL,' '   ;LOOP FOR SPACE
  30. LOOPS:  CALL    PRINT
  31.         LOOP    LOOPS
  32.        
  33.         DEC     BH      ;SPACE--
  34.                            
  35.                            
  36.         MOV     CL,0    ;J=0
  37. LOOPP:  MOV     DL,BL   ;PRINT C
  38.         CALL    PRINTINT
  39.         MOV     DL,' '
  40.         CALL    PRINT
  41.        
  42.        
  43.         MOV     AL,[701]; AL = I
  44.         SUB     AL,CL   ; AL = I-J
  45.         MUL     BL      ; AX = AL*BL = C*(I-J)
  46.        
  47.         MOV     BL,CL   ; BL = J
  48.         INC     BL      ; BL = J+1        
  49.         DIV     BL      ; AL = AX/BL = C*(I-J)/(J+1)
  50.  
  51.         MOV     BL,AL
  52.        
  53.         INC     CL     ;=;
  54.         CMP     CL,[701]
  55.         JNG     LOOPP
  56.        
  57.         MOV     DL,0AH  
  58.         CALL    PRINT
  59.         MOV     DL,0DH
  60.         CALL    PRINT
  61.        
  62.         INC     [701]  ;=;
  63.         MOV     CL,[701]
  64.        
  65.         CMP     CL,DH  ;=;
  66.         JL      LOOPX
  67.         RET
  68.  
  69. PRINT:  MOV     AH,2H
  70.         INT     21H
  71.         RET
  72.  
  73. READ:   MOV     AH,1H
  74.         INT     21H
  75.         RET
  76.  
  77. PRINTINT:
  78.         ; DL = some integer
  79.         CMP     DL, 0
  80.         JNE     PINT1
  81.         MOV     DL, '0'
  82.         JMP     PRINT
  83.        
  84. PINT1:  ; store context
  85.         PUSH    AX
  86.         PUSH    BX
  87.         PUSH    CX
  88.         MOV     AL, DL
  89.         XOR     AH, AH    ; AX = num  
  90.         XOR     BX, BX    ; a counter
  91.         MOV     DL, 10
  92.        
  93.        
  94. PINT2:  ; while (num != 0)
  95.         CMP     AX, 0
  96.         JE      PINT3
  97.         DIV     DL          ; AL = AX/10 = num/10
  98.                             ; AH = AX%10 = num%10
  99.         MOV     800[BX], AH ; store the digit
  100.         INC     BX          ; increase the counter
  101.         XOR     AH, AH      ; keep AX = num
  102.         JMP     PINT2
  103.              
  104. PINT3:  ; now print the characters stored in the buffer
  105.         CMP     BX, 0
  106.         JE      PINT4
  107.         DEC     BX
  108.         MOV     DL, 800[BX]
  109.         ADD     DL, '0'
  110.         CALL    PRINT
  111.         JMP     PINT3
  112.        
  113. PINT4:  ; restore context
  114.         POP     CX
  115.         POP     BX
  116.         POP     AX
  117.         RET
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement