4.7 Pointers and addressing4 Class Schedule4.5 Bit fields, rotate instructions, and shift instructions4.6 Subroutines and the interface to "C"

4.6 Subroutines and the interface to "C"

 

4.6.1 Reading and Web Sites

  1. Read Carter Chapter 4 -- Subprograms. I found this to be a well written introduction to subroutines in general. It also covers the stack and frames fairly well.
  2. Read as much of Intel's Volume 1: Basic Architecture Chapter 6 -- Procedure Calls, Interrupts, and Exceptions as you can.
  3. Read about CALL, RET. Subroutine call and return instructions in Intel's IA-32 Intel Architecture Software Developer's Manual
    Volume 2A: Instruction Set Reference, A-M
    and Intel's IA-32 Intel Architecture Software Developer's Manual
    Volume 2BA: Instruction Set Reference, N-Z
    .
  4. Read about PUSH, POP. Instructions for pushing values onto the stack and removing items from the stack in Intel's IA-32 Intel Architecture Software Developer's Manual
    Volume 2BA: Instruction Set Reference, N-Z
  5. Read about PUSHA, POPA in Intel's IA-32 Intel Architecture Software Developer's Manual
    Volume 2BA: Instruction Set Reference, N-Z
    . Pushes and pops all of the 32 bit registers at one time.
  6. Read about ENTER, LEAVE In Intel's IA-32 Intel Architecture Software Developer's Manual
    Volume 2A: Instruction Set Reference, A-M
    . A high level procedure entry and exit instructions.

4.6.2 Notes

4.6.3 Lab Assignment, Subroutines

  1. Write an assembly language program that calls an assmbly language subroutine. The subroutine adds the two numbers passed on the stack and returns the value in the EAX register.
  2. Call the subroutine with 6 and 7. Print the result in decimal.
  3. Call the subroutine a second time with the low seven digits of your student services number and the current days date. For example for February 1, 2006 use 2012006. Print the result in decimal.
  4. Call the subroutine a third time with the above result twice. Print this result in decimal as well.
  5. Run the program. Check your results.
  1. Write an assembly language version of the following "C" program that calls the "C" function printf twice.
    #include <stdio.h>
    int count;      
    char name[]="your-name";
    int month=11, day=1, year=2004;
    int main()
     {
     count = printf("%s CIS250 %d/%d/%d\n\n",name,month,day,year);
     printf("count: %d\n",count);
     return 0;
     }
     
  2. Use the current date and time for when you write your program.
  3. Assemble your main program.
  4. Link the program and the printf together.
  5. Run the program.

Turn in a printed error free listing of the assembly language programs & subprograms, and the output of your program. Include a copy of the testing that you did to verify the program was correct.


Instructor: Louis Taber, louis.taber.at.pima at gmail dot com (520) 206-6850
My web site in California
The Pima Community College web site

4.7 Pointers and addressing4 Class Schedule4.5 Bit fields, rotate instructions, and shift instructions4.6 Subroutines and the interface to "C"