PDA

View Full Version : [ASSEMBLY] Confronto 2 caratteri da tastiera


ShadyA&B
10-12-2009, 12:51
Salve,
sto impazzendo per trovare l'errore (sicuramente un'istruzione mancante) per attivare il doppio "if" che in assembly manca e si può emulare solo con l'istruzione di salto.

Devo richiedere da tastiera un carattere, se "m" deve stampare un messaggio al maschile, se "f" deve stampare un messaggio al femminile.

Ecco il codice completo che ho buttato giù:

; multi-segment executable file template.



data segment
; add your data here!
pkey db 13,10, "press any key...$"
mes_gen1 db 'Sei maschio o femmina? $'
mes_gen2 db 13,10, 'Inserisci m o f -> $'
mes_masch db 13,10,"Benvenuto nel mondo della programmazione assembly $"
mes_femm db 13,10, "Benvenuta nel mondo della programmazione assembly $"
ends

stack segment
dw 128 dup(0)
ends

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

; add your code here


;STAMPA DOMANDA
lea dx, mes_gen1
mov ah, 9
int 21h



;STAMPA RICHIESTA SCELTA
lea dx, mes_gen2
mov ah, 9
int 21h


;CHIEDI CARATTERE DA TASTIERA
mov ah,00h
int 16h

cmp al,'m'
je maschio
cmp al, 'f'
je femmina

maschio: lea dx, mes_masch
mov ah,9
int 21h

femmina: lea dx, mes_femm
mov ah,9
int 21h



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.

L'istruzione di salto je mi sembra giusta visto che c'è da confrontare un'uguaglianza...in "al" perchè quel tipo di interrupt salva in al il carattere immesso.. Però andando a compilare ed eseguire qualsiasi carattere immetto mi stampa entrambe le stringhe.. in pratica non riesco AD ATTIVARE il salto.

ShadyA&B
10-12-2009, 14:04
Ho risolto, praticamente non si può fare un "if-if" come in C, ma ci si deve per forza costruire una struttura "if sì, salta a sì, if no, salta a no, else fai questo".

Se può servire a qualcuno inserisco il codice finale

; multi-segment executable file template.



data segment
; add your data here!
pkey db 13,10, "press any key...$"
mes_gen1 db 'Sei maschio o femmina? $'
mes_gen2 db 13,10, 'Inserisci m o f -> $'
mes_masch db 13,10,"Benvenuto nel mondo della programmazione assembly $"
mes_femm db 13,10, "Benvenuta nel mondo della programmazione assembly $"
errore db 13,10, 'errore $'
ends

stack segment
dw 128 dup(0)
ends

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


; add your code here


;STAMPA DOMANDA
lea dx, mes_gen1
mov ah, 9
int 21h



;STAMPA RICHIESTA SCELTA
lea dx, mes_gen2
mov ah, 9
int 21h


;CHIEDI CARATTERE DA TASTIERA
mov ah,00h
int 16h


cmp al,'f'
je femmina
cmp al,'m'
je maschio

lea dx,errore
mov ah,9
int 21h
jmp continua

maschio:
lea dx,mes_masch
mov ah,9
int 21h
jmp continua

femmina:
lea dx,mes_femm
mov ah,9
int 21h
jmp continua

continua:
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.

umbescla
11-12-2009, 09:31
ciao ShadyA&B , vorrei iniziare a programmare in assembler Intel , che programmi , IDE o quantaltro utilizzi per programmare in assembler ?


grazie