Thread: C code understandings conversion to assembly (MIPS)

  1. #16
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    So now just add in a counter.

    Why are you using such a stupid function? It's just:
    Code:
    void f(int a) {
        return a >= 1 ? 1 : a;
    }
    Last edited by john.c; 02-03-2024 at 09:54 AM.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  2. #17
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    How to add counters
    Code:
    int divide(int a)
    { 
        numcalls++;
        if (a > 1) {
              return divide (a/2);
                      }
        return a; 
    }
    
    int divide(int a)
    {
        for( ; a > 1 ; a /=2 ) {
            numloops++;
        }
        return a;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #18
    Registered User
    Join Date
    Jan 2024
    Posts
    25
    Quote Originally Posted by Salem View Post
    Show us what you have so far.
    Quote Originally Posted by john.c View Post
    So now just add in a counter.

    Why are you using such a stupid function? It's just:
    Code:
    void f(int a) {
        return a >= 1 ? 1 : a;
    }

    Thanks John , kindly why it's like this? I didn't get how my recursive function is equivalent to what you suggested .. could you illustrate please how it's same as my recursive function?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ to MIPS Assembly: how to approach
    By primoriscruor in forum C++ Programming
    Replies: 3
    Last Post: 11-29-2012, 08:46 AM
  2. MIPS Assembly Bubble Sort
    By cornfeller in forum Tech Board
    Replies: 17
    Last Post: 06-16-2012, 08:09 PM
  3. convert c programm to mips assembly
    By mariakat in forum Tech Board
    Replies: 8
    Last Post: 02-14-2011, 08:39 PM
  4. Converting C into MIPS Assembly
    By clag in forum C Programming
    Replies: 5
    Last Post: 02-13-2010, 07:48 PM
  5. A question of the MIPS assembly program
    By ok_good in forum Tech Board
    Replies: 0
    Last Post: 05-03-2006, 10:13 PM

Tags for this Thread