Nios/structstore

From ASMBits

Consider the following struct:

struct Codes {
	char postal_code[7];
	unsigned short area_code;
};

Write a function that will write to a given entry of an array of struct Codes. The first two function parameters specify the beginning of the array of structs and which array element to modify (index=0 is the first array element). The third and fourth parameters provide the new value of the postal_code and area_code fields.

You are guaranteed that postcode is a null-terminated string of no more than 6 characters (not including the NULL). Ensure the postal_code is also null-terminated (but do not modify any bytes after the null).

void set_data (struct Codes* array, int index, char *postcode, unsigned short areacode);


Expected solution length: Around 10 lines.

Sample Input

Write {"N2L3G1",519} into { {"M5S3G4",416}, {"V6T1Z4",604}, {"K7L3N6",613} } at position 1

Sample Output

{ {"M5S3G4",416}, {"N2L3G1",519}, {"K7L3N6",613} }

Write your solution here

x
 
1
.data
2
List:
3
    .string "M5S3G4"
4
    .hword 416
5
    .string "V6T1Z4"
6
    .hword 604
7
    .string "K7L3N6"
8
    .hword 613
9
.align 2
10
PCode: .string "N2L3G1"
11
12
.text
13
.global _start
14
_start:
15
    movia r4, List
16
    movia r5, 1
17
    movia r6, PCode
18
    movia r7, 519
19
    
20
    call set_data
21
    1: br 1b  # done
22
23
set_data:
24
    
25
    
Upload a source file...