Implementazione di un Driver MIPS per l'Interfacciamento di un Tastierino Alfanumerico
Input/Output
Scrivere nel linguaggio assembly del processore MIPS il driver per collegare un tastierino alfanumerico.
Il registro di stato RS e il registro dati RD dell'interfaccia hanno la seguente struttura:
- RS (8 bit): [R IE X X X X X X], dove R indica il bit di ready, IE il bit di Interrupt Enable.
- RD (16 bit): [ - - - - - - - - - - - - - - - - ], con MSB a sinistra e LSB a destra.
Si suppone che:
- Quando viene premuto un tasto, l'interfaccia scriva in RD il dato fornito dal tastierino e asserisca il bit R.
- Quando viene letto il contenuto di RD, l'interfaccia deasserisca il bit R.
- La sincronizzazione debba avvenire da programma.
### Task Breakdown
1. **Registers:**
- **RS (8-bit status register):**
- Bit 7: Ready (R)
- Bit 6: Interrupt Enable (IE)
- **RD (16-bit data register):**
- Contains the data from the keypad.
2. **Assumptions:**
- When a key is pressed, the interface writes the data from the keypad to `RD` and sets the `R` bit in `RS`.
- When the content of `RD` is read, the interface clears the `R` bit.
- Initially, `R = 0`.
- Synchronization must be handled by the program.
### Steps to Implement
1. Poll the `RS` register to check if the `R` bit is set.
2. If the `R` bit is set, read the data from `RD`.
3. Clear the `R` bit by reading `RD`.
4. Repeat the process.
### MIPS Assembly Code
Below is the MIPS assembly code that accomplishes this:
```assembly
.data
RS: .byte 0x00 # Status register RS initialized to 0
RD: .half 0x0000 # Data register RD initialized to 0
.text
main:
# Base addresses for RS and RD registers
la $t0, RS # Load address of RS into $t0
la $t1, RD # Load address of RD into $t1
polling_loop:
lb $t2, 0($t0) # Load byte from RS into $t2
andi $t2, $t2, 0x80 # Mask to isolate the R bit (bit 7)
beq $t2, $zero, polling_loop # If R bit is not set, keep polling
lh $t3, 0($t1) # Load halfword from RD into $t3 (read data)
# Clear the R bit by reading RD, automatically handled by hardware
# Assuming the R bit clears when RD is read, if not, we might need additional steps
# Here we assume it clears by the hardware automatically as per the problem statement
j polling_loop # Repeat the polling process
```
### Explanation
- **Data Section:**
- `RS` and `RD` registers are declared and initialized.
- **Text Section:**
- The main polling loop continuously checks if the `R` bit is set in the `RS` register.
- When the `R` bit is set, the code reads the data from the `RD` register.
- After reading `RD`, the hardware is assumed to clear the `R` bit as per the problem statement.
- The process repeats indefinitely in the polling loop.
This assembly code will keep checking for input from the keypad, read it when available, and handle the synchronization as required.
Commenti
Posta un commento