Nios/load align

From ASMBits

Write a function that reads a 32-bit word from memory and returns it. The location to read is passed as the first parameter to the function. This pointer is not necessarily 4-byte aligned, but your function must emulate what an unaligned load would do, while only using properly aligned accesses,

int load (int* p);

Expected solution length: Around 15 lines.

Sample Input

Pointer: .word 1234

Sample Output

1234

The easiest method is probably to use a sequence of byte-sized loads, as byte-sized loads have no alignment requirements.

Write your solution here

x
 
1
.data
2
Pointer: .word 1234
3
.text
4
.global _start
5
_start:
6
    movia sp, 0x04000000
7
    movia r4, Pointer
8
    call load
9
    1: br 1b    # Done
10
11
.global load
12
load:
13
    
14
    
Upload a source file...