riccardinofuffolo

Calcolatori elettronici - #502

Jun 20th, 2011
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. DIM EQU 6    
  2. .MODEL small
  3. .STACK
  4. .DATA        
  5.  
  6. ANNI DW 1945, 2008, 1800, 2006, 1748, 1600    
  7. RISULTATO DB DIM DUP(0)      
  8.  
  9. .CODE
  10. .STARTUP                                    
  11.  
  12. LEA SI, ANNI                ;
  13. LEA DI, RISULTATO           ; Parametri di input
  14. MOV BX, DIM                 ;
  15. CALL BISESTILI
  16.  
  17. .EXIT    
  18.  
  19. BISESTILI PROC    
  20.     PUSH AX
  21.     PUSH BX
  22.     PUSH CX
  23.     PUSH DX
  24.     ; SI e DI li salvo?
  25.    
  26.     MOV CX, BX                       ; Contatori fuori dai cicli, sennò cicli verso l'infinito.
  27.     BISESTO: MOV AX, [SI]            ; Pongo l'anno in DX AX
  28.              MOV DX, 0              
  29.              MOV BX, 100
  30.            
  31.              DIV BX                  ; Verifico se è divisibile per 100. Il resto è in DX
  32.              CMP DX, 0               ; E' divisibile per 100? Se sì / no, devo fare ulteriori test.
  33.              JE QUATTROCENTO         ; E' divisibile per 100, devo vedere se anche per 400.
  34.              JNE QUATTRO             ; Non è divisibile per 100, devo vedere se per 4. Niente JMP.
  35.            
  36.              QUATTROCENTO: MOV AX, [SI]       ; Analogo a prima.
  37.                            MOV DX, 0
  38.                            MOV BX, 400    
  39.                            DIV BX
  40.                            CMP DX, 0          ; Se arrivo qui è sicuramente divisibile per 100
  41.                            JE BISESTILE       ; Qui anche per 400.
  42.                            JNE NONBISESTILE   ; Qui non per 400. Non c'è bisogno di JMP.
  43.                          
  44.              QUATTRO:      MOV AX, [SI]       ; Tutto uguale
  45.                            MOV DX, 0
  46.                            MOV BX, 4
  47.                            DIV BX
  48.                            CMP DX, 0
  49.                            JNE NONBISESTILE   ; Mi risparmio un salto    
  50.            
  51.              BISESTILE:    INC [DI]           ; Se è bisestile o se l'ultimo salto fallisce, va qui
  52.            
  53.              NONBISESTILE: ADD SI, 2          ; Se non è bisestile passo al prossimo anno  
  54.                            INC DI             ; Occhio a non fare ADD DI, 2, sono byte!
  55.                            LOOP BISESTO       ; e ripeto il procedimento
  56.     POP DX
  57.     POP CX
  58.     POP BX
  59.     POP AX
  60.    
  61.     RET
  62. BISESTILI ENDP  
  63.  
  64. END
Advertisement
Add Comment
Please, Sign In to add comment