0

cofile.s:

.section .data
arr: 
    .long 333
    .long 111
    .long 666

.section .text
.global main
main:
    inc 1(arr)
    int $0x80
    mov $1, %rax
    int $0x80

fl.cpp:

#include <iostream>

int main() {
    //here you need to get an array from assembler
}

Codes are not working. This is just an examplede here.

the busybee
  • 10,755
  • 3
  • 13
  • 30
  • Please add code in code blocks. Please also add what is it that this code is supposed to do which it is not doing. What error are you getting when you run this code. Hope his helps :) Welcome to stackoverflow – sarmahdi Nov 15 '19 at 04:43
  • 1
    Also please mention _which_ assembler language you are referring to. There are some 50+ different versions. – Lundin Nov 15 '19 at 07:37
  • 1
    You can "cheat" by writing the needed functionality in C and let the compiler output the assembler. – the busybee Nov 15 '19 at 08:29
  • 1
    I'm thinking this would work, no? `extern long arr[3];`, then use it like normal. I access assembly code startup file functions and arrays occasionally in C on STM32 microcontrollers. Would have to find and review my code to be sure on the context I did it under, and the syntax. – Gabriel Staples Nov 15 '19 at 08:34
  • Yes, see the first line of the last code chunk in my answer here. I access a variable from an assembly file, in C. https://stackoverflow.com/a/54728097/4561887 – Gabriel Staples Nov 15 '19 at 08:38
  • Exaclty as @GabrielStaples mentioned, use `extern` if you really need to operate on array in static segment. But consider flipping the dependencies here - create your `main` function in C, then call function defined in ASM `void myAsmFunc(long arr[], size_t size)`. Then pass the array created in C, in global scope. – saleph Nov 15 '19 at 08:43

1 Answers1

0
extern long arr[3];

Then use it like normal in C or C++.

Gabriel Staples
  • 36,492
  • 15
  • 194
  • 265