ECE 3210 Laboratory 1: Develop an Assembly Program

Similar documents
CS354 gdb Tutorial Written by Chris Feilbach

Embedded Systems. 2. Software Development. Lothar Thiele. Computer Engineering and Networks Laboratory

1. Allowed you to see the value of one or more variables, or 2. Indicated where you were in the execution of a program

1 A Brief Introduction To GDB

CS/COE 0449 term 2174 Lab 5: gdb

Laboratory 1 Semester 1 11/12

Reviewing gcc, make, gdb, and Linux Editors 1

Exercise Session 6 Computer Architecture and Systems Programming

Systems Programming. Fatih Kesgin &Yusuf Yaslan Istanbul Technical University Computer Engineering Department 18/10/2005

12. Debugging. Overview. COMP1917: Computing 1. Developing Programs. The Programming Cycle. Programming cycle. Do-it-yourself debugging

HOW TO USE CODE::BLOCKS IDE FOR COMPUTER PROGRAMMING LABORATORY SESSIONS

18-600: Recitation #3

Problem Set 1: Unix Commands 1

Source level debugging. October 18, 2016

CS 270 Systems Programming. Debugging Tools. CS 270: Systems Programming. Instructor: Raphael Finkel

Compilation, Disassembly, and Profiling (in Linux)

An Introduction to Komodo

Scientific Programming in C IX. Debugging

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Lab6 GDB debugging. Conventions. Department of Computer Science and Information Engineering National Taiwan University

CSSE Operating Systems. Project A Booting, Getting Started

Program Design: Using the Debugger

Digital Design and Computer Architecture Harris and Harris, J. Spjut Elsevier, 2007

CS356: Discussion #5 Debugging with GDB. Marco Paolieri

CSE 351. GDB Introduction

Using gdb to find the point of failure

CMPT 300. Operating Systems. Brief Intro to UNIX and C

Debugging. ICS312 Machine-Level and Systems Programming. Henri Casanova

Lab 8. Follow along with your TA as they demo GDB. Make sure you understand all of the commands, how and when to use them.

The CS-220 Development Environment

Compiler Drivers = GCC

CS201 Lecture 2 GDB, The C Library

ECE 471 Embedded Systems Lecture 8

ECE 3210 Lab 4: Calculator

EL2310 Scientific Programming

GDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial

gdbtui - Linux Command

Code::Blocks Student Manual

Jackson State University Department of Computer Science CSC / Advanced Information Security Spring 2013 Lab Project # 5

Laboratory Assignment #3 Eclipse CDT

SU 2017 May 18/23 LAB 3 Bitwise operations, Program structures, Functions (pass-by-value), local vs. global variables. Debuggers

Compila(on, Disassembly, and Profiling

CSci 4061 Introduction to Operating Systems. Programs in C/Unix

CSE 410: Systems Programming

Supplement: Visual C++ Debugging


We first learn one useful option of gcc. Copy the following C source file to your

COP4530 Data Structures, Algorithms and Generic Programming Recitation 3 Date: January 20 & 22, 2009

CNIT 127: Exploit Development. Ch 2: Stack Overflows in Linux

Making things work as expected

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems

Compiling and Linking

Using the Debugger. Michael Jantz Dr. Prasad Kulkarni

SPRING 2017 CSCI 304 LAB1 (Due on Feb-14, 11:59:59pm)

Continue: How do I learn C? C Primer Continued (Makefiles, debugging, and more ) Last Time: A Simple(st) C Program 1-hello-world.c!

ECE QNX Real-time Lab

Programming Studio #9 ECE 190

An Introduction to Python (TEJ3M & TEJ4M)

VORAGO VA108x0 GCC IDE application note

Intro to MS Visual C++ Debugging

Introduction to Linux (Part II) BUPT/QMUL 2018/03/21

Computer Components. Software{ User Programs. Operating System. Hardware

Chapter 2. Basics of Program Writing

Debugging (Part 1) The material for this lecture is drawn, in part, from The Practice of Programming (Kernighan & Pike) Chapter 5

M2 Instruction Set Architecture

Debugging with GDB and DDT

EL2310 Scientific Programming

Data and File Structures Laboratory

CSE2421 Systems1 Introduction to Low-Level Programming and Computer Organization

Lab 03 - x86-64: atoi

IDE: Integrated Development Environment

CS 361S - Network Security and Privacy Spring Project #2

Lab 1 Introduction to UNIX and C

Assembly Language Programming Debugging programs

Tips on Using GDB to Track Down and Stamp Out Software Bugs

Debugging! The material for this lecture is drawn, in part, from! The Practice of Programming (Kernighan & Pike) Chapter 5!

Debugging! The material for this lecture is drawn, in part, from! The Practice of Programming (Kernighan & Pike) Chapter 5!

FALL 2017 CSCI 304 LAB1 (Due on Sep-19, 11:59:59pm)

C Language, Token, Keywords, Constant, variable

Computer Organization and Assembly Language. Lab Session 01

Cornell Cup Tutorials

Code::Blocks Student Manual

Debugging on Intel Platforms

Your code must have been compiled with the -g compiler option. Example:

Homework 1 CS 642: Information Security

EXPERIMENT 1. FAMILIARITY WITH DEBUG, x86 REGISTERS and MACHINE INSTRUCTIONS

U Reverse Engineering

Recitation: Bomb Lab. September 17 th 2018

CPE 323: Laboratory Assignment #1 Getting Started with the MSP430 IAR Embedded Workbench

Embedded Software TI2726 B. 3. C tools. Koen Langendoen. Embedded Software Group

CNIT 127: Exploit Development. Ch 3: Shellcode. Updated

C Compilation Model. Comp-206 : Introduction to Software Systems Lecture 9. Alexandre Denault Computer Science McGill University Fall 2006

Buffer Overflow Defenses

The Linux Programming Environment. Computer Science Department Texas State University

F28HS2 Hardware-Software Interfaces. Lecture 6: ARM Assembly Language 1

CS 107 Lecture 18: GCC and Make

Princeton University COS 217: Introduction to Programming Systems GDB Tutorial and Reference

Introduction to the C Programming Language

ENERGY 211 / CME 211. Evolution

Operating Systems and Networks Project 1: Reliable Transport

Transcription:

ECE 3210 Laboratory 1: Develop an Assembly Program Spring 2018 1 Objective To become familiar with the development system s software: screen editor, assembler, linker, and debugger. After finishing this experiment, you should be able to do the following: 1. Able to remote login your Raspberry Pi as the workstation 2. Use a text editor to create a C source code (.c) or assembly source code (.s) 3. Use the GNC compiler to create an executable file from C source code. 4. Use the assembler and linker to create an executable file from assembly source code. 5. Understand the general procedure to develop and debug an assembly language program. 2 Background 2.1 GNU Compiler The GNU Compiler Collection includes front ends for C, C++, Objective-C, Fortran, Ada, and Go, as well as libraries for these languages (libstdc++,...). GCC was originally written as the compiler for the GNU operating system. To compile a program (assuming the file name is lab1.c), you should type the command line: $ gcc o lab1. o lab1. c 2.2 Assembler The GNU Assembler, commonly known as gas or simply as, is the assembler developed by the GNU Project and sponsored by the Free Software Foundation. It is the default back-end of gcc and it will be the assembler used in this class. To assembly a program (assuming the file name is lab1.s), one should type the command line: $ as o lab1. o lab1. s 1

where the.s is the source file and the.o is the output of the assembly, aka the object file. An object file is a file containing the machine code generate by the assembler and includes the name of variables, their locations and other pertinent information for the linker. We need to generate the debugging information for each assembler source line to enable the debugger functionality. To do so, we type the command line: $ as g o lab1. o lab1. s 2.3 Linker The GNU linker, or GNU ld, is the GNU Project s implementation of the Unix command ld. The ld command creates an executable file (or a library) from one or more object files from the compilation (gcc) or the assembly (as) of one or more source files. To link a single object file into an executable, one should type the command line: $ ld o lab1 lab1. o At this point, the linker will take as input the.o file and generate an executable given by the -o option. Next, to execute the program, we type the command line: $. / lab1 The entry point of an assembly source program is usually referred to as start. Often, we will need to link object files from gcc with object files from the assembler. In that case, we will need to change the entry point to main. This can be accomplished by the following command line: $ ld e main o lab1 lab1. o As before, the linker will generate a executable file named lab1. 2.4 Debugger The GNU Project debugger (gdb) allows you to execute, trace, inspect variables, and many other things that happen inside your program while it executes. This is very useful to understand, for example, what the program was doing at the very moment that it crashed. The main things that gdb can do to help you catch bugs in the act are: 1. Start your program, specifying anything that might affect its behavior. 2. Make your program stop on specified conditions. 3. Examine what has happened when your program stops. 4. Change things in your program, so you can experiment with correcting the effects of an identified bug so you can go on to learn about other bugs. 2.5 GDB Graphical Interface GNU DDD is a graphical front-end for command-line gdb debuggers, they essentially perform the same functionality but DDD has a more intuitive user interface. 2

3 Prelab No pre-lab report is required for Lab 1 4 Laboratory Part 1: Hello World Example Breakdown We first start a Hello World! example. In this section you will create both a C program and an assembly program that prints a string Hello World! on the screen. Doing so you can compare the difference between the two and see how the C program is broken down in details through assembly. 1. Download the lab1p1.c from Canvas and compile it with the following command. $ gcc o lab1p1 lab1p1. c 2. Execute the program by typing./lab1p1 into the command line. You should see the output Hello World! on your screen. Next, we will break down the printf function from the C library to understand how it is implemented in Assembly language. 1. Download the lab1p2.s from Canvas and compile it with the following command. $ as o lab1p2. o lab1p2. s $ ld e main o lab1p2 lab1p2. o 2. Execute the program and you should see similar output as the first example. Part 2: Debug an Assembly Program using DDD In C programming, you usually print out the value of each variable to make sure your program is functioning properly. In assembly, the registers take the position as variables and share the same importance. However, from Part 1 you can tell it is quite tedious if you want to perform the printf function each time for just checking register values. This is where the debugger comes in handy. Before we start, recompile your assembly source code with the following command $ as g o lab1p2. o lab1p2. s $ ld e main o lab1p2 lab1p2. o By using a graphical interface DDD, it provides a lot of convenience for the process of debugging. First, we will start debugging the executable file lab1p2 with the command line tool ddd. $ ddd lab1p2 You should see a similar interface as Figure 1. Next, under the View tab open the Machine Code Table. And under the Status tab, click Registers. Now your interface should look similar to Figure 1. You can set a break point by right clicking the blank area (left side as shown in Figure 1) next to each instructions. Once the break point has been set, you can click the Run button to start debugging and the stepi button to trace each instructions as well. The value of each register should be displayed in the Registers status window on the right side of Figure 1. 3

Figure 1: The proper setting for the DDD debugger. Lab deliverable 1 Use stepi to trace through each instructions in the program and monitor the changes among R0, R1, R2, and R7 from the Registers window. Fill the Table 1 and include it in your lab report results section. MOV R0,#1 LDR R1, =message MOV R2, =length MOV R7, #4 MOV R2, #3 SWI 0 MOV R7, #1 SWI 0 R0 R1 R2 R7 Table 1: Instruction trace table. Lab deliverable 2 After fixing the bug inside lab1p2.s, make changes of the program so it can print the following message. Submit the program with your lab report. 4

ECE 3210 <Your Name> Hello World! 5 Report Please follow the template provided from the syllabus. Include the answer for the following questions in your Conclusion section. 1. What does.data,.text, and.global mean? 2. What does the instruction LDR do? 6 Appendix lab1p1.c #i n c l u d e <s t d i o. h> main ( ) { char message [ 1 3 ] = H e l lo World! \ n ; } lab1p2.s p r i n t f ( %s, message ) ;. data message :. a s c i i Hello World! \ n length :. byte 13. t e x t. g l o b a l main main : @ w r i t e s y s c a l l mov r0, #1 @ For stdout l d r r1, =message @ b u f f e r i s loaded with message l d r r2, =l e n g t h @ count i s the length o f message mov r7, #4 @ w r i t e i s s y s c a l l 4 mov r2, #3 swi 0 @ i n t e r r u p t @ e x i t s y s c a l l mov r7, #1 swi 0 5