Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# File: mlRemoveBlanks # Author: ************ # Date: mm/dd/yyyy # Purpose: Practice rotate & AND to remove spare blanks #-------------------------------------------------------------- # Write a MIPS assembler

# File: mlRemoveBlanks

# Author: ************

# Date: mm/dd/yyyy

# Purpose: Practice rotate & AND to remove spare blanks

#--------------------------------------------------------------

# Write a MIPS assembler program to remove the extra blanks from

# a string:

# INPUT: "Two bee ore knot too Bea that"

# PATTERN:00011000100011000010001100010000

# ROTATE: 00110001000110000100011000100000

# AND: 00010000000010000000001000000000

# RESULT:"Two bee ore knot too Bea that "

.data

.eqv SYS_PRINT_WORD 1 #word, byte, character

.eqv SYS_PRINT_FLOAT 2 #float

.eqv SYS_PRINT_DOUBLE 3 #double

.eqv SYS_PRINT_TEXT 4 #text (zero terminated)

.eqv SYS_INPUT_WORD 5 #input word

.eqv SYS_INPUT_FLOAT 6 #input float

.eqv SYS_PRINT_BIN 35 #print binary

.eqv SYS_EXIT 10 #terminate

# declare variables

.eqv BLANK 32

#12345678901234567890123456789012

text: .ascii "Two bee ore knot too Bea that"

end_text: .asciiz " "

result: .ascii " "

end_result: .asciiz " "

blank: .byte ' '

endl: .asciiz " "

endl2: .asciiz " "

.text

.globl main

main:

# Print starting text

la $a0, text

li $v0, SYS_PRINT_TEXT

syscall

# ----------------------------------------------------------------

# Create the bit pattern with a 1 where each blanks exists

# ----------------------------------------------------------------

# s7 = ending address for loop

# s1 = text address

# s0 = the bit pattern

loop1:

# shift pattern left

# get 'text' byte

# compare with BLANK

# set s0 bit0 for BLANK, else skip to noBlank, not setting bit0

noBlank:

# move to next character

# loop1 if not done (s1 != s7)

# print s0 pattern

# ----------------------------------------------------------------

# Duplicate bit pattern, Rotate left, AND the two patterns

# should be where extra blanks exist

# ----------------------------------------------------------------

# duplicate s0 pattern into s2

# rotate s2 left one bit

# print s2 rotate

# AND the two patterns: s2 & s0

# print the AND pattern

# ----------------------------------------------------------------

# Copy 'text' into 'result' for each zero bit in s3 pattern

# ----------------------------------------------------------------

# ending s7 'end_text' address

# source address 'text' in s0

# destination address 'result' in s1

loop2:

# rotate high bit to bit0

# test bit0

# skip if bit0 is 1

# get character at (s0)

# save character in (s1)

# advance s1 'result' address

skip:

# advance s0 'text' address

# loop2 if not done (s0 != s7)

# print 'result'

#---- terminate ---

exit:

li $v0, SYS_EXIT

syscall

#.end main

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PC Magazine Guide To Client Server Databases

Authors: Joe Salemi

1st Edition

156276070X, 978-1562760700

More Books

Students also viewed these Databases questions