I'm attempting to test an assembly file compiled from my c++ program and I keep getting errors. My program is a simple "hello world" but no matter what I try and what variation of assembly files I try I can't get a solid run on anything bu the exception.s that comes with SPIM. Here is what I do:

-write quick cpp file
-Compile using: g++ file.cpp -S
-open file.s in SPIM

And I get the following error:

spim: (parser) syntax error on line 2 of file c:\Users\Dan\Desktop\file.s
                     .mod_init_func
                    ^

This line reads:

1     .mod_init_func
2     .align 3
3     .quad__GLOBAL__I_main

Aside from getting this specific error fixed, can someone please tell me how to compile and simulate a program without errors ocurring?

Also, when I just double click a .s file to open it in SPIM, it says the file can't be opened. Any reason why?

Edited 6 Years Ago by dansnyderECE: n/a

I'm sortof new to using g++, do you mean what is my Makefile? Here it is:

##############################################################################
#  \author acc@cs.rochester.edu
#  \version 0.01
#  \brief
##############################################################################

# Environment variables which should already be set in your path
# ACC_PATH ?= $(shell `pwd | awk 'BEGIN{FS="benchmarks/acc"} {print $1}'`)
# BENCHDIR ?= $(ACC_PATH)/benchmarks
# SESCSOURCEDIR ?= $(ACC_PATH)/sesca
# SESCBUILDDIR ?= $(ACC_PATH)/build
XTOOLSPREFIX ?= ~/Desktop/cmplrs

##############################################################################

# Compiler and linker
CC     = $(XTOOLSPREFIX)/bin/mipseb-linux-gcc
CXX    = $(XTOOLSPREFIX)/bin/mipseb-linux-g++
LD     = $(XTOOLSPREFIX)/bin/mipseb-linux-gcc
AR     = $(XTOOLSPREFIX)/bin/mipseb-linux-ar
RANLIB = $(XTOOLSPREFIX)/bin/mipseb-linux-ranlib

# Common compiler flags
CFLAGS = -O3 -funroll-loops -fsched-interblock \
	 -finline-functions -fomit-frame-pointer -funroll-loops \
	 -mips2 -mabi=32 -mtune=r8000 -static -Wa,-non_shared \
         -mno-abicalls -fno-PIC -freduce-all-givs \
	 -I. -I$(SESCSOURCEDIR)/src/libapp \
	 -I$(SESCSOURCEDIR)/src/libacc \
	 -I$(XTOOLSPREFIX)/mipseb-linux/include

# C++ flags
CXXFLAGS = $(CFLAGS) \
	  -I$(XTOOLSPREFIX)/mipseb-linux/include/c++/3.2 \
	  -I$(XTOOLSPREFIX)/mipseb-linux/include/c++/3.2/mips-linux-gnu

# Common linker flags
LDFLAGS = -Wl,--script=$(SESCSOURCEDIR)/src/libapp/mint.x \
	  -L$(SESCBUILDDIR)/obj/mipseb_obj -L$(XTOOLSPREFIX)/mipseb-linux/lib

# Common libs
LIBS    = -lapp

# Common definitions
DEFS    = -DLINUX_MIPS

# Emacs tags
EMACSTAGS = $(BENCHDIR)/acc/TAGS

I suppose so. The g++ you are using is not a cross-compiler, it targets the host, that is generates the intel assembly. The compiler that targets MIPS (judging from your makefile) is $(XTOOLSPREFIX)/bin/mipseb-linux-g++.
To obtain a MIPS assembly, use a following makefile:

inclide mips.mk
file.asm: file.cpp
    $(CXX) $(CXXFLAGS) -S file.cpp

That is, assuming that the makefile you posted is called mips.mk, and the assembly suffix is asm; substitute them appropriately. Don't forget that a whitespace at the last line must be a hard tab.

I'm still getting a similar error. Well, it seems to make sense that my compiler isn't compiling into MIPS correctly. Is it possible to do a hex dump on a .s file?

This article has been dead for over six months. Start a new discussion instead.