Mystofolyse
Weaksauce
- Joined
- Jun 25, 2006
- Messages
- 103
Hello, again. I'm still learning how computers work, and I've started a bit of assembly programming. AFAIK, an efficiently written assembly program will outperform a program performing the identical task in a higher language (perhaps depending on the complexity of said program?). Anyway, I'm curious about how to go about measuring the resource usage and overall processor utilization of both implementations. By the way, I understand the code of both programs below.
An assembly program (from MIPS Assembly Language Programming by Robert L. Britton (pp 20-21):
...and a C++ program accomplishing the identical task:
Again, any help is greatly appreciated!
An assembly program (from MIPS Assembly Language Programming by Robert L. Britton (pp 20-21):
Code:
.data # Data declaration section
Prompt: .asciiz "\n Please Input a value for N = "
Result: .asciiz "The sum of the integers from 1 to N is "
Bye: .asciiz "\n **** Adios Amigo - Have a good day ****"
.globl main
.text
main: # Start of code section
li $v0, 4 # system call code for Print String
la $a0, Prompt # load address of prompt in $a0
syscall # print the prompt message
li $v0, 5 # system call code for Read Integer
syscall # reads the value of N into $a0
blez $v0, End # branch to end if $v0 <= 0
li $t0, 0 # clear register $t0 to 0
Loop:
add $t0, $t0, $v0 # sum of integers in register $t0
addi $v0, $v0, -1 # summing integers in reverse order
bnez $v0, Loop # branch to loop if $v0 is != 0
li $v0, 4 # system call code for Print String
la $a0, Result # load address of message into $a0
syscall # print the string
li $v0, 1 # system call code for Print Integer
move $a0, $t0 # move value to be printed to $a0
syscall # print sum of integers
b main # branch to main
End:
li $v0, 4 # system call code for Print String
la $a0, Bye # load address of msg. into $a0
syscall # print the string
li $v0, 10 # terminate program run and
syscall # return control to system
# END OF PROGRAM
Code:
#include <iostream>
using namespace std;
int main(){
int num;
int solution;
cout << "\n Please Input a value for N = ";
cin >> num;
if( num > 0 ){
solution = 0;
while( num > 0 )
{
solution = solution + num;
num = num - 1;
}
cout << " The sum of the integers from 1 to N is " << solution
<< endl;
}else
cout << "\n **** Adios Amigo - Have a good day ****" << endl;
}
Again, any help is greatly appreciated!