![]() |
How to convert this C array code to MIPS Assembly language?
Hi all I'm working on a problem involving translating an example C array code into the MIPS version, but I'm not quite sure how to do it right. Here is the sample code:
example: int count(int a[], int n, int x) { int res=0; int i; for(i=0;i!=n;i++) if(a[i]==x) res=res+1; return res; } Here is what I have so far with my code according to what I understand. Any assistance would be appreciated! move $t0, $zero # register t0 = 0 move $t1, $zero # register t1 = 0 loop: sll $t2,$t0,2 #t2 = i * 4 add $t3,$a0,$t2 # $t3 = address of array a[] sw $zero, 0($t2) # array a[] = 0 bne $ # check the end of the loops |
Re: How to convert this C array code to MIPS Assembly language?
here is a small example that i made for you.
i do not use it as a function but as a single program. modify it to your needs. Code:
.data |
Re: How to convert this C array code to MIPS Assembly language?
You can do the MIPS conversion using ctomips.com I used it to check against my homework. It works pretty well.
|
| All times are GMT +5.5. The time now is 13:27. |