How to start the MIPS program without the main one and call the MIPS program from program C

Ask for a long time, sorry in advance. Well, that’s why I work with a few unusual limitations, so I haven’t found much help on the Internet yet. The main limitation is that I cannot use the emulator, and therefore I cannot use syscalls. I need to do a few things with MIPS and C and I don’t know enough about how these programs run to understand how to make them work the way I need them. First, according to my teacher’s instructions, I need to create a file called "rng.s". It also indicates that it should begin with the following code:

.abicalls
.option pic0
.globl rng, seed
.set nomips16

As I understand it, this means that I create two functions "rng" and "seed", and I do not need to create the main function. In the template provided for earlier tasks, there was a code that looked like this:

.ent main
.type main, @function

And I'm not sure if I need to do something like this here with my rng and seed functions. In addition, when I do not include the main one, the assembler throws an error. Later in the assignment I have to write a C program that calls the rng () function (the same one that is written in my MIPS program) and pass some values ​​to it. I don’t quite understand how to call rng () from my C program. First I tried this as follows:

#include<stdio.h>

int main(int argc, char* argv[])
{
    //int a, b, c are input from command line using atoi(argv)
    //i've tested it and that part works fine, so it not important
    rng(a, b, c);
    return 0;
}

Makefile, , , , main.

, , MIPS ? MIPS C?

, , . .

+4
1

, , , , . , , , , , , . , :

1: MIPS

, - - . . :

.abicalls
.option pic0
.globl main
.set nomips16
.ent main
.type main, @function

, main main.

, - Makefile , MIPS , . , , , (, ):

.abicalls
.option pic0
.globl rng, seed
.set nomips16
.ent rng
.type rng, @function

, .globl rng, seed. , (rng seed) , .

2: , MIPS C

C, , . , MIPS (a, b, c) $a0- $a2. , $v0, C. :

// C Program
//=========================
#include<stdio.h>
int main()
{
    printf("%d", rng(0));
    return 0;
}
//=========================

// MIPS program
//=========================
rng:
    addi $v0, $a0, 1
    jr   $ra
//=========================

C 1, rng(), 1 ( $a0, C 0) $v0 . printf rng, 1.

, . .

0

Source: https://habr.com/ru/post/1616926/


All Articles