Pick the defaults on every screen prompted till you get to the screen that asks you to "
Choose A Download Site". It does not matter which you pick other than affect the speed at which you download. I choose
http://mirror.mcs.anl.gov because I've always found this site to be reliable and to have a decent speed.
The next screen will present a long list of packages and ask you to
select the ones you want to install. In addition to the default
packages, make sure you select these packages:
- Under the Devel tab choose these by clicking on the circle preceding the word "Skip", which will change the "Skip" to a number
showing the version of the utility you are installing. Here are the
packages:
Devel-
- binutils: The GNU assmebler, linkerand binary utilities
- bison: A parser generator that is compatible with YACC
- flex: A fast lexical analyzer generator
- gcc: C compiler upgrade helper
- gcc-core: C Compiler
- gdb: The GNU debugger
- make: The GNU version of the 'make' utility
- Under the Editors tab choose a editor you know or heard about. I like joe because it is fast and simple. Here is the package:
Editors-
- joe: Fast and simple editor which emulates 5 other editors
That is it. Click the next button at the bottom of the screen and give
it a few minutes to complete the download and installation. This should
take approximately 15-20 minutes depending on the speed of your
Internet connection and your processor.
Building lcc in Cygwin
The Cygwin software you installed has one application called a
shell
that allows you to do all of the work needed including programming.
First though, we will use it to build the LC3 C compiler. To do this,
double click the "Cygwin Terminal" icon that was placed on your Desktop
when Cygwin installation was complete. This will open a window that
looks like this
- At the command prompt (shown as $) type in (Do not type the dollar)
$ cd c:lc3/lcc-1.3
to change directory to the directory that you previously downloaded the lcc software to.
- Run these three commands in order. Do not worry about warnings
$ ./configure --installdir /bin
$ make
$ make install
These commands will take a few minutes to complete at the end of which you will have the software built and installed
Install the lc3 assembler
While the previous step installed the compiler software, it depends on
one other utility which was part of lc3tools, i.e., the assembler.
I am providing this at the following link:
http://users.ece.utexas.edu/~ryerraballi/ee306/lc3as.exe
Right-click on the above link and choose
save-link-as (Firefox) to save it in the following directory on your PC:
C:\cygwin\bin
CONGRATULATIONS!!
That is it, you are now ready to write your C Programs, compile them
and generate assembly and object files that can be run in the LC3
Simulator.
C Programming
It is not the intent of this document to teach you to program in C for
that I refer you to the textbook, Introduction to Computing by Yale
Patt and Sanjay Patel [
1].
The second part of this text (chapter 11 onwards) covers C programming
with LC3 computer as the reference. That is assuming you understand the
LC3 assembly language and know basic programming principles, you can
read this material to see how programming at a higher level works.
I will however show you how to write your C programs and go through the
process of running them on the simulator, using the tools you
installed.
Again, open the Cygwin Terminal if you did not already do so. You may
want to create a directory for your C programming exercises to keep
them well organized. To do this type the following commands:
$ cd
$ mkdir Exercises
$ cd Exercises
$ mkdir C
$ mkdir asm
$ cd C
The above set of commands will create a directory called C under
Exercises in your default home directory where you can put all your C
programs you write. Now we are ready to write our first C Program. Open
an editor to write your first program:
$ joe hello.c
This will open the editor and you can type in your code. Here is your first C Program
#include <stdio.h>
int main(){
char name[10];
printf("What is your name: ");
scanf("%s", name);
printf("Hello %s\n", name);
return(0);
}
|
If you want to learn how to use the editor tpye in
Control-k followed by h. To close the file once you finished editing it type
Control-k followed by x. Now you are ready to compile it, to do so type in the following at the command prompt:
$ lcc -o hello hello.c
This will take produce the assembly, object and symbol table files. Now
open the object file in LC3Simulate like you do when you are working
with assembly files. When you run it is LC3Simulate the LC3
console should prompt you for your name and after you enter it should
greet you.
That is it!
Bonus
Interestingly, the process of installing
the software also gave you the ability to build C programs not just for
the LC3 but also to run directly on your PC. That is you can compile
the C program you just wrote for the x86 ISA. To do this, you use the
gcc compiler instead of the lcc compiler as follows:
$ gcc -o hello hello.c
Note the gcc instead of lcc. This will create a file called hello.exe,
which is a native executable for Windows. Run it as follows: