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

Hi everyone, I am trying to find a way to read in a 32-bit binary number into a

ID: 3763046 • Letter: H

Question

Hi everyone, I am trying to find a way to read in a 32-bit binary number into a register and do operations such as; negation, add two binary numbers, and print the results. This is what i have so far: ################################################################### ###################################################################

.data .align 2 jumptable: .word top, case1, case2, case3, case4, case5, case6, case7, case8, case9, case10

vector1: .word 1,0,1,1,1,1,0,0,1,1,1,1,1,0,0,0,0,0,1,0

vector2: .word 1,1,1,0,1,1,1,0,1,0,1,0,1,0,1,1,1,0,1,1

vector3: .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

menu: .ascii " 1.) Vector1 (+) Vector2. "

.ascii "2.) Vector1 (<--) Vector2 "

.ascii "3.) Vector1 (<-->) Vector2 "

.ascii "4.) Vector1 (/) Vector2 "

.ascii "5.) Vector1 (/) Vector2 "

.ascii "6.) Copy Vector3 to Vector2 "

.ascii "7.) Copy Vector3 to Vector1 "

.ascii "8.) Negate Vector1 "

.ascii "9.) Negate Vector2 "

.asciiz "10.) Exit " vec3_prompt: .asciiz " Vector3= "

copied_vec2: .asciiz " Vector3 has been copied to Vector2: "

copied_vec1: .asciiz " Vector3 has been copied to Vector1: "

neg_vec1: .asciiz " The Negated value of Vector1: "

neg_vec2: .asciiz " The Negated value of Vector2: "

blank: .asciiz " "

##############################################################################

.globl main .text

main:

top: li $v0, 4 #Prompt to display menu

la $a0, menu syscall li $v0, 5 #Reads menu choice

syscall

blez $v0, top #go back to menu if choice is less than or equal zero

bgt $v0, 10, top #go back to menu if choice is greater than 5

la $a1, jumptable #read address for jumptable

sll $t0, $v0, 2 #word offset

add $t1, $a1, $t0 #pointer to jumptable

lw $t2, 0($t1) #load an address from jumptable

jr $t2 #jump to specified case ##############################################################################

case1:

li $v0, 4

la $a0, vec3_prompt

syscall li $v0, 35

move $a0, $t1

syscall b top

##############################################################################

case2:

##############################################################################

case3:

##############################################################################

case4:

###############################################################################

case5:

###############################################################################

case6:

###############################################################################

case7:

###############################################################################

case8:

###############################################################################

case9:

Explanation / Answer

Here are three methods for implementing the logic
1. USe read32BitNumber function to read a 32 bit binary number.
2. To perform sum..call this function twice. and store value in a variable required
3. To negate the number, use negate function.
4. To add two numbers, use add function.

public void read32BitNumber()
{
final int number = 5;

try (DataInputStream myStream = new DataInputStream(new FileInputStream(file))) {
    for (int i = 0; i < number; i++) {
        int number_32 = myStream.readInt();
        System.out.println(Integer.toBinaryString(number_32));
    }
}
}

publiv void negate(int number_32)
{
int negated = ~number_32;
    int maskingValue = ~0 >>> 1;
    logger.info("Mask for negation is [" + Integer.toBinaryString(maskingValue) + "]");
    return negated & mask;
}

static String add(double number_32_1, double number_32_2) {
        System.out.println(a + "first val :" + b);
        int a1 = (int) number_32_1;
        int b1 = (int) number_32_2;
        String s1 = Integer.toString(a1);
        String s2 = Integer.toString(b1);
        int number0 = Integer.parseInt(s1, 2);
        int number1 = Integer.parseInt(s2, 2);

        int sumOfNumbers = number0 + number1;
        String sumString = Integer.toBinaryString(sumOfNumbers);

        return sumString;
    }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote