How do I pass the array size from a c function back to assembly?

  assembly, c++

I am able to pass the pointer and get the user’s integers, but I need to return the count back to print out the # of integers inputted.

I know it’s not returning what I want because it just prints out 100 afterward.

From the manager.asm

...
ARRAY_COUNT         equ     100
...
extern input_array
global manager
manager:

; Prologue
    push rbp     ; base pointer
    push rbx     ; stoping point for the pointer
    push r12     ; points to the beginning of the array
    push r13     ; holds ARRAY_COUNT
    push r14     ; running pointer
...
    mov rdi, r12                
    mov rsi, r13                
    call input_array          

From the input_array.cpp file

extern "C" {
    long int input_array(long int* array, long int count);
}
 
long int input_array (long int* array, long int count) {
    long int number;
    long int total_ints;
...
    for (int i; i < count; i++) {
        ...
        } else {
            array[i] = number;
            ++total_ints;
        std::cout << "You can enter up to " << count - total_ints... ;
        }
    }
    return (count - total_ints);     // Want to retun ARRAY_COUNT - # of entered integers
}

Source: Windows Questions C++

LEAVE A COMMENT