#I'm trying to run a routine test on this MIPS assembly #language proram. Scroll down to int CountBits (unsigned int a0) #and look at notes. # The main routine has been written for you. #Do not modify it in any way. # # ############################################################################ # Ones counter # The user will type in an integer. # the program will pass the integer to a function that will # count the number of binary bits that are "1". # ################################################################## ############ # Function CountBits(int) # # counts the one bits in an integer. # for example, it the input is "15" the output is "4" # # Arguments: # a0 input integer # # Returns # v0 the bit count of 1 bits # Other Register usage: # t0-t7 as required # S0-S7 as required #--------------------- # int Countbits(unsigned int a0) # { # int v0 = 0; #Note: Trying to translate thus # do { #pseudocode into MIPS assembly language # v0 += a0 & 1; #so that I can run it in my MIPS code below. # a0 >>= 1; # }while (a0); # return v0; # } #------------------- CountBits: #{the code goes here!} ############################################################################### do not modify below this line .data prompt: .asciiz "\nType in an integer: " ans: .asciiz "The number of one bits is: " .text .globl main main: la $a0,prompt #do{ syscall $print_string # cout<< prompt syscall $read_int # cin >> N; move $a0,$v0 jal CountBits # move $s0,$v0 # s0= CountBits(N) la $a0,ans syscall $print_string # cout << ans << s0; move $a0,$s0 syscall $print_int b main # }while (true)
Yes, I just need to figure out how to translate the C++ code given to MIPS assembly language so that I may use the translated code into my routine program, to get it running. Also, there's no other questions . This information would be helpful Jim. Ans again, thank you for your response.
It might be helpful if you take the "C" code and actually convert it back to pseudo code. For example: "int v0 = 0;" create a variable v0 and assign 0 to it. Then take and convert that pseudo code to assembly. I'm not familiar with MIPS assembly, but you could try to Google "MIPS assembly code" there is about 360,000 possible entries. This is one which might help AssemblyLanguageProgDoc.pdf. Jim