1

How can I convert this to mips assembly code

M[][]= {{1, 2, 3, 4},{5, 6, 7, 8},{9, 10, 11, 12},{13, 14, 15, 16}}

should I break this array into two or what? like this?

M1: .byte 1, 2, 3, 4, 5, 6, 7, 8
M2: .byte 9, 10, 11, 12, 13, 14, 15, 16
1
  • you didn't "break" the array, it's still one sequence of bytes. the object created doesn't care for how many labels you had, and how many lines code you used to create it. the question is how to access these bytes, esp how to convert array access m[x][y] to the correct byte position (M1+4+y+x), and how to care for alignment Commented May 11, 2017 at 11:51

1 Answer 1

1

No, it's single continuous M array of 16 byte values (1-16). The "two MxN dimensions" are faked by the index mapping function fmap(n, m) = n*M + m, and then address of element(n, m) is M + fmap(m, n).

I.e. to fetch M[2, 3] from 4x4 array you calculate offset of element as 2*4 + 3 = 11 (if indices are going from 0 of course, as every decent low level programming language does, eat this pascal!), so this would be element with value 12 (last one in third group).

The computer memory is only "one-dimensional", so any more complex structure has to be mapped to it by the code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.