Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

mainNumPhrases: .word 4 mainPhrases: .word mainPhrase1 .word mainPhrase2 .word m

ID: 3553131 • Letter: M

Question

mainNumPhrases: .word 4 mainPhrases:    .word mainPhrase1    .word mainPhrase2    .word mainPhrase3    .word mainPhrase4    mainPhrase1:    .asciiz "abcdefghijklmnopqrstuvwxyz" mainPhrase2:    .asciiz "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdeabcdeABCDEXYXYXYZz" mainPhrase3:    .asciiz "1234567890-=`~!@#$%^&*()_+[]{}|';:,./?><" mainPhrase4:    .ascii "I have sworn upon the altar of God eternal hostility "    .ascii "against every form of tyranny over the mind of man. "    .asciiz "-- Thomas Jefferson."
For each phrase in the array: Write a program in SPIM
mainNumPhrases: .word 4 mainPhrases:    .word mainPhrase1    .word mainPhrase2    .word mainPhrase3    .word mainPhrase4    mainPhrase1:    .asciiz "abcdefghijklmnopqrstuvwxyz" mainPhrase2:    .asciiz "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdeabcdeABCDEXYXYXYZz" mainPhrase3:    .asciiz "1234567890-=`~!@#$%^&*()_+[]{}|';:,./?><" mainPhrase4:    .ascii "I have sworn upon the altar of God eternal hostility "    .ascii "against every form of tyranny over the mind of man. "    .asciiz "-- Thomas Jefferson."
For each phrase in the array: Write a program in SPIM
For each phrase in the array: Write a program in SPIM
For each phrase in the array: Write a program in SPIM

Explanation / Answer

the code is as follows:



.data


mainNumPhrases:

.word 4

mainPhrases:

.word mainPhrase1

.word mainPhrase2

.word mainPhrase3

.word mainPhrase4

  

mainPhrase1:

.asciiz "abcdefghijklmnopqrstuvwxyz"

mainPhrase2:

.asciiz "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdeabcdeABCDEXYXYXYZz"

mainPhrase3:

.asciiz "1234567890-=`~!@#$%^&*()_+[]{}|';:,./?><"

mainPhrase4:

.ascii "I have sworn upon the altar of God eternal hostility "

.ascii "against every form of tyranny over the mind of man. "

.asciiz "-- Thomas Jefferson."

colon_space:

.asciiz " : "

blank:

.asciiz "0 "

new_line:

.asciiz " "

intarray:

.space 26

.text


main :

la $t0,mainPhrases # load the address to $t0

la $s0,mainNumPhrases

lb $s0,0($s0) # initialise the number of phrases count

start:

lw $t1,0($t0) # Load address of first phrase to t1

loop:

li $s3, 0

lb $s1,0($t1) # load character to s1

add $t1,$t1,1 #increment the phrase pointer

beq $s1,$s3,next #next phrase

addi $s3,$s3,0x60

bge $s1,$s3,adjust # if character is larger than 60 then subtract 60, case sensitivity

back:

subi $s3,$s3,0x20

ble $s1,$s3,loop #not an alpahbet next char

addi $s3,$s3,0x1A

bgt $s1,$s3,loop #not a character

subi $s1,$s1,0x41 #extract the offest of the char fron A

la $t2,intarray #load array address

add $t2,$t2,$s1 #load the current count of that char

lb $s2,0($t2)

addi $s2,$s2,1 #increment

sb $s2,0($t2) $#store back

j loop


InfLoop : j InfLoop # stay here for infinite time


next:

addi $t0,$t0,4 #increment the phrase pointer array

sub $s0,$s0,1 #decrement the number of phrases

j print # print


adjust:

subi $s1,$s1,0x20 #decrease by 0x20 for case change

j back


print:

addi $v0,$0,4

move $a0,$t0

subi $a0,$a0,4

lw $a0,0($a0)

syscall # print the phrase

la $a0,new_line

addi $v0,$0,4

syscall

la $t2,blank

la $t3,intarray

li $s4,0x1A # 26 chars to print

addi $s2,$0,0x41 # first print A

continue_print:

subi $s4,$s4,1

sb $s2,0($t2)

addi $v0,$0,4 # command to print integer is 1 to be loade to $v0

move $a0,$t2

syscall   

la $a0, colon_space

syscall

addi $v0,$0,1

lb $a0,0($t3)

addi $t3,$t3,1

syscall # print the count

la $a0,new_line

addi $v0,$0,4

syscall

addi $s2,$s2,1

bgt $s4,$0,continue_print continue to print until all the chars are done

bgt $s0,$0, start

j InfLoop



hope it helps.....:)

if possible increase the points....it is a long problem ..thanks