Question

Implement the functionality of "main" function for the following C code in MIPS assembly. Comment your...

Implement the functionality of "main" function for the following C code in MIPS assembly. Comment your code including which registers represent the variables in the main function. Include the .data and the .text sections. Do not write the bit_count function.

int main() {

int count = 149;

int num = 432;

if (count + num > 534){

count = bit_count(num);

printf("%d bits to store the number", count);

}else{

printf("cannot count bit in %d",)

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

For above problem:

As ques says no need to write bit_count function so i assume to print the count value only.

.data
msg1: .asciiz "Enter the first number: "
msg2: .asciiz "\nEnter the second number: "
bitsStore: .asciiz "\nbits to store the number"
bitsNotStore: .asciiz "\ncannot count bit in "
result: .asciiz "\nThe result of addition is: "
comp: .word 534

.text
li $v0,4
la $a0,msg1 // taking input for count
syscall

li $v0,5
syscall
move $t1,$v0 // reading the count and loading to $t1

li $v0,4
la $a0,msg2 // taking input for num
syscall

li $v0,5
syscall
move $t2,$v0 // reading the count and loading to $t1

Add $t3,$t1,$t2 // adding count and num and storing result in $t3
lw $t0, comp // load comp value declared in .data section in $t0

bgt $t3, $t0, numberGreater // if (count+num > comp)
blt $t3, $t0, numberSmaller // if(count+num < comp)

numberGreater:
li $v0, 4
la $a0, bitsStore //printing msg
syscall

li $v0,1
move $a0,$t1 // according to question there is no need to write bit_count function
syscall // so just print the value of count

b exitLabel

numberSmaller
li $v0, 4
la $a0, bitsNotStore   //printing msg
syscall

li $v0, 1
move $a0,$t3 // print (count+ num) value
syscall

b exitLabel

exitLabel:

li $vo, 10
syscall

I above code i had take the input from user, according to the ques the values are pre defined as 149, 432, if you want to do so here is the code below:

.data

comp: .word 534

count: .word 149

num: .word 432

.text

w $t1, count

w $t2, num

lw $t0, comp

// and continue the above program code from add command onward...

There can be other ways to solve the question, if you have doubts then ask...

Add a comment
Know the answer?
Add Answer to:
Implement the functionality of "main" function for the following C code in MIPS assembly. Comment your...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • MIPS assembly language Implement the following code in MIPS int array [ ] {2, 3, 4,...

    MIPS assembly language Implement the following code in MIPS int array [ ] {2, 3, 4, 5, 6); int main) int num, position; scanf("%d",&num) ; position search(array, printf("The position is: num, 5); %d\n",positio int search(int array, int num, int size int position =-1; for(int i-0;i<size; i++) if(array [i]=num) { position-i; break; return position; Register map $s1: position $a0: array address $a1: num . $a2: size . $VO: return value

  • MIPS assembly language Covert this code to MIPS: #include <stdio.h> int function (int a) int main)i...

    MIPS assembly language Covert this code to MIPS: #include <stdio.h> int function (int a) int main)i int x=5 ; int y: y function(x); printf "yd",y); return 0; int function (int a) return 3*a+5; Assumptions: . Place arguments in $a0-$a3 . Place return values in $vO-$v1 Return address saved automatically in $ra . lgnore the stack for this example. (Thus, the function will destroy registers used by calling function

  • How can I convert the following C code to MIPS Assembly? +++++++++++++++++++++++++++++++++ MIPS main program ++++++++++++++++++++++++++++++++...

    How can I convert the following C code to MIPS Assembly? +++++++++++++++++++++++++++++++++ MIPS main program ++++++++++++++++++++++++++++++++ .data # Defines variable section of an assembly routine. array: .word x, x, x, x, x, x, x, x, x, x # Define a variable named array as a word (integer) array # with 10 unsorted integer numbers of your own. # After your program has run, the integers in this array # should be sorted. .text # Defines the start of the code...

  • Turn the Following c-code into MIPS assembly code. You are given the main procedure which calls...

    Turn the Following c-code into MIPS assembly code. You are given the main procedure which calls multiply. You are also given the argument registers to be used. /* C-program */ int multiply (int number, int times) { int f; f = number * times return f; } # MIPS PROGRAM # assumes we have called the program leaf_example # $a0=number, $a1=times, $s0=f main: $addi $a0,$zero,3 $addi $a1,$zero,2 jal multiply # place the address into $ra j EXIT2 EXIT2: j OS...

  • In mips code please Implement the following C code in MAL and develop a small main...

    In mips code please Implement the following C code in MAL and develop a small main program that tests your implementation on an integer array. You must use nested procedures in your implementation. int getArrAvg (int Arr) int sum0 for (int i = 0; i < 10; i += 1) sum-addfn (sum, Arr[i]) return sum/10; int addfn (int a, int b) return ab;

  • PLEASE USE VERY BASIC REGISTERS AND CODE TO DO THE FOLLOWING Objectives: -write assembly language programs...

    PLEASE USE VERY BASIC REGISTERS AND CODE TO DO THE FOLLOWING Objectives: -write assembly language programs to:             -define a recursive procedure/function and call it.             -use syscall operations to display integers and strings on the console window             -use syscall operations to read integers from the keyboard. Assignment Description: Implement a MIPS assembly language program that defines "main", and "function1" procedures. The function1 is recursive and should be defined as: function1(n) = (2*n)+9                      if n <= 5              =...

  • IN MIPS AND MUST RUN IN QTSPIM Translate the following C code to MIPS assembly code....

    IN MIPS AND MUST RUN IN QTSPIM Translate the following C code to MIPS assembly code. Use a minimum number of instructions. Assume that the values of a, b, i and j are stored in registers Ss0, Ss1, St0 and Stl, respectively. Also assume that register Ss2 holds the base address of the array D. for (i=0; i<a; itt) for (i-0j<b:jt+)

  • Translate the following C code into RISC-V Assembly. (no need to implement the prints just use...

    Translate the following C code into RISC-V Assembly. (no need to implement the prints just use ecall) int a[] = {2,2,5,3,4,8,3}; int b[] = {1,4,2,0,-1,5,4}; int z[7]; void multiply(int* a, int* b, int* c, int d) { for (int i=0; i < d; i++) { c[i] = a[i] * b[i]; } } int main() { int n = 7; multiply(a,b,z,n); printf("%s", "res: "); for (int i = 0; i < z; i++) { printf("%d", d[i]); } printf("\n"); return 0; }

  • 1. [2 points] Write a MIPS assembly language program of the following C function and the...

    1. [2 points] Write a MIPS assembly language program of the following C function and the code to call the function: int leaf_example (int g, h, i, j) { int f; f = (g + h) - (i + j); return f; مهه Arguments g, h, i, and j are passed to the function in registers $a0, $al, Şa2, and $a3, respectively while f in $50 (hence, need to save $50 on stack), and the result is to be stored...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT