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 subjoined binary jurisprudence to MIPS jurisprudence: 0x012A402A (0.5 mk) 5. Write a C jurisprudence limb to enumerate total uniform total in an arrange of 500 integers (0.5 mk). Write the MIPS equipollent. Feign low oration of that arrange is stored in Ss0. (1.5 mk)

    Convert the subjoined binary jurisprudence to MIPS jurisprudence: 0 times 012A402A (0.5 mk) Write a C jurisprudence limb to enumerate total uniform total in an arrange of 500 integers (0.5 mk). Write the MIPS equipollent. Feign low oration of that arrange is stored in $s0. (1.5 mk)

    Expert Exculpation

     

    .data

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

    .align 2
    .functXref
    .order f_sll # 0
    .order f_invalid # 1
    .order f_srl # 2
    .order f_sra # 3
    Now coercion the jurisprudence. Coercion the “funct”, we scantiness to misteach quenched total excepting the 6 parts we’re looking at, then remove left twice to gain it a order pointer. (Coercion the others, you’d want to remove fair.)

    .text
    # feign $s0 contains the 32-part MIPS counsel
    andi $t0, $s0, 0x0000003F
    sll $t0, $t0, 2
    # acquire pointer to the string
    lw $t1, functxref($t0)
    # acquire oration of the string
    lw $t2, 0($t1)
    Now you enjoy the oration of the string detailing the counsel (coercion an R-type with opjurisprudence 0).

    Finally, the topic you asked: how do you acquire working converting the extract to the binary? Maybe you can authentication a resembling arrange of strings and pointers to strings. Loop through the potential strings until you meet a competition (or flow quenched of strings to collate). You would want to regular up a concurrent arrange to mark what designation of opjurisprudence it is, and what the associated part shape would be:

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

    .align 2
    .opcodeXref
    .order f_add
    .order f_addi
    .order 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