Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please provide fast answer Assignment 2: Assemble Code Write a Java program which reads the standard input and produces valid SPARC assembly code on the
please provide fast answer
Assignment 2: Assemble Code Write a Java program which reads the standard input and produces valid SPARC assembly code on the standard output. The assembly code should make use of procedures written in C. Write C procedures to allocate arrays, create classes, and print decimal numerals. Remember Java initializes all int arrays and class variables to zero. Imagine that you are writing a compiler for Java programs of the following form: These programs all have one array y (of size 10) and one class R with three instance fields. We simplify the syntax of such programs to a few simple tokens (the comments are not part of the input) as follows: 5a313bb9b3//println(y[5])//println(r,a)//y[3]=1//println(y[3])//println(r,b)//rb=9//println(r,b)//println(y[3]) This is the format of the input to your compiler-a Java program. Your compiler reads such lines (first token is a digit or the letter a-c, the optional second is a digit), and produces a SPARC assembly program. Executing the assembly program produces the appropriate output. Your Java program, like all files, should be encoded in USASCII to avoid problems interpreting the characters. The output for the example above is: You must use make to communicate how the project is to be built from the source files. A makefile describes the steps (assembling, linking, etc) necessary to create a program. Note that makefiles depend crucially on leading tabs, and must end in Unix newlines ( n) not DOS newlines ( n ) ! The make file, like all files, should be encoded in US-ASCII. Here is an example Makefile. JAVACGCC:=javac:=sparc1inux-gcc JAVAC := javac GCC := sparc-linux-gcc default : compiler compiler : Main.class runtime.o compile chmod u+x compile Main.class : Main.java \$(JAVAC) -encoding ASCII -Xlint -Xlint:-serial Main.java runtime.o : runtime.c $( GCC) -Wall -c runtime.c -o runtime.o It is more convenient to parameterize your makefile with variables so that it adjusts easily to changes and may work in more than one environment. Also, create a shell (sh, csh, bash) script named compile that executes the compiler on our SPARC emulator. Your script should take one argument, the path to the source program, say, dir/file.java, (it is not really a Java programs; it represents an imaginary one in the form described above) compile it, and produce a SPARC/ELF executable file dir/file (no extension). Your script should look something like the following: #! bin/csh \# input files and output files set dir=`dirname $1 set base=' basename $1.java set file=\$dir/\$base Assembly Code Examples Main Program The C library routine 'exit' (not the system call) flushes the standard output stream and this is a prudent, even necessary step at exit. Macros Debugging You can use gdb to help debug your assembly programs. Invoke it on the executable module. gdb program Here are some useful commands: Another good tip is to write simple C programs and compile them gec -s program.c Examine the assembly program output (in the file program.s) to learn how to write assembly code. Starting the debugger is different with the emulator. First you need to run the emulator and tell it to listen on specific port for gdb. Then you run gdb and point it the emulator. For example: qemu-sparc-wrapper -g 1234 executable \& sparc-linux-gdb -ex 'target remote : 1234 ' executable Helpful Stuff - GNU make documentation - GNU as and ld documentation - gdb documentationStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started