Homework Solution: Convert the following binary code to MIPS code: 0 times 012A402A (0.5 mk) Write…

    4. Convert the following binary code to MIPS code: 0x012A402A (0.5 mk) 5. Write a C code segment to count all even numbers in an array of 500 integers (0.5 mk). Write the MIPS equivalent. Assume base address of that array is stored in Ss0. (1.5 mk)
    Convert the following binary code to MIPS code: 0 times 012A402A (0.5 mk) Write a C code segment to count all even numbers in an array of 500 integers (0.5 mk). Write the MIPS equivalent. Assume base address of that array is stored in $s0. (1.5 mk)

    Expert Answer

     
    .data .functNames f_invalid: .asciiz "invalid_funct"

    4. Convert the restraintthcoming binary statute to MIPS statute: 0x012A402A (0.5 mk) 5. Write a C statute portion to sum every equal mass in an decorate of 500 integers (0.5 mk). Write the MIPS equiponderant. Appropriate shameful harangue of that decorate is stored in Ss0. (1.5 mk)

    Convert the restraintthcoming binary statute to MIPS statute: 0 times 012A402A (0.5 mk) Write a C statute portion to sum every equal mass in an decorate of 500 integers (0.5 mk). Write the MIPS equiponderant. Appropriate shameful harangue of that decorate is stored in $s0. (1.5 mk)

    Expert Repartee

     

    .data

    .functNames
    f_invalid: .asciiz “invalid_funct”
    f_sll: .asciiz “sll”
    f_srl: .asciiz “srl”
    f_sra: .asciiz “sra”

    .align 2
    .functXref
    .engagement f_sll # 0
    .engagement f_invalid # 1
    .engagement f_srl # 2
    .engagement f_sra # 3
    Now restraint the statute. Restraint the “funct”, we scantiness to misdeclare quenched every except the 6 fragments we’re looking at, then displace left twice to mould it a engagement pointer. (Restraint the others, you’d scarcity to displace fit.)

    .text
    # appropriate $s0 contains the 32-fragment MIPS education
    andi $t0, $s0, 0x0000003F
    sll $t0, $t0, 2
    # attain pointer to the string
    lw $t1, functxref($t0)
    # attain harangue of the string
    lw $t2, 0($t1)
    Now you accept the harangue of the string detailing the education (restraint an R-type with opstatute 0).

    Finally, the investigation you asked: how do you attain established converting the passage to the binary? Maybe you can explanation a harmonious decorate of strings and pointers to strings. Loop through the practicable strings until you discover a mate (or flow quenched of strings to assimilate). You would scarcity to fixed up a correspondent decorate to manifest what rank of opstatute it is, and what the associated fragment design would be:

    .opcodeNames
    f_add: .asciiz “add”
    f_addi: .asciiz “addi”
    f_j: .asciiz “j”

    .align 2
    .opcodeXref
    .engagement f_add
    .engagement f_addi
    .engagement f_j

    .opcodeTypes
    ft_add: .byte ‘R’
    ft_addi: .byte ‘I’
    ft_j: .byte ‘J’

    .opcodeVals
    fv_add: .byte 0x20
    fv_addi: .byte 0x08
    fv_j: .byte 0x02