>> Tecnologia elettronica >  >> Telefoni >> Segreterie telefoniche

Programma assembly 8085: verificare se un numero è pari o dispari

Di seguito un programma 8085 pulito e commentato che legge un singolo numero da una routine di input simulata, testa il bit meno significativo e stampa «PARI» o «DISPARI». Presuppone un semplice display mappato in memoria a 2000H e una routine tastiera GETCHAR.

 ORG 1000H LXI SP, 2000H ; Stack pointer START: CALL GETNUM ; Restituisce cifra (0-9) in A ANI 01H ; Maschera tutto tranne LSB JZ PARI ; Se zero → pari ; --- DISPARI --- MVI C, 'D' CALL PUTCHAR MVI C, 'I' CALL PUTCHAR MVI C, 'S' CALL PUTCHAR MVI C, 'P' CALL PUTCHAR MVI C, 'A' CALL PUTCHAR MVI C, 'R' CALL PUTCHAR MVI C, 'I' CALL PUTCHAR JMP FINE PARI: MVI C, 'P' CALL PUTCHAR MVI C, 'A' CALL PUTCHAR MVI C, 'R' CALL PUTCHAR MVI C, 'I' CALL PUTCHAR FINE: HLT ;------------------------------------------------ ; Subroutine: GETNUM – leggi cifra ASCII, restituisci binario in A ;------------------------------------------------ GETNUM: CALL GETCHAR ; ASCII in A SUI '0' ; Converti '0'-'9' → 0-9 RET ;------------------------------------------------ ; Subroutine: PUTCHAR – output char in C a display mappato in memoria ;------------------------------------------------ PUTCHAR: MOV A, C STA 2000H ; Porta display RET ;------------------------------------------------ ; GETCHAR fittizio – sostituisci con la tua routine hardware ;------------------------------------------------ GETCHAR: MVI A, '5' ; Valore di test RET 

Come funziona

  1. ANI 01H isola il bit 0 (LSB).
  2. JZ PARI salta se LSB = 0 (pari).
  3. Altrimenti continua a stampare «DISPARI».
  4. Ogni carattere viene inviato a un display mappato in memoria a 2000H tramite PUTCHAR.

Adatta GETCHAR/PUTCHAR al tuo hardware specifico (SDK-85, simulatore, ecc.).

  1. Si Digita “00” (o “011”/“+”) per Chiamate Internazionali?
  2. Chi Risponde a Queste Domande?
  3. 12 Mbps sono sufficienti per 4-5 utenti? Dipende dall'uso
  4. Come fare una domanda su Answers.com da computer
  5. Idee per messaggi in segreteria
  6. Il numero 1-887-4997 è un numero di telefono valido?