Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC run assembly program mac?

I am attempting to run the following code in terminal on my Mac:

.section, .data

format_string:
   .asciz "My favorite number is %d!"

number:
  .long 786

.section, .text
.globl main

main:
  pushl number
 pushl $format_string  
 call printf 
  addl $8, %esp

  pushl $0
  call exit

This code is in a file named favorite.s

I used the command "gcc favorite.s -m32" and am seeing the following message:

Undefined symbols for architecture i386:
  "_main", referenced from:
      start in crt1.10.6.o
  "exit", referenced from:
      main in ccUKdD8O.o
  "printf", referenced from:
      main in ccUKdD8O.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status

What am I doing wrong here? Thanks.

like image 251
zProgrammer Avatar asked Jul 09 '26 09:07

zProgrammer


1 Answers

Symbols have an underscore prepended to them on Mac OS X. Add a _ in front of main, exit, and printf in your program and try again!

like image 67
Carl Norum Avatar answered Jul 13 '26 18:07

Carl Norum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!