PLEASE FOLLOW THE INSTRUCTION
PLEASE FOLLOW THE INSTRUCTION. AND IF YOU DON'T KNOW, DON'T WASTE TIME.
This is very simple.
Here is the complete ARM Code for the given problem statement.
---------------------------------------------------- ARM Code --------------------------------------------------
AREA MagicSquare, CODE, READONLY
ENTRY
MOV r9, #0
MOV r8, #1
MOV r7, #0
MUL r6, r1, r1 ; r6 = N^2
ADD r6, r6, #1 ; r6 = N^2 + 1
MUL r6, r6, r1 ; r6 = N(N^2 + 1)
MOV r6, r6, LSR #1 ; r6 = N(N^2 + 1)/2
BL Initialize Rows0
MOVEQ r3, #0 Rows
LDRB r4, [r2], #1 ; r4 = element for row addition
ADD r3, r3, r4 ; acc row sums to r3
SUBS r5, r5, #1 ; decrement counter
BNE Rows Check_Rows
SUBS r7, r7, #1 ; row counter
BEQ Column_Init ; tested all rows successfully
CMP r3, r6 ; test for magic
MOVEQ r5, r1 ; reset counter
BEQ Rows0 ; test next row
B Done Column_Init
BL Initialize Columns0
MOVEQ r3, #0 Columns
LDRB r4, [r2], r1
ADD r3, r3, r4
SUBS r5, r5, #1
BNE Columns Check_Columns
SUBS r7, r7, #1
BEQ Diag_Init
CMP r3, r6
MOVEQ r5, r1
MOVEQ r2, #0x20000010
ADDEQ r2, r2, r8
ADDEQ r8, r8, #1
BEQ Columns0
B Done Diag_Init
BL Initialize Diags0
MOVEQ r3, #0
ADD r10, r1, #1
Diags LDRB r4, [r2], r10
ADD r3, r3, r4
SUBS r5, r5, #1
BNE Diags Diags1
CMP r3, r6
BNE Done
MOV r3, #0
MOV r2, #0x20000010
MOV r7, r1
SUB r7, r7, #1
ADD r2, r2, r7
SUB r10, r1, #1
MOV r5, r1 Diags2
LDRB r4, [r2], r10
ADD r3, r3, r4
SUBS r5, r5, #1
BNE Diags2
CMP r3, r6
MOVEQ r9, #0xFFFFFFFF
Done B Done
END
Step by step
Solved in 2 steps