Type of instructions used (ld
and dadd
), I believe this is MIPS-64 (source who says that the dadd
is present in MIPS-64).
I have no experience with the MIPS-64 and I have worked little with the MIPS-32 Assembly, but this is my code reading:
ld
is load
(64-bit) and dadd
is signed add
(64-bit).
This code starts by declaring three variables: A, B and C with initial values 10
, 8
and 0
. These variables are declared with the size of a word. I’m not sure if that’s 32 or 64 bits, but the code that follows only makes sense if it’s 64 bits.
Log readings $zero
(r0
) give the value 0
and written in this record are ignored.
ld X, Y(Z)
click on the log X
the value at the position Y + Z
(this is handy when you are making accesses to constant arrays indexes). Since Z
is zero, carries the position directly.
What this does is:
- Load the global variable A in the log
r4
.
- Load the global variable B in the record
r5
.
- Add the two variables and save the result in
r3
.
- Store the value in
r3
in global variable C.
- Stop the execution.
That is to say, C = A + B
. So C kills 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
}