changing this IO MIPS program to work on a null terminating string

0

First off thank you for taking the time to help me out. I'm new to Comp Architecture and MIPS and am passionate about learning this stuff so excuse the noobiness. Secondly before you say there are other discussions opened discussing this topic- i've tried & they don't fit into the current problem. I'm trying to modify my current program to search for null terminated character. instead of what's occuring to check for only the 4 characters before it exits. I'm using the MARS IDE and the KeyBoard & Display MMIO for this assignment

I've tried changing main: to just load the buffer and not the space for the 4 chars.

I've looked at the polling loop and the Branch in the loop and the Bne in getNchar. Maybe its just not clicking with me

Here's my main.

# Program to input and output a 4 character field

# Data area
.globl main
.data
buffer: .space  80

    .text
main:   
# get 4 characters from the keyboard and save them in the buffer
    la  $a0, buffer 
    li  $a1, 4
    jal getNChar

# put 4 characters from the buffer to the display   
    la  $a0, buffer # no need to move the characters (redundant move for illustration only)
    li  $a1, 4
    jal putNChar

# Exit
    li      $v0, 10     
    syscall         

Here is my GetString (currently working for 4Chars)

# Get  n character procedure

# Memory mapped addresses of device fields.
.eqv kbInCtl 0xFFFF0000     # 0xFFFF0000 rcv contrl
.eqv kbInData 0xFFFF0004    # 0xFFFF0004 rcv data
.eqv dispOutCtl 0xFFFF0008  # 0xFFFF0008 tx contrl
.eqv dispOutData 0xFFFF000c # 0xFFFF000c tx data

# Pseudo code
#   $t0 = 0
#   while ($t0 < &a1) {
#       loop until character is available
#       move character to buffer address offset by $t0
#       $t0+=1
#       } 
#   return      

# buffer address in $a0
# number of characters to read in $a1
.globl getNChar
.text           
getNChar:       

    la     $t1,kbInCtl      # set up register for input control word
    li  $t2, 0          # initialize counter
loop:
    lw  $t3,0($t1)          # read rcv ctrl
    andi    $t3,$t3,0x0001      # extract ready bit
    beq $t3,$0,loop     # keep polling till ready
# move character    
    lb  $t4,kbInData        # read character into temporary register
    add $t5, $a0, $t2       # calculate store address
    sb  $t4, 0($t5)
    addi    $t2, $t2, 1     # increment counter
    slt $t5, $t2, $a1       # test for end of loop
    bne $t5, $zero, loop  
    jr  $ra         # if end do return

And here is my PutString (also working with 4 Chars rn)

# put N Characters procedure
# Memory mapped addresses of device fields.
.eqv kbInCtl 0xFFFF0000     # 0xFFFF0000 rcv contrl
.eqv kbInData 0xFFFF0004    # 0xFFFF0004 rcv data
.eqv dispOutCtl 0xFFFF0008  # 0xFFFF0008 tx contrl
.eqv dispOutData 0xFFFF000C # 0xFFFF000c tx data

# Pseudo code
#   $t2 = 0
#   while ($t2 < &a1) {
#       loop all previous output complete
#       move character from buffer address offset by $t2 to disp out word
#       $t2+=1
#       }
#   loop to be sure last character output before return 
#   return      

# buffer address in $a0
# number of characters to output in $a1
.globl putNChar
putNChar:       

    la      $t1,dispOutCtl  # set up register for output control word
    la  $t5,dispOutData
    li  $t2, 0      # initialize counter
#   j   output  
# loop until last character written out
loop:   lw  $t3,0($t1)  # read disp ctrl
    andi    $t3,$t3,0x0001  # extract ready bit 
    beq $t3,$0,loop     # poll till ready for next character
output: add     $t4, $a0, $t2   # calculate output byte address
    lbu $t6, 0($t4) # move byte to output field
    sw  $t6, ($t5)
    addi    $t2, $t2, 1 # increment counter
    slt     $t7, $t2, $a1   # test end of loop
    bne $t7, $zero, loop
    jr  $ra     # return
io
mips
mars-simulator
null-terminated
asked on Stack Overflow Oct 6, 2019 by Sam Berman

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0