Question: Writing a Base 6 4 Decoder program using MIPS with the format below: # # base 6 4 decode.s ( incomplete ) # # by

Writing a Base64 Decoder program using MIPS with the format below:
#
# base64decode.s (incomplete)
#
# by Deborah Pickett 2003-02-27
#
# This MIPS program reads lines of Base 64-encoded text from standard
# input, and outputs the decoded bytes to standard output.
#
# INSERT YOUR CODE AT THE POINT INDICATED BELOW.
#
# Data segment
#
.data
# Space to read a line into.
inbuffer: .space 80
# The Base 64 alphabet, in order.
sequence: .asciiz "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
#
# Text segment
#
.text
# Program entry.
main:
# The first byte we're expecting is byte 0 of a group of 4.
la $t9, byte0
# Read a string from standard input.
loop: li $v0,8
la $a0, inbuffer
li $a1,80
syscall
# Is this an empty line? Since SPIM can't detect when end of
# file has been reached, we need to use another way to indicate
# the end of the Base 64 data. We'll use a completely
# blank line for this.
lb $t0, inbuffer
# First character newline means there was no text on this line,
# so end the program.
beq $t0,10, alldone
# Walk along the string. Start at the beginning.
la $t8, inbuffer
# Go back to where we left off last time (byte 0,1,2 or 3).
jr $t9
# Get four characters at a time.
byte0: lbu $s0,0($t8)
add $t8, $t8,1
beq $s0,10, linedone
# Now up to byte 1.
la $t9, byte1
byte1: lbu $s1,0($t8)
add $t8, $t8,1
beq $s1,10, linedone
# Now up to byte 2.
la $t9, byte2
byte2: lbu $s2,0($t8)
add $t8, $t8,1
beq $s2,10, linedone
# Now up to byte 3.
la $t9, byte3
byte3: lbu $s3,0($t8)
add $t8, $t8,1
beq $s3,10, linedone
# Now all bytes in this block are read.
# Four Base64 characters are now in $s0, $s1, $s2, $s3.
bytesdone:
#
# DO NOT DELETE THIS LINE.
######
#
# PUT YOUR ANSWER HERE.
# Your answer should not modify $t8 or $t9, as they are used by
# the above code.
#
######
# DO NOT DELETE THIS LINE.
#
endgroup:
# Go back to do next bunch of four bytes. We're now expecting
# byte 0 of 4.
la $t9, byte0
j byte0
linedone:
# Line is finished; go get another one.
j loop
alldone:
# Exit.
li $v0,10
syscall

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!