Visualizzazione dei risultati da 1 a 8 su 8
  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2010
    Messaggi
    26

    [Assembler] problema nell'acquisire stringa da tastiera

    Ciao a tutti, ho un problema su un esercizio, uso come programma l'emu 8086

    La traccia mi chiede di acquisire il mio nome da tastiera e memorizzarlo nel vettore NOME.

    Ho provato in questo modo:

    ; multi-segment executable file template.

    data segment
    DIM EQU 10
    NOME db 0

    ; add your data here!
    pkey db "press any key...$"
    ends

    stack segment
    dw 128 dup(0)
    ends

    code segment
    start:
    ; set segment registers:
    mov ax, data
    mov ds, ax
    mov es, ax



    mov ax, 0
    mov cx, 10
    mov si, 0
    ciclo: mov ah, 1
    int 21h
    mov NOME[si], al
    inc si
    loop ciclo


    ; add your code here

    lea dx, pkey
    mov ah, 9
    int 21h ; output string at ds:dx

    ; wait for any key....
    mov ah, 1
    int 21h

    mov ax, 4c00h ; exit to operating system.
    int 21h
    ends

    end start ; set entry point and stop the assembler.



    In questo modo dopo aver eseguito , riesco ad acquisire il nome, però mi escono dopo il nome alcune lettere ripetute, che sostituiscono in parte la scritta "press any key" , in questo modo: http://i46.tinypic.com/hvze68.jpg

    come posso risolvere?

  2. #2
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,466

    Re: [Assembler] problema nell'acquisire stringa da tastiera

    Devi fare in modo che la stringa sia terminata da $

    Le correzioni in rosso

    codice:
    ; multi-segment executable file template.
    
    data segment
        DIM EQU 11
        NOME db dup(DIM)
        
        ; add your data here!
        pkey db "press any key...$"
    ends
    
    stack segment
        dw   128  dup(0)
    ends
    
    code segment
    start:
    ; set segment registers:
        mov ax, data
        mov ds, ax
        mov es, ax
    
        mov ax, 0
        mov cx, 10
        mov si, 0
    ciclo:  mov ah, 1
        int 21h  
        mov NOME[si], al
        inc si
        loop ciclo
        mov al,'$'          
        mov NOME[si], al
    
        ; add your code here
                
        lea dx, pkey
        mov ah, 9
        int 21h        ; output string at ds:dx
        
        ; wait for any key....    
        mov ah, 1
        int 21h
        
        mov ax, 4c00h ; exit to operating system.
        int 21h    
    ends
    
    end start ; set entry point and stop the assembler.
    P.S. Devi postare il codice usando i tag CODE ...
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  3. #3
    Utente di HTML.it
    Registrato dal
    Jan 2010
    Messaggi
    26
    grazie mille, in effetti ci avevo pensato ma non mi veniva in mente come fare

    scusate se non ho postato bene il codice ^^

  4. #4
    Utente di HTML.it
    Registrato dal
    Jan 2010
    Messaggi
    26
    scusate l'ho riprovato, ma non funziona, ora non stampa più press any key ma ripete sempre le lettere..

  5. #5
    Utente di HTML.it
    Registrato dal
    Jan 2010
    Messaggi
    26
    risolto, non avevo impostato il valore di cx prima del loop

  6. #6
    Utente di HTML.it
    Registrato dal
    Jan 2010
    Messaggi
    26
    altro problema. l'esercizio richiedeva anche di acquisire 5 elementi per un vettore e farne la media.
    va tutto bene, ma dopo che eseguo mi stampa sullo schermo "media: T" com'è possibile? come risolvo?

    codice:
    ; multi-segment executable file template.
    
    data segment
        DIM EQU 10
        NOME db  10 dup(?)
        msg db "Inserire nome e cognome: $"
        DIM EQU  5
        NUM db 0
        msg_2 db "Inserire numeri del vettore: $"
        d db 5  
        msg_3 db "Media: $ "
        ; add your data here!
        pkey db "press any key...$"
    ends
    
    stack segment
        dw   128  dup(0)
    ends
    
    code segment
    start:
    ; set segment registers:
        mov ax, data
        mov ds, ax
        mov es, ax
        
        
        lea dx, msg
        mov ah, 9
        int 21h
        
        mov ax, 0
        mov cx, 10
        mov si, 0
    ciclo:mov ah, 1
          int 21h  
          mov NOME[si], al
          inc si
          loop ciclo  
          
          mov dl, 13
          mov ah, 2
          int 21h
          mov dl, 10
          mov ah, 2
          int 21h
          
          lea dx, msg_2
          mov ah, 9
          int 21h 
             
            mov ax, 0
            mov cx, 5
            mov si, 0
    ciclo2: mov ah, 1
            int 21h 
            sub al,48
            mov NUM[si], al
            inc si
            loop ciclo2 
           
           
          mov dl, 13
          mov ah, 2
          int 21h
          mov dl, 10
          mov ah, 2
          int 21h 
           
          
          
            
          mov ax, 0
          mov cx, 5
          mov si, 0  
    media:add al, NUM[si] 
          inc si
          loop media  
          div d
             
          
          
          lea dx, msg_3  
          mov ah, 9
          int 21h 
          
          add al, 48
          mov dl, al 
          mov ah, 2
          int 21h
          
        
                  
          
        ; add your code here
                
        lea dx, pkey
        mov ah, 9
        int 21h        ; output string at ds:dx
        
        ; wait for any key....    
        mov ah, 1
        int 21h
        
        mov ax, 4c00h ; exit to operating system.
        int 21h    
    ends
    
    end start ; set entry point and stop the assembler.

  7. #7
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,466
    Dovresti aprire un nuovo thread, anche se si tratta dello stesso programma, il problema è diverso da quello espresso nel titolo.

    E poi ... che fine hanno fatto le modifiche che ti avevo suggerito'

    Commenta un po' il codice ... qual è il range dei valori in input ? Come calcoli la media ? Come stampi il risultato ?
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  8. #8
    Utente di HTML.it
    Registrato dal
    Jan 2010
    Messaggi
    26
    apro un altro topic.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.