{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

MARKED LAB.docx - [INTRODUCTION TO COMPUTER SYSTEMS...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
[ INTRODUCTION TO COMPUTER SYSTEMS ] Computing Science Department Course : COMP 2130 Lab: #5 Date: 15 th March 2018 Assembly Language 101 Due End of class (9:30 or 12:30) weight : 2% 1. Introduction The purpose of this lab assignment is to get familiar with ATT & Intel assembly code. 2. Generating assembly from C code A good first step to rewriting a C routine in assembly language is to use the C compiler to automatically generate the assembly language. Not only does this give you an assembly file that compiles correctly, but it also ensures that the assembly routine does exactly what you intended it to. We will now use the GNU C compiler to generate assembly code, for the purposes of examining the ATT and Intel assembly language syntax. Step 1 : Write a simple sum function in C and save it as test.c int sum(int x, int y) { int z; z=x + y; return z; } Step 2: Compile your C code and run the relocatable object code that can be used later. gcc -c test.c Step 3: Now, let's generate the equivalent 32-bit x86 ATT assembly language. Type the following at the prompt: gcc -S -m32 test.c This should create a file called " test.s " (".s" is the file extension that the GNU system gives to assembly files). 1
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
[ INTRODUCTION TO COMPUTER SYSTEMS ] Step 4 : Copy the assembly file with different name cp test.s testm32.s Step 5: Remove the gcc directive and still generate the assembly code gcc -S test.c Step 6: Now let’s look at the assembly file. We’ll use the 32-bit version. Use vim or any other editor to open the test.s file.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern