| | |
Converting C to MIPS(SPIM)
Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2006
Posts: 2
Reputation:
Solved Threads: 0
Hey guys I know little of C (specializing in JAVA) and my data structures course asked that I transfer this into MIPS using $a and $v registers... any help would be awesome!
#include <stdlib.h>
void *(memset)(void *s, int c, size_t n) {
const unsigned char uc = c;
unsigned char *su;
for (su = s; 0 < n; ++su, --n) {
*su = uc;
}
return s;
}
void *(a_memmove)(void *dest, const void *src, size_t n) {
char *sc1;
const char *sc2;
sc1 = dest;
sc2 = src;
if (sc2 < sc1 && sc1 < sc2 + n) {
for (sc1 += n, sc2 += n; 0 < n; --n) {
*--sc1 = *--sc2;
}
} else {
for (; 0 < n; --n) {
*sc1++ = *sc2++;
}
}
return (dest);
}
char *(a_strcat)(char *dest, const char *src, size_t n) {
char *s;
for (s = dest; *s != '\0'; ++s)
;
for (; 0 < n && *src != '\0'; --n) {
*s++ = *src++;
}
*s = '\0';
return (dest);
}
#include <stdlib.h>
void *(memset)(void *s, int c, size_t n) {
const unsigned char uc = c;
unsigned char *su;
for (su = s; 0 < n; ++su, --n) {
*su = uc;
}
return s;
}
void *(a_memmove)(void *dest, const void *src, size_t n) {
char *sc1;
const char *sc2;
sc1 = dest;
sc2 = src;
if (sc2 < sc1 && sc1 < sc2 + n) {
for (sc1 += n, sc2 += n; 0 < n; --n) {
*--sc1 = *--sc2;
}
} else {
for (; 0 < n; --n) {
*sc1++ = *sc2++;
}
}
return (dest);
}
char *(a_strcat)(char *dest, const char *src, size_t n) {
char *s;
for (s = dest; *s != '\0'; ++s)
;
for (; 0 < n && *src != '\0'; --n) {
*s++ = *src++;
}
*s = '\0';
return (dest);
}
1st: please use code tags when posting code. If you don't know how to do that you can read the links in my signature.
2nd. Many compilers will produce assembly language printouts of the c code. Check your c compiler to see if it has options to do that. If not, I don't know MIPS assembly, so I can't help you.
2nd. Many compilers will produce assembly language printouts of the c code. Check your c compiler to see if it has options to do that. If not, I don't know MIPS assembly, so I can't help you.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Optimizing MIPS in SPIM (Assembly)
- MIPS language question2 pls help.. (Assembly)
- MIPS language question pls help.. (Assembly)
- Easy (I hope) MIPS (SPIM) Question (Assembly)
Other Threads in the Assembly Forum
- Previous Thread: newb and nasm
- Next Thread: First Timer and trying to learn the basics (Please help me ASAP)
Views: 5299 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for Assembly
3d 68hc11 6811 80386 :( adress array asm assembler assembly boot bootloader buffer compression cursor debug directory division docs dos draw emulator endtask error exceptions file int10h integer intel interrupt interrupts language loop newbie nohau osdevelopment print program range read remainder shape string text theory tsr x86






