Nios/chrcpy

From ASMBits

Write a function that will copy one character from a string to a second string. Your function will be passed four parameters: The first two parameters specify the source string and character position. The third and fourth parameters specify the destination string and character position. Copy the character. (Don't consider null-termination, overflows, etc.)

int chrcpy (char *src, int src_pos, char *dst, int dst_pos);

Expected solution length: Around 5 lines.

Sample Input

chrcpy("hello", 1, "bye", 1)

Sample Output

"bye" -> "bee"

Write your solution here

x
 
1
Src: .string "hello"
2
.align 2   # Insert padding so it's easier to read.
3
Dst: .string "bye"
4
.global _start
5
_start:
6
    movia r4, Src
7
    movi r5, 1
8
    movia r6, Dst
9
    movi r6, 1
10
    call chrcpy
11
    1: br 1b    # Done
12
13
# Copy a character from one string to another
14
chrcpy:
15
    
16
    
Upload a source file...