Please convert C program to MIPS main int u v w k u s0 v

Please convert C program to MIPS

main() { int u, v, w, k; // u -> $s0, v -> $s1, w -> $s2, k -> $s3;

u = 2; v = 3; w = 4;

k = sum_square(u, v, w);

return;

}

int sum_square(int x, int y, int z)

{ int x2, y2, z2; // x2 -> $s0, y2 -> $s1, z2 -> $s2;

x2 = x * x; y2 = y * y; z2 = z * z;

return x2 + y2 + z2; }

Solution

.file \"tryu.c\" .text .globl main .type main, @function main: .LFB0: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 subq $16, %rsp movl $2, -16(%rbp) movl $3, -12(%rbp) movl $4, -8(%rbp) movl -8(%rbp), %edx movl -12(%rbp), %ecx movl -16(%rbp), %eax movl %ecx, %esi movl %eax, %edi movl $0, %eax call sum_square movl %eax, -4(%rbp) nop leave .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE0: .size main, .-main .globl sum_square .type sum_square, @function sum_square: .LFB1: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 movl %edi, -20(%rbp) movl %esi, -24(%rbp) movl %edx, -28(%rbp) movl -20(%rbp), %eax imull -20(%rbp), %eax movl %eax, -12(%rbp) movl -24(%rbp), %eax imull -24(%rbp), %eax movl %eax, -8(%rbp) movl -28(%rbp), %eax imull -28(%rbp), %eax movl %eax, -4(%rbp) movl -8(%rbp), %eax movl -12(%rbp), %edx addl %eax, %edx movl -4(%rbp), %eax addl %edx, %eax popq %rbp .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE1: .size sum_square, .-sum_square .ident \"GCC: (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4\" .section .note.GNU-stack,\"\",@progbits
Please convert C program to MIPS main() { int u, v, w, k; // u -> $s0, v -> $s1, w -> $s2, k -> $s3; u = 2; v = 3; w = 4; k = sum_square(u, v, w); r

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site