Reputation: 26671
I can run this assembly code in my simulator but I get a linker warning
Linking...
ld: warning: cannot find entry symbol start; defaulting to 80020000
Post build...
Done
Why do I get this error with solely the assembly code and not with C code that does the same? How can I change my assembly to make the linker happy? I'd like to know which statements are not necessary so that I can have a minimal program?
I could comment out these statement (that I'm not sure what they do):
#.frame $fp,40,$31 # vars= 16, regs= 2/0, args= 16, extra= 0
#.mask 0xc0000000,-4
#.fmask 0x00000000,0
My code (that was translated from C) is
.file 1 "minimips.c"
# -G value = 8, Cpu = 3000, ISA = 1
# GNU C version cygnus-2.7.2-970404 (mips-mips-ecoff) compiled by GNU C version cygnus-2.7.2-970404.
# options passed: -msoft-float
# options enabled: -fpeephole -ffunction-cse -fkeep-static-consts
# -fpcc-struct-return -fcommon -fverbose-asm -fgnu-linker -msoft-float
# -meb -mcpu=3000
gcc2_compiled.:
__gnu_compiled_c:
.rdata
.align 2
$LC0:
.ascii "Result %d\000"
.text
.align 2
.globl main
.ent main
main:
#.frame $fp,40,$31 # vars= 16, regs= 2/0, args= 16, extra= 0
#.mask 0xc0000000,-4
#.fmask 0x00000000,0
subu $sp,$sp,40
sw $31,36($sp)
sw $fp,32($sp)
move $fp,$sp
jal __main
li $2,40
sw $2,16($fp)
li $2,40
sw $2,20($fp)
lw $2,16($fp)
lw $3,20($fp)
addu $2,$2,$3
sw $2,24($fp)
la $4,$LC0
lw $5,24($fp)
jal printf
move $2,$0
j $L1
$L1:
move $sp,$fp # sp not trusted here
lw $31,36($sp)
lw $fp,32($sp)
addu $sp,$sp,40
j $31
.end main
To begin with I'm just adding numbers. The C code was a+b=c.
When I translated a simpler program (without any includes) then I can create a project type assembly (and not combined C/asm).
It now compiles and runs without linker error (but it doesn't use printf
)
gcc2_compiled.:
__gnu_compiled_c:
.text
.align 2
.globl main
.ent main
main:
.frame $fp,40,$31 # vars= 16, regs= 2/0, args= 16, extra= 0
.mask 0xc0000000,-4
.fmask 0x00000000,0
subu $sp,$sp,40
sw $31,36($sp)
sw $fp,32($sp)
move $fp,$sp
jal __main
li $2,15 # 0x0000000a
sw $2,16($fp)
li $2,20 # 0x00000014
sw $2,20($fp)
lw $2,16($fp)
lw $3,20($fp)
addu $2,$2,$3
sw $2,24($fp)
move $2,$0
j $L1
$L1:
move $sp,$fp # sp not trusted here
lw $31,36($sp)
lw $fp,32($sp)
addu $sp,$sp,40
j $31
.end main
Upvotes: 0
Views: 576
Reputation: 179717
The C library defines a special symbol called start
which is where the program starts execution. The linker expects to find this symbol, which it will use as the program entry point.
You didn't define start
so the linker complains and gives you a default value. The default is probably the first instruction of your code, so that's why the program still works.
Upvotes: 3