Assembly 01. Outline Binary vs. Text Files Compiler vs. Assembler Mnemonic Assembly Process Development Process Debugging Example 1 this analogy will.

Slides:



Advertisements
Similar presentations
Chapter 11 Introduction to Programming in C
Advertisements

Dr. Ken Hoganson, © August 2014 Programming in R COURSE NOTES 2 Hoganson Language Translation.
Week 3. Assembly Language Programming  Difficult when starting assembly programming  Have to work at low level  Use processor instructions >Requires.
Chapter 2 Machine Language.
IT253: Computer Organization Lecture 6: Assembly Language and MIPS: Programming Tonga Institute of Higher Education.
Utilizing the GDB debugger to analyze programs Background and application.
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Lecture 1: Overview of Computers & Programming
SYSTEM PROGRAMMING & SYSTEM ADMINISTRATION
1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
Lab6 – Debug Assembly Language Lab
Chapter 2 Machine Language. Machine language The only language a computer can understand directly. Each type of computer has its own unique machine language.
The Binary Machine Modern high-level programming languages are designed to make programming easier. On the other end, the low level, all modern digital.
Outline Learning Assembly by an Example.  Program Formats  Some Simple Instructions  Assemble and Execute Learning Another Example  Data Definition.
Chapter 3 Assembly Language: Part 1. Machine language program (in hex notation) from Chapter 2.
CS 201 Overview of Computers & Programming Debzani Deb.
1 Lecture 1  Getting ready to program  Hardware Model  Software Model  Programming Languages  The C Language  Software Engineering  Programming.
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Programming and Problem Solving
Chapter 7 Low-Level Programming Languages. 2 Chapter Goals List the operations that a computer can perform Discuss the relationship between levels of.
Table 1. Software Hierarchy Levels.. Essential Tools An assembler is a program that converts source-code programs into a machine language (object file).
Computer Architecture and Assembly Languages Course’s web site: Teaching Assistant: Or Peri Office Hours: Thursday 37/-108.
8051 ASSEMBLY LANGUAGE PROGRAMMING
Topic 1: Introduction to Computers and Programming
CS2422 Assembly Language & System Programming September 26, 2006.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#1) By Dr. Syed Noman.
Assembly & Machine Languages
Chapter 2 Software Tools and Assembly Language Syntax.
CCSA 221 Programming in C CHAPTER 2 SOME FUNDAMENTALS 1 ALHANOUF ALAMR.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
Parts of a Computer Why Use Binary Numbers? Source Code - Assembly - Machine Code.
Lab 1 – Assembly Language and Interfacing Start date: Week 3 Due date: Week 4 1.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
Topics Introduction Hardware and Software How Computers Store Data
MIPS coding. SPIM Some links can be found such as:
Instruction Set Architecture
Chapter 3 Elements of Assembly Language. 3.1 Assembly Language Statements.
Chapter 1: Basic Concepts
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 1 Introduction to Computers and Programming.
Practical Session 4. Labels Definition - advanced label: (pseudo) instruction operands ; comment valid characters in labels are: letters, numbers, _,
Programming With C.
Python From the book “Think Python”
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 3 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
CNIT 127: Exploit Development Ch 3: Shellcode. Topics Protection rings Syscalls Shellcode nasm Assembler ld GNU Linker objdump to see contents of object.
Overview of Previous Lesson(s) Over View  A program must be translated into a form in which it can be executed by a computer.  The software systems.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
The Development Process Compilation. Compilation - Dr. Craig A. Struble 2 Programming Process Problem Solving Phase We will spend significant time on.
CMPE13Cyrus Bazeghi 1 Chapter 11 Introduction to Programming in C.
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
OCR A Level F453: The function and purpose of translators Translators a. describe the need for, and use of, translators to convert source code.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
1 Chapter 1: Introduction Appendix A: Binary and Hexadecimal Tutorial Assembly Language for Intel-Based Computers, 3rd edition Kip R. Irvine.
Computer Basics.
Topics Introduction Hardware and Software How Computers Store Data
Assembly Language (continue)
Microprocessor and Assembly Language
Computer Science I CSC 135.
Computers: Hardware and Software
Chapter 11 Introduction to Programming in C
C Prog. To Object Code text text binary binary Code in files p1.c p2.c
CSCE Fall 2013 Prof. Jennifer L. Welch.
CSCE 121: Simple Computer Model Spring 2015
Topics Introduction Hardware and Software How Computers Store Data
Chapter 11 Introduction to Programming in C
MARIE: An Introduction to a Simple Computer
CSCE Fall 2012 Prof. Jennifer L. Welch.
Computer Organization and Assembly Language
1.3.7 High- and low-level languages and their translators
Computer Architecture and System Programming Laboratory
Presentation transcript:

Assembly 01

Outline Binary vs. Text Files Compiler vs. Assembler Mnemonic Assembly Process Development Process Debugging Example 1 this analogy will make sense…

Text Files Meaningful to humans when displayed Contains 95 visible characters and white space White space includes spaces, tabs, and newlines You compile or assemble text files into binary files Old school computer scientists wrote binary instructions (yuck!) Thank your compiler and/or assembler!! 2

3 Example Text File Command-line editor vim showing simple “Hello World” C++ program

Binary Files NOT meaningful to humans Example binary files: Executables (i.e., instructions for CPU) Compressed files (e.g.,.zip) Network I/O Sensor data … 4

5 Example Text File Command-line editor vim showing compiled “Hello World” executable

Text Files Text files are stored as binary in computer’s memory How else would contents be stored?!?! Text files are ASCII characters 95 meaningful characters and white space ASCII character is a byte E.g., ‘A’ is 0x41, decimal 65, binary sequence

Text File Contents 7 Bless Hex Editor text equivalent hexadecimal representing the binary stored in memory Texts are stored in memory as binary, but displayed as human- readable ASCII characters

Outline Binary vs. Text Files Compiler vs. Assembler Mnemonic Assembly Process Development Process Debugging Example 8 this analogy will make sense…

Compiler vs. Assembler 9 high-level language assembly language compile assemble machine language (object code)

Compiler 10 high-level language assembly language compile assemble machine language (object code)

Compiler Translates high-level language into object code Assembly code may be intermediate step Programmer DOES NOT have full control of object code Compiler decides what instructions go into machine code Compiler decides the order of instructions in machine code E.g., code snippet “ x = 4; “ could be compiled into 4 or 5 instructions 11

Assembler 12 high-level language assembly language machine language (object code) compile assemble

Mnemonic Example use of mov mnemonic: mov eax,4; place 4 in general 32-bit register eax 13

Assembler Translates assembly language into machine language Programmer has FULL CONTROL of object code Must define every instruction to be executed “Long journey in very small steps” Each “step” is instruction for CPU (many lines of code) 14

Outline Binary vs. Text Files Compiler vs. Assembler Mnemonic Assembly Process Development Process Debugging Example 15

Mnemonic Assembler sees at least one line of assembly source code for every machine instruction it generates Assembly language has a mnemonic for each machine instruction available for that architecture Example mnemonics for x86 architecture: mov add push … 16

Mnemonic Example line of assembly: mov eax,4; place 4 in general 32-bit register eax 17

Mnemonic Example line of assembly: mov eax,4; place 4 in general 32-bit register eax 18 mnemonic

Mnemonic Example line of assembly: mov eax,4; place 4 in general 32-bit register eax 19 operands note: some instructions have zero operands other instructions have 1 operand other instructions have 2 operands

Mnemonic Example line of assembly: mov eax,4; place 4 in general 32-bit register eax 20 comment: starts at ; ends at EOL best practice: comment EVERY line of assembly code!!

Mnemonic Example line of assembly: mov eax,4; place 4 in general 32-bit register eax 21 instruction: mnemonic and operand(s)

Mnemonic Assembler converts instruction into object code mov ebp,esp; save stack pointer to ebp register 0x8BEC 22 assembly language instruction gets assembled into… machine language instruction

Mnemonic Machine language instruction gets decoded… Execution cycle begins… 0x8BEC =

Mnemonic You will become familiar with x86 mnemonics Practice, practice, practice writing x86 assembly code Same idea for MIPS and ARM assembly.. Slightly different mnemonics and operands Flip through Appendix A in the book… Taste of x86 mnemonics Don’t worry about details, yet 24

BREAK TIME!! Please stand up, stretch your legs, walk around… 25

Outline Binary vs. Text Files Compiler vs. Assembler Mnemonic Assembly Process Development Process Debugging Example 26

Assembly Process How to go from assembly source code to executable Two steps: 1.Assemble 2.Link 3.(Execute) 27

Assembly Process.asm assembler.o linker executable assembly source code file(s) object file(s) executable program file

Assembly Process 1)Assembler translates assembly source code into object file Assembly source code file(s) end in.asm Object file(s) end in.o Object file(s) cannot be executed by CPU Modern operating systems prevent object file execution 29.asm.o

Assembly Process 2) Linker (or loader) creates executable program file Linker “links” object file(s) into executable Linker creates image of how executable will be stored in memory 30.o executable

Assembly Process 2) Execute Run the assembly code Run the machine language instructions… Do cool stuff… 31

Assembly Process Example: Assemble, load, and execute “eatsyscall.asm” Note: “UNIX>” will indicate the command prompt This example is available to download from book’s website: “asmsbs3e.zip” contains all examples in book!! 32

Assembly Process Step 1: Assemble the source file eatsyscall.asm We’ll discuss what goes into assembly source files in the coming weeks UNIX> nasm –f elf –g –F stabs eatsyscall.asm 33

Assembly Process Step 1: Assemble the source file eatsyscall.asm UNIX> nasm –f elf –g –F stabs eatsyscall.asm 34 invoke the nasm assembler

Assembly Process Step 1: Assemble the source file eatsyscall.asm UNIX> nasm –f elf –g –F stabs eatsyscall.asm 35 -f elf command line option:.o files (produced by nasm) will be elf format

Assembly Process Step 1: Assemble the source file eatsyscall.asm UNIX> nasm –f elf –g –F stabs eatsyscall.asm 36 -g command line option: include debug information in.o file

Assembly Process Step 1: Assemble the source file eatsyscall.asm UNIX> nasm –f elf –g –F stabs eatsyscall.asm 37 -F stabs command line option: debug information in “stabs” format

Assembly Process Step 1: Assemble the source file eatsyscall.asm UNIX> nasm –f elf –g –F stabs eatsyscall.asm 38 filename of assembly source code to be assembled

Assembly Process Step 2: Link the object file(s) to create executable UNIX> ld –o eatsyscall eatsyscall.o 39

Assembly Process Step 2: Link the object file(s) to create executable UNIX> ld –o eatsyscall eatsyscall.o 40 invoke the linker

Assembly Process Step 2: Link the object file(s) to create executable UNIX> ld –o eatsyscall eatsyscall.o 41 -o command line option: specifies name of executable (e.g., eatsyscall)

Assembly Process Step 2: Link the object file(s) to create executable UNIX> ld –o eatsyscall eatsyscall.o 42 name of object file(s) to be linked together

Assembly Process Step 3: Execute the program UNIX>./eatsyscall Eat at Joe’s! 43./ (dot slash) indicates current directory

Assembly Process Step 3: Execute the program UNIX>./eatsyscall Eat at Joe’s! 44 eatsyscall executable program name

Assembly Process Step 3: Execute the program UNIX>./eatsyscall Eat at Joe’s! 45 output

Outline Binary vs. Text Files Compiler vs. Assembler Mnemonic Assembly Process Development Process Debugging Example 46

Development Process General idea for developing assembly code 1.Edit 2.Assemble 3.Link 4.Execute 5.Debug 6.Repeat.. 47

48.asm.o executable Assembler Linker Debugger.o start here no errors Assembler errors no errors Linker errors works perfectly!! you’re done!! doesn’t work previously assemble d object files editor

Outline Binary vs. Text Files Compiler vs. Assembler Mnemonic Assembly Process Development Process Debugging Example 49

Debugging We are going to use KDbg Easy to use View register contents, output, etc. GUI front-end to gdb Book uses insight (Chapter 6+) It would not install on VMs!! Other options out there e.g., ddd 50

Debugging 51 screensho t of KDbg

Debugging To begin debugging UNIX> kdbg eatsyscall 52 kdbg starts KDbg debugger GUI

Debugging To begin debugging UNIX> kdbg eatsyscall 53 name of executable program e.g., eatsyscall

Debugging Using a debugger will save you time and frustration!!! Use breakpoints to check flow of execution Register contents Output etc. KDbg is a visual debugger, easier than command line only gdb command-line debugger is clunky and hard to learn 54

Outline Binary vs. Text Files Compiler vs. Assembler Mnemonic Assembly Process Development Process Debugging Example 55

Example VMWare virtual machine running Linux operating system (lubuntu) Assemble, link, execute eatsyscall.asm Use KDbg debugger to analyze registers.. 56