Arm/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
    .align 1
5
    .hword 416
6
    .string "V6T1Z4"
7
    .align 1
8
    .hword 604
9
    .string "K7L3N6"
10
    .align 1
11
    .hword 613
12
.align 2
13
PCode: .string "N2L3G1"
14
15
.text
16
.global _start
17
_start:
18
    ldr r0, =List
19
    mov r1, #1
20
    ldr r2, =PCode
21
    ldr r3, =519
22
    
23
    bl set_data
24
    1: b 1b  // done
25
26
set_data:
27
    
28
    
Upload a source file...