0

I'm trying to solve exercism.io problem on x86_64 assembly track and am stuck on segfault within the first test.

DEFAULT REL

section .rodata
string db "One for you, one for me.", 0

section .text
global two_fer
two_fer:
    mov rdi, [rsp + 8]
    mov rsi, [string]
    mov rcx, 1
    movsb
    ret

Test is as follows:

void test_no_name_given(void) {
    char buffer[BUFFER_SIZE];

    two_fer(NULL, buffer);
    TEST_ASSERT_EQUAL_STRING("One for you, one for me.", buffer);
}

Inspecting through gdb, it segfaults at movsb instruction.

Any ideas as to what is going wrong here?

jafarlihi
  • 322
  • 3
  • 9
  • 2
    Your function doesn't have 7 args so IDK what you expect to load from stack memory at `[rsp+8]`. The first 2 function args will be in RDI, RSI on entry to your function. Also, it seems you want `lea rsi, [string]`, not `mov` to load 8 ASCII chars from the array. Since you're already using GDB, look at registers when `movsb` executes: RDI and RSI need to be pointers to destination and source. – Peter Cordes Dec 19 '21 at 15:49

0 Answers0