Guest User

Untitled

a guest
Apr 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Scrivere un programma assembly che:
  2. ;- carichi da tastiera un vettore di 9 elementi, ogni elemento e' un digit
  3. ;- Inserisca da tastiera una cifra
  4. ;- conti le occorrenze della cifra nel vettore
  5. ;- stampi a video il numero di occorrenze, se la cifra è presente nel vettore
  6. ;- stampi a video il messaggio NON TROVATO, se la cifra non è presente
  7. ;nel vettore
  8.  
  9. data segment
  10.     ; add your data here!
  11.     array db 9 dup(?)
  12.     ricerca db ?
  13.     messaggio1 db "Inserisci 9 cifre non separate da spazi: ", 13, 10, '$'
  14.     messaggio2 db 13, 10, "Inserisci una cifra da cercare all'interno delle cifre inserite: ", 13, 10, '$'
  15.     risultato1 db 13, 10,"la cifra e' stata trovata $"
  16.     risultato1pt2 db " volte$"
  17.     risultato2 db 13, 10,"la cifra non e' stata trovata$"
  18.     n_volte db '0' , '$'
  19.     pkey db 13, 10,"premi un tasto per continuare...$"
  20. ends
  21.  
  22. stack segment
  23.     dw   128  dup(0)
  24. ends
  25.  
  26. code segment
  27. start:
  28. ; set segment registers:
  29.     mov ax, data
  30.     mov ds, ax
  31.     mov es, ax
  32.  
  33.     ; add your code here
  34.     lea dx, messaggio1
  35.     mov ah, 9
  36.     int 21h
  37.  
  38.     mov cx, 9    
  39.     mov si, 0
  40.    
  41. inserimento: mov ah, 1
  42.              int 21h
  43.              mov array[si], al
  44.              sub array[si], 30h
  45.              inc si          
  46.              loop inserimento
  47.  
  48.     lea dx, messaggio2
  49.     mov ah, 9
  50.     int 21h
  51.  
  52.     mov ah, 1
  53.     int 21h
  54.     mov ricerca, al
  55.     sub ricerca, 30h
  56.    
  57.     mov cx, 9
  58.     mov si, 0
  59.  
  60.  
  61.        
  62.    
  63.  
  64. confronto:  cmp si, 9
  65.             je uscitaciclo
  66.             mov al, array[si]
  67.             sub cx, 1
  68.             inc si
  69.             cmp al, ricerca
  70.             jne confronto
  71.             inc n_volte    
  72.             cmp cx, 0
  73.             jne confronto
  74.  
  75.  
  76.  
  77. uscitaciclo:    mov al, '0'
  78.                 cmp al, n_volte[0]
  79.                 je ris2
  80.      
  81.      
  82.     lea dx, risultato1
  83.     mov ah, 9
  84.     int 21h
  85.     lea dx, n_volte
  86.     mov ah, 9
  87.     int 21h
  88.     lea dx, risultato1pt2
  89.     mov ah, 9
  90.     int 21h
  91.     jmp fine  
  92.      
  93.  
  94. ris2: lea dx, risultato2
  95.       mov ah, 9
  96.       int 21h
  97.                          
  98. fine:    lea dx, pkey
  99.          mov ah, 9
  100.          int 21h        ; output string at ds:dx
  101.    
  102.     ; wait for any key....    
  103.     mov ah, 1
  104.     int 21h
  105.    
  106.     mov ax, 4c00h ; exit to operating system.
  107.     int 21h    
  108. ends
  109.  
  110. end start ; set entry point and stop the assembler.
Add Comment
Please, Sign In to add comment