1).. 0x014C4820 0x21490020 0x00000000 0x1211FFFC 2).. *********************This is for non delayed branch******* *****Since Non delayed branch,Think as pc +4* offset****** # bne s0,s1,3 # for non delayed branch, jump 3 instructions from 0x400000(3* 4 = 12 =c) # so..0x40000c # bne s0,s1,-3 # for non delayed branch, jump -3 instructions from 0x40000c (-3* 4 = -12 =-c) # so 0x400000 ************************************** For Delayed Branch 0x400000 bne s0, s1, 3 =pc +4 +4*offset =0x400000 + 4 + 4*3 = 0x400010 0x40000c bne s0,s1,-3 =pc +4 +4*-3 = 40000C ? 8 = 400004 ************************************** 3).. number of occurences of words containing A = 6 B = 1 C = 2 D = 1 E = 6 F = 2 G = 1 H = 3 I = 4 J = 0 K = 1 L = 3 M = 1 N = 6 O = 5 P = 1 Q = 0 R = 2 S = 2 T = 6 U = 0 V = 0 W = 1 X = 1 Y = 2 4).. number of words start with A = 1 B = 1 C = 1 D = 1 E = 1 F = 0 G = 1 H = 0 I = 1 J = 0 K = 1 L = 0 M = 1 N = 0 O = 1 P = 1 Q = 0 R = 0 S = 0 T = 2 U = 0 V = 0 W = 0 X = 0 Y = 0 Z = 0 ## Code For the Problem 4## ########################################## # SOLUTION FOR PROBLEM 4. ## # Based on SOLUTION FOR PROBLEM 3(P.3) # # By modifying P.3 a little, # # You can get this easily, and fast # ########################################## # $t0 = location of the string # $t1 = hold scanned character # $s2 = holds the ascii value for a space(32) # $t3 = used for address computation # $s5 = used for starting address of TABLE2 for a word statistics # $s0 = holds the word length cnt # $s1 = holds the address for TABLE .data string: .asciiz "IN A DISTANT GALAXY EONS BEFORE THE CREATION OF THE MYTHICAL PLANET KNOWN \n" return: .asciiz "\n" newline: .asciiz "\n" word_msg: .asciiz " number of words containing \n" eq_msg: .ascii " = " .align 4 TABLE2: .space 104 # for word statistics .text .globl main main: la $t0, string # stores the address for string in $t0 la $s5, TABLE2 addi $s2, $0, 32 # stores the ascii value for space in $t2 ### addi $t4, $0, 1 LOOP: lbu $t1, 0($t0) # load the next charater beq $t1, $0, DONE # END of STRING nop beq $t1,$s2,RESETWLC # space nop addi $s0,$s0,1 #increment word length cnt. ###### Goal: Record the word Statistics at the TABLE2 ## ### Step1: Test For THE First Character################## ### Step2: Capitalize the Character ##################### ### Step3: Record Statistics at TABLE2################## ######################################################### ##Adding checking code for the first character on a word## ##If It is the first character, do updating ## ##O/W , just skip ####################################### addi $t5,$0,1 beq $s0,$t5,DO_UPDATE nop j NEXT ## SKIP_UPDATE, Not the first character on a word,so skip nop DO_UPDATE: ######## slti $t2, $t1, 97 # < 'a' // not a lower case. bne $t2, $0, CAPITAL_DONE slti $t2, $t1, 123 # 'z' + 1 // 97-122 lower case. beq $t2, $0, CAPITAL_DONE # $t2 =1 means , character is lower case. addi $t1, $t1, -32 CAPITAL_DONE: addi $t1, $t1, -65 # Set $t1 to table index. ( A->0, B->1, etc.) sltiu $t2, $t1, 26 # If $t1 is >= 26 then it's not a letter. beq $t2, $0, NEXT # Note that comparison above is unsigned. nop sll $t1, $t1, 2 # Scale index. add $t5, $s5, $t1 # Add index on to address of first element add $t9, $s4, $t1 lw $t6, 0($t5) addi $t6, $t6, 1 sw $t6, 0($t5) #SKIP_UPDATE: NEXT: addi $t0,$t0,1 #point next character. j LOOP nop RESETWLC: add $s0,$0,$0 # reset word length beq $s0,$0,PreviousSF nop NOCLEAR: nop PreviousSF: addi $t0,$t0,1 #point next character. j LOOP nop DONE: # print and Exit.. beq $s0,$0,PRINT nop PRINT: PW_LOOP_MAIN: la $a0,word_msg li $v0,4 syscall li $t1,0 li $t0,25 PW_LOOP: move $a0,$t1 addi $a0,$a0,65 li $v0,11 syscall la $a0,eq_msg li $v0,4 syscall add $t3,$0,$t1 # sll $t3,$t3,2 # multiply 4 to get byte address. add $t3,$t3,$s5 # get memory address.### TABLE 2 lw $a0,0($t3) # get Character information. li $v0,1 syscall la $a0,newline li $v0,4 syscall addi $t1,$t1,1 beq $t1,$t0,EXIT nop j PW_LOOP nop EXIT: addi $v0, $0, 10 syscall # Exits program jr $ra # nop