go to previous page   go to home page   go to next page hear noise

Answer:

Four levels deep: main calls doLines which calls convert which calls conCh.


main Subroutine

An advantage of modular programming is that each subroutine can be displayed and explained independently of the others. Each subroutine can also be tested independently of the others. (This is called unit testing).

Here is the design of  main.

         .text
         .globl  main
main:
         la      $a0,mainPr       # prompt the user
         li      $v0,4            # service 4
         syscall

         jal     doLines          # process lines of input
         
         li      $v0,10    
         syscall                  # return to QTSPIM 

         .data
mainPr:  .ascii  "Type each line of text followed by ENTER.\n"
         .asciiz "Type Q at the start of a line to finish.\n"

The main routine calls doLines. The flowchart shows the design for that routine. Below is its (incomplete) code.

# doLines -- read in and process each line of user input
#
# on entry:
#    $a0 -- address of the prompt text
#    $ra -- return address
#
# on exit:
#    no return values
Flowchart for doLines

         .text
         .globl  doLines
doLines:   
         sub     $sp,$sp,4        # push the return address
         sw      $ra,($sp)
 
loop:                             # get a line

         la      $a0,    # argument: address of buffer
         
         li      $a1,    # argument: length of buffer
         
         jal             # get line from user
         
         la      $a0,line         # if "Q"
         jal     testEnd          # return to caller
         beqz    $v0,endloop          

                                  # convert to capitals
                                  
         la      $a0,    # argument: address of buffer
         
         li      $a1,    # argument: length of buffer
         
         jal             # convert
         
         
         la      $a0,outline      # print out the result
         li      $v0,4
         syscall
         
         b       loop             # continue with next line
         
endloop:          
         lw      $ra,($sp)        # pop return address
         add     $sp,$sp,4         
         jr      $ra              # return to caller 

         .data
outline: .ascii  ":"              # pad so output lines 
                                  # line up with input
line:    .space  132              # input buffer

QUESTION 25:

Fill in the blanks.


go to previous page   go to home page   go to next page