ECEn 425

Lab #1: Class Tools and the 8086 Architecture


This lab is to be completed individually; you must work alone. This lab is an introduction to the 8086 architecture and the tools that will be used to complete the remaining labs this semester. In this lab, use the tools to compile, assemble, and execute a simple program written in C and assembly language. Then you will write a function in assembly language that is called from the C source code. You will learn about the tools, the 8086 instruction set, and the C function calling convention.


Start by familiarizing yourself with the topics of this lab by doing the following reading:

All of the above documents can also be found on the 425 Online Resources page for future reference. Once you feel comfortable with the build process, follow the instructions below to build the program for this lab.


The tools for this class run on the department's Linux machines in 425 CB. (If you want to explore the possibility of running the tools on another platform, the source code is available at /ee2/ee425/src/dist. /ee2 is a drive mounted on linux machines in the lab. You are on your own getting the code to compile and run on your own machine.) Use one of the available machines to perform the following steps:

  1. Create a directory to contain all your work for this class. You must maintain access privileges appropriately so that only you have access to the files and directories it contains. Once this is done, create a subdirectory to contain the files for this lab.
  2. Add /ee2/ee425/bin to your path. This is necessary to run the compiler and assembler. See setting your path for more details.
  3. Copy the class library file clib.s and its C header file clib.h to your lab directory. These files are needed for all programs you build to run in the simulator.
  4. Copy the assembly file lab1asm.s and the C file lab1.c to your lab directory.
  5. Use cpp to preprocess lab1.c, the C file for this lab, by changing to your lab directory and typing "cpp lab1.c lab1.i". This will produce a version of lab1.c named lab1.i that is ready to be compiled.
  6. Compile lab1.i using c86 by typing "c86 -g lab1.i lab1.s". This will produce an assembly language file named lab1.s.
  7. Concatenate your files together by typing "cat clib.s lab1asm.s lab1.s > lab1final.s". The file clib.s contains output functions used by lab1.c and must be included as the first file when you concatenate your assembly files together.
  8. Assemble the final assembly file using NASM to produce an 8086 executable named lab1.bin. To assemble the file, type "nasm lab1final.s -o lab1.bin -l lab1.lst". This also creates a listing file named lab1.lst.
  9. Start the instruction level emulator for the 8086, by typing "emu86". Notice that the simulator uses two separate windows: one for the output of the program executing on the simulator and another for interacting with the simulator itself.
  10. Load the executable into Emu86 by typing "l lab1.bin" at the "Emu86>" prompt.
  11. Execute the program by typing "e". The program's output should appear in the output window. It should output the following text:
    Hello, world!
    Result 1 is: 0
    Result 2 is: 0
    Result 3 is: 0
  12. Quit the simulator by entering "q".

You now know how to build programs to run on Emu86. In future labs you will use a Makefile to make this process as simple as typing "make". Now your task is to modify the file lab1asm.s to change its functionality. To do this you will need to have a basic understanding of the 8086 instruction set as well as the C calling convention on the 8086.

The file lab1asm.s contains the assembly routine "AsmFunction". This function is called a few times from the file lab1.c with different function arguments based on the prototype:

int AsmFunction(int a, char b, char c, int d, int e);

Your assignment is to edit lab1asm.s and modify the assembly routine AsmFunction so that it returns the result of the calculation 


where a, b, c, d, and e are the arguments passed to the function and gvar is a global variable declared in lab1.c. You may look at the source code for lab1.c but you are not allowed to modify it in any way. After lab1asm.s has been modified to include your assembly function contents, you must again go through the steps of concatenation and assembly by entering "cat clib.s lab1asm.s lab1.s > lab1final.s" followed by "nasm lab1final.s -o lab1.bin -l lab1.lst". Then run the simulator as explained previously. When AsmFunction is correct, your program's output should look like this:

Hello, world!
Result 1 is: 16
Result 2 is: 111
Result 3 is: -34


Please consider the TA lab schedule well in advance. New for Fall 2019: after passing off to the TA, upload your lab1asm.s file on Learning Suite. (We need to collect examples of student work for our department's ABET review next fall, but TAs may also review your submission to double check that all requirements were met.)

Tips and Hints


Last updated 4 September 2019