By the type of statements used ( ld
and dadd
), I believe this is MIPS-64 ( font that says dadd
is present in MIPS-64).
I have no experience with MIPS-64 and have worked little with the MIPS-32 Assembly, but this is my reading of the code:
ld
is load
(64-bit) and dadd
is signed add
(64-bit).
This code begins by declaring three variables: A, B, and C with the initial values 10
, 8
, and 0
. These variables are declared the size of a word. I'm not sure if this is 32 or 64 bits, but the code that follows only makes sense if they are 64-bit.
Log reads $zero
( r0
) give the value 0
and written in this log are ignored.
ld X, Y(Z)
loads in register X
the value in position Y + Z
(this works when accessing constant indexes of arrays). Since Z
is zero, load the position directly.
What this does is:
Load global variable A into r4
.
Load global variable B into r5
.
Add the two variables and save the result to r3
.
Save value in r3
in global variable C.
Stop execution.
That is, C = A + B
. Therefore, C ends with the value 18
.
The equivalent C code is:
#include <stdint.h>
int64_t A, B, C;
int main()
{
C = A + B;
// Ou o seguinte, que é equivalente:
// (&C)[0] = (&A)[0] + (&B)[0];
halt(); // Talvez implementado como for (;;) {}
// Embora imagino que o halt seja mais eficiente
}