c - How can I assemble a minimal working MIPS program? -
i can run assembly code in simulator linker warning
linking... ld: warning: cannot find entry symbol start; defaulting 80020000 post build... done
why error solely assembly code , not c code same? how can change assembly make linker happy? i'd know statements not necessary can have minimal program?
i comment out these statement (that i'm not sure do):
#.frame $fp,40,$31 # vars= 16, regs= 2/0, args= 16, extra= 0 #.mask 0xc0000000,-4 #.fmask 0x00000000,0
my code (that translated 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 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 i'm adding numbers. c code a+b=c.
update
when translated simpler program (without includes) can create project type assembly (and not combined c/asm).
it compiles , runs without linker error (but 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
the c library defines special symbol called start
program starts execution. linker expects find symbol, use program entry point.
you didn't define start
linker complains , gives default value. default first instruction of code, that's why program still works.
Comments
Post a Comment