please write the following Y86 assembley instructions for the following C code. Please write in text so I can copy and paste.
* C Program to Solve the Magic Squares Puzzle without using
* Recursion
*/
#include <stdio.h>
void magicsq(int, int [][10]);
int main( )
{
int size;
int a[10][10];
printf("Enter the size: ");
scanf("%d", &size);
if (size % 2 == 0)
{
printf("Magic square works for an odd numbered sizen");
}
else
{
magicsq(size, a);
}
return 0;
}
void magicsq(int size, int a[][10])
{
int sqr = size * size;
int i = 0, j = size / 2, k;
for (k = 1; k <= sqr; ++k)
{
a[i][j] = k;
i--;
j++;
if (k % size == 0)
{
i += 2;
--j;
}
else
{
if (j == size)
{
j -= size;
}
else if (i < 0)
{
i += size;
}
}
}
for (i = 0; i < size; i++)
{
for (j = 0; j < size; j++)
{
printf("%d ", a[i][j]);
}
printf("n");
}
printf("n");
}
Expert Answer
The assembly instruction from the above given c code is given below:
.file 1 "" .section .mdebug.abi32 .previous .nan legacy .module fp=32 .module nooddspreg .abicalls .section .rodata.str1.4,"aMS",@progbits,1 .align 2 $LC0: .ascii "%d 00" .text .align 2 .globl magicsq .set nomips16 .set nomicromips .ent magicsq .type magicsq, @function magicsq: .frame $sp,56,$31 # vars= 0, regs= 7/0, args= 16, gp= 8 .mask 0x803f0000,-4 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro mult $4,$4 srl $3,$4,31 addiu $sp,$sp,-56 addu $3,$3,$4 sra $3,$3,1 movz $31,$31,$0 sw $16,28($sp) .cprestore 16 sw $31,52($sp) sw $21,48($sp) sw $20,44($sp) sw $19,40($sp) sw $18,36($sp) sw $17,32($sp) move $16,$4 mflo $7 li $6,1 # 0x1 move $2,$0 $L2: slt $4,$7,$6 bne $4,$0,$L13 sll $8,$2,5 bne $16,$0,1f div $0,$6,$16 break 7 1: sll $4,$2,3 addu $4,$4,$8 addu $4,$5,$4 sll $8,$3,2 addu $4,$4,$8 sw $6,0($4) mfhi $4 bne $4,$0,$L3 nop b $L4 addiu $2,$2,1 $L3: addiu $3,$3,1 beq $16,$3,$L9 addiu $2,$2,-1 bgez $2,$L4 nop b $L4 addu $2,$2,$16 $L9: move $3,$0 $L4: b $L2 addiu $6,$6,1 $L13: lw $19,%got($LC0)($28) move $17,$5 move $18,$0 addiu $19,$19,%lo($LC0) $L6: slt $2,$18,$16 beq $2,$0,$L14 move $21,$17 move $20,$0 $L8: slt $2,$20,$16 beq $2,$0,$L15 move $5,$19 lw $25,%call16(__printf_chk)($28) lw $6,0($21) .reloc 1f,R_MIPS_JALR,__printf_chk 1: jalr $25 li $4,1 # 0x1 addiu $20,$20,1 lw $28,16($sp) b $L8 addiu $21,$21,4 $L15: lw $25,%call16(putchar)($28) nop .reloc 1f,R_MIPS_JALR,putchar 1: jalr $25 li $4,10 # 0xa addiu $18,$18,1 lw $28,16($sp) b $L6 addiu $17,$17,40 $L14: lw $31,52($sp) lw $21,48($sp) lw $20,44($sp) lw $19,40($sp) lw $18,36($sp) lw $17,32($sp) lw $16,28($sp) lw $25,%call16(putchar)($28) li $4,10 # 0xa .reloc 1f,R_MIPS_JALR,putchar 1: jr $25 addiu $sp,$sp,56 .set macro .set reorder .end magicsq .size magicsq, .-magicsq .section .rodata.str1.4 .align 2 $LC1: .ascii "Enter the size: 00" .align 2 $LC2: .ascii "%d 00" .align 2 $LC3: .ascii "Magic square works for an odd numbered size 00" .section .text.startup,"ax",@progbits .align 2 .globl main .set nomips16 .set nomicromips .ent main .type main, @function main: .frame $sp,440,$31 # vars= 408, regs= 1/0, args= 16, gp= 8 .mask 0x80000000,-4 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro lw $5,%got($LC1)($28) addiu $sp,$sp,-440 lw $25,%call16(__printf_chk)($28) addiu $5,$5,%lo($LC1) .cprestore 16 movz $31,$31,$0 sw $31,436($sp) .reloc 1f,R_MIPS_JALR,__printf_chk 1: jalr $25 li $4,1 # 0x1 lw $28,16($sp) addiu $5,$sp,424 lw $4,%got($LC2)($28) lw $25,%call16(__isoc99_scanf)($28) nop .reloc 1f,R_MIPS_JALR,__isoc99_scanf 1: jalr $25 addiu $4,$4,%lo($LC2) lw $4,424($sp) lw $28,16($sp) andi $2,$4,0x1 bne $2,$0,$L17 nop lw $4,%got($LC3)($28) lw $25,%call16(puts)($28) nop .reloc 1f,R_MIPS_JALR,puts 1: jalr $25 addiu $4,$4,%lo($LC3) b $L20 nop $L17: lw $25,%got(magicsq)($28) nop .reloc 1f,R_MIPS_JALR,magicsq 1: jalr $25 addiu $5,$sp,24 $L20: lw $31,436($sp) move $2,$0 j $31 addiu $sp,$sp,440 .set macro .set reorder .end main .size main, .-main .ident "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.1) 5.4.0 20160609"