In: Computer Science
Write the following assembly code file into C code.
.globl main
.text
main:
# Tests simple looping behaviour
li t0, 60
li t1, 0
loop:
addi t1, t1, 5
addi t0, t0, -1
bne t1, t0, loop
bne t1, zero, success
failure:
li a0, 0
li a7, 93 # a7 is what determines which system call we
are calling and we what to call write (64)
ecall # actually issue the call
success:
li a0, 42
li a7, 93
ecall
In your question, the code points to calling system call 93 which is to terminate the program but in comments you wrote you want to call 64 system call which is to to write.
I'm providing both the codes to suit your needs.
C Code to call write system call (64):
#include <stdio.h>
int main()
{
int t0 = 60;
int t1 = 6;
while(t1 != t0){
t1 = t1 + 5;
t0 = t0 - 1;
}
if(t1 == 0){
int a0 = 0;
printf("%d", a0);
}
else{
int a0 = 42;
printf("%d", a0);
}
}
C Code to call terminate system call (93):
#include <stdio.h>
int main()
{
int t0 = 60;
int t1 = 6;
while(t1 != t0){
t1 = t1 + 5;
t0 = t0 - 1;
}
if(t1 == 0){
int a0 = 0;
return 0;
}
else{
int a0 = 42;
return 0;
}
}