Question: Modify the read string procedure in the code below to read in a variable length string using Interrupt I / O not polling. Check its

Modify the "read string" procedure in the code below to read in a variable length string using Interrupt I/O not polling. Check its operation by reading in a string and examining it in the input buffer. You do not need to write the string out to the display but if you want to undertake that addition to the assignment using interrupt handling there will be a significant amount of extra credit. A few hints....... You will need a buffer to hold the string that is input. Normally this would be allocated by the calling program and passed as an argument to the read string procedure. The read string procedure introductory code would save the buffer address in a kernel data structure (in .kdata) along with the counter of the next character to be entered. How does main know when the data input is complete? The operating system would provide a wait/post mechanism to communicate the fact that the input is complete. This wait/post mechanism can be simulated by passing the read string routine the address of a control word in memory to signal the read complete. The word would contain 0 while the input is being handled. The word would be set to 1 when the read string is complete. The read string routine would save the address of this control word along with the buffer address and count in the read string data structure. When the NL is entered the read string would place a NULL in the buffer, set the control word to 1, and run the epilog code to restore registers. The main routine (on MARS) would test the control word for 1 in the wait loop since we do not have a real wait function in MARS. .text .globl readString readString: li $t0,0 read_loop: li $t1,0xFFFF0000 # Address of the keyboard poll_keyboard: lw $t2,0($t1) # Load the register andi $t2, $t2,1 # Check if input is ready beq $t2, $zero, poll_keyboard li $t3,0xFFFF0004 # Address of the keyboard lw $t4,0($t3) # Loads the input character li $t5,0x0A beq $t4, $t5, end_read sb $t4,0($a0) # Store the character at string addi $a0, $a0,1 # Move to the next position in the string j read_loop # Continues to read end_read: li $t6,0x00 # Null then terminates the string sb $t6,0($a0) # Store null character at the end jr $ra # Return from the function

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!