|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Mar 2007
Messaggi: 688
|
[ASSEMBLY] Confronto 2 caratteri da tastiera
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ù: Codice:
; 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.
|
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Mar 2007
Messaggi: 688
|
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 Codice:
; 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.
|
|
|
|
|
|
#3 |
|
Member
Iscritto dal: Dec 2000
Città: emilia
Messaggi: 255
|
ciao ShadyA&B , vorrei iniziare a programmare in assembler Intel , che programmi , IDE o quantaltro utilizzi per programmare in assembler ?
grazie |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 14:24.



















