mith College Computer Science CSC231 - Assembly Week #3 Dominique Thiébaut

Similar documents
mith College Computer Science CSC231 - Assembly Week #4 Dominique Thiébaut

mith College Computer Science CSC231 Assembly Week #9 Fall 2017 Dominique Thiébaut

mith College Computer Science CSC231 - Assembly Week #9 Dominique Thiébaut

mith College Computer Science CSC231-Assembly Fall 2017 Week #2 Dominique Thiébaut

mith College Computer Science CSC231 Assembly Week #5 Fall 2017 Dominique Thiébaut

mith College Computer Science CSC231 - Assembly Week #8 Dominique Thiébaut

mith College Computer Science CSC231 Assembly Week #9 Spring 2017 Dominique Thiébaut

mith College Computer Science CSC231 Assembly Week #11 Fall 2017 Dominique Thiébaut

mith College Computer Science Fixed-Point & Floating-Point Number Formats CSC231 Dominique Thiébaut

mith College Computer Science Fixed-Point & Floating-Point Number Formats CSC231 Assembly Language Week #13 Dominique Thiébaut

mith College Computer Science Fixed & Floating Point Formats CSC231 Fall 2017 Week #15 Dominique Thiébaut

mith College Computer Science CSC231 Assembly Week #10 Fall 2017 Dominique Thiébaut

ADDRESSING MODES. Operands specify the data to be used by an instruction

mith College Computer Science Fixed-Point & Floating-Point Number Formats CSC231 Assembly Language Week #14 Dominique Thiébaut

Name: CMSC 313 Fall 2001 Computer Organization & Assembly Language Programming Exam 1. Question Points I. /34 II. /30 III.

UMBC. A register, an immediate or a memory address holding the values on. Stores a symbolic name for the memory location that it represents.

Assembly basics CS 2XA3. Term I, 2017/18

mith College Computer Science CSC231 Assembly Week #12 Thanksgiving 2017 Dominique Thiébaut

MODE (mod) FIELD CODES. mod MEMORY MODE: 8-BIT DISPLACEMENT MEMORY MODE: 16- OR 32- BIT DISPLACEMENT REGISTER MODE

mith College Computer Science Week 14 Fixed & Floating Point Formats CSC231 Fall 2017 Week #14 Dominique Thiébaut

mith College Computer Science CSC231 Assembly Week #13 Fall 2017 Dominique Thiébaut

X86-NASM STANDARD COMMANDS. Comment your code with a semicolon (;)! The assembler won t read anything after it.

Shell Code For Beginners

CONCORDIA UNIVERSITY Department of Computer Science and Software Engineering COMP 228/4 Section PP Midterm Exam

register clicker:

SOEN228, Winter Revision 1.2 Date: October 25,

Basic Pentium Instructions. October 18

CMSC 313 Lecture 08 Project 2 Questions Recap Indexed Addressing Examples Some i386 string instructions A Bigger Example: Escape Sequence Project

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 21: Generating Pentium Code 10 March 08

Computer Architecture and Assembly Language. Practical Session 5

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution

Machine Code and Assemblers November 6

Macros in Pentium. Assembly Language. October 25

CMSC 313 Lecture 10. Project 3 Questions. The Compilation Process: from *.c to a.out. UMBC, CMSC313, Richard Chang

Machine and Assembly Language Principles

Faculty of Engineering Computer Engineering Department Islamic University of Gaza Assembly Language Lab # 2 Assembly Language Fundamentals

Computer Architecture and System Programming Laboratory. TA Session 5

CSC 405 Computer Security Shellcode

printf("this program adds the value 10 to a given integer number.\n\n");

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB

Operating Systems. Part 8. Operating Systems. What is an operating system? Interact with Applications. Vector Tables. The master software

Computer Architecture and System Programming Laboratory. TA Session 3

CS241 Computer Organization Spring 2015 IA

Università Ca Foscari Venezia

Sistemi Operativi. Lez. 16 Elementi del linguaggio Assembler AT&T

CMSC 313 Lecture 07. Short vs Near Jumps Logical (bit manipulation) Instructions AND, OR, NOT, SHL, SHR, SAL, SAR, ROL, ROR, RCL, RCR

Practical Malware Analysis

1 /* file cpuid2.s */ 4.asciz "The processor Vendor ID is %s \n" 5.section.bss. 6.lcomm buffer, section.text. 8.globl _start.

Computer Architecture and Assembly Language. Practical Session 3

CMSC 313 Lecture 10 [draft] The Compilation Process: from *.c to a.out

Chapter 11. Addressing Modes

Assembly Language Lab # 9

Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p

Machine-Level Programming I: Introduction Jan. 30, 2001

Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction

The 8051 Microcontroller and Embedded Systems

Assembly level Programming. 198:211 Computer Architecture. (recall) Von Neumann Architecture. Simplified hardware view. Lecture 10 Fall 2012

X86 Addressing Modes Chapter 3" Review: Instructions to Recognize"

ASSEMBLY - QUICK GUIDE ASSEMBLY - INTRODUCTION

why we shouldn t use assembly compilers generate pre8y fast, efficient code tedious, easy to screw up not portable

Systems I. Machine-Level Programming I: Introduction

Lecture 2 Assembly Language

CSC 2400: Computer Systems. Towards the Hardware: Machine-Level Representation of Programs

Assembly Language Programming Debugging programs

This is an example C code used to try out our codes, there several ways to write this but they works out all the same.

Selected Machine Language. Instructions Introduction Inc and dec Instructions

CPU. IBM PC and compatible Memory Structure

We will first study the basic instructions for doing multiplications and divisions

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 7. Procedures and the Stack

CSCI 334: Principles of Programming Languages. Computer Architecture (a really really fast introduction) Lecture 11: Control Structures II

ALT-Assembly Language Tutorial

Topic 6: Code Generation

Lab 4: Basic Instructions and Addressing Modes

Interfacing Compiler and Hardware. Computer Systems Architecture. Processor Types And Instruction Sets. What Instructions Should A Processor Offer?

Machine Programming 1: Introduction

Dr. Ramesh K. Karne Department of Computer and Information Sciences, Towson University, Towson, MD /12/2014 Slide 1

Shellcode. Compass Security Schweiz AG Werkstrasse 20 Postfach 2038 CH-8645 Jona. Tel Fax

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 10. Advanced Procedures

The Instruction Set. Chapter 5

Registers. Ray Seyfarth. September 8, Bit Intel Assembly Language c 2011 Ray Seyfarth

Introduction to 8086 Assembly

CSC 8400: Computer Systems. Machine-Level Representation of Programs

Introduction to 8086 Assembly

Giving credit where credit is due

Assembly I: Basic Operations. Jo, Heeseung

Today: Machine Programming I: Basics. Machine Level Programming I: Basics. Intel x86 Processors. Intel x86 Evolution: Milestones

ASSEMBLY I: BASIC OPERATIONS. Jo, Heeseung

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB

Load Effective Address Part I Written By: Vandad Nahavandi Pour Web-site:

CS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017

LAB 3 Memory Addresses

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

Assembly Language Programming

Procedure Calls. Young W. Lim Mon. Young W. Lim Procedure Calls Mon 1 / 29

Lab 5: Input/Output using a Library of Procedures

Page # CISC 360. Machine-Level Programming I: Introduction Sept. 18, IA32 Processors. X86 Evolution: Programmerʼs View.

Today: Machine Programming I: Basics

CISC 360. Machine-Level Programming I: Introduction Sept. 18, 2008

ECOM Computer Organization and Assembly Language. Computer Engineering Department CHAPTER 7. Integer Arithmetic

Transcription:

mith College Computer Science CSC231 - Assembly Week #3 Dominique Thiébaut dthiebaut@smith.edu

memory mov add registers hexdump listings number systems

Let's Review Last Week's Material

section.data Hello db "Hello there!", 10, 10 HelloLen equ $-Hello Listing _start: section.text global _start ;;; print message mov eax, 4 ; write mov ebx, 1 ; stdout mov ecx, Hello ; address of message to print mov edx, HelloLen ; # of chars to print int 0x80 ;;; exit mov ebx, 0 mov eax, 1 int 0x80

11 section.data 12 00000000 48656C6C6F20746865- Hello db "Hello there!", 10, 10 13 00000009 7265210A0A 14 HelloLen equ $-Hello 15 16 section.text 17 global _start 18 _start: 19 20 ;;; print message 21 00000000 B804000000 mov eax, 4 ; write 22 00000005 BB01000000 mov ebx, 1 ; stdout 23 0000000A B9[00000000] mov ecx, Hello ; 24 0000000F BA0E000000 mov edx, HelloLen ; 25 00000014 CD80 int 0x80 26 27 ;;; exit 28 00000016 BB00000000 mov ebx, 0 29 0000001B B801000000 mov eax, 1 30 00000020 CD80 int 0x80

11 section.data 12 00000000 48656C6C6F20746865- Hello db "Hello there!", 10, 10 13 00000009 7265210A0A 14 HelloLen equ $-Hello 15 16 section.text 17 global _start 18 _start: 19 20 ;;; print message 21 00000000 B804000000 mov eax, 4 ; write 22 00000005 BB01000000 mov ebx, 1 ; stdout 23 0000000A B9[00000000] mov ecx, Hello ; 24 0000000F BA0E000000 mov edx, HelloLen ; 25 00000014 CD80 int 0x80 26 27 ;;; exit 28 00000016 BB00000000 mov ebx, 0 29 0000001B B801000000 mov eax, 1 30 00000020 CD80 int 0x80

Hexdump

11 section.data 12 00000000 48656C6C6F20746865- Hello db "Hello there!", 10, 10 13 00000009 7265210A0A 14 HelloLen equ $-Hello 15 16 section.text 17 global _start 18 _start: 19 20 ;;; print message 21 00000000 B804000000 mov eax, 4 ; write 22 00000005 BB01000000 mov ebx, 1 ; stdout 23 0000000A B9[00000000] mov ecx, Hello ; 24 0000000F BA0E000000 mov edx, HelloLen ; 25 00000014 CD80 int 0x80 26 27 ;;; exit 28 00000016 BB00000000 mov ebx, 0 29 0000001B B801000000 mov eax, 1 30 00000020 CD80 int 0x80

11 section.data 12 00000000 48656C6C6F20746865- Hello db "Hello there!", 10, 10 13 00000009 7265210A0A 14 HelloLen equ $-Hello 15 16 section.text 17 global _start 18 _start: 19 20 ;;; print message 21 00000000 B804000000 mov eax, 4 ; write 22 00000005 BB01000000 mov ebx, 1 ; stdout 23 0000000A B9[00000000] mov ecx, Hello ; 24 0000000F BA0E000000 mov edx, HelloLen ; 25 00000014 CD80 int 0x80 26 27 ;;; exit 28 00000016 BB00000000 mov ebx, 0 29 0000001B B801000000 mov eax, 1 30 00000020 CD80 int 0x80 Why Hexadecimal?

0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

RAM 'H'

Processor-RAM Connection RAM Pentium

Our Goal for int x, y, sum; This Week x = 3; y = 5; sum = x + y;

Plan Mov & add instructions Registers Memory storage options

The mov instruction mov dest, source

The mov instruction 11 section.data 12 00000000 48656C6C6F20746865- Hello db "Hello there!", 10, 10 13 00000009 7265210A0A 14 HelloLen equ $-Hello 15 16 section.text 17 global _start 18 _start: 19 20 ;;; print message 21 00000000 B804000000 mov eax, 4 ; write 22 00000005 BB01000000 mov ebx, 1 ; stdout 23 0000000A B9[00000000] mov ecx, Hello ; 24 0000000F BA0E000000 mov edx, HelloLen ; 25 00000014 CD80 int 0x80 26 27 ;;; exit 28 00000016 BB00000000 mov ebx, 0 29 0000001B B801000000 mov eax, 1 30 00000020 CD80 int 0x80 mov dest, source

Operands mov reg, reg mov reg, mem mov mem, reg mov reg, imm mov mem, imm

Pentium Registers eax ebx ecx edx

section.data a dd 1234 section.text mov eax, 34 mov ebx, 12345 mov mov edx, eax ecx, ebx eax ebx ecx edx

section.data a dd 1234 section.text mov eax, dword[a] mov ebx, eax mov eax, 1234 mov dword[a], eax eax ebx ecx edx

We stopped here last time

Review bit nybble byte double-word

Review Hexadecimal: 0000 0 0001 1 0010 2 0011 3 0100 4 0101 5 0110 6 0111 7 1000 8 1001 9 1010 A 1011 B 1100 C 1101 D 1110 E 1111 F

0 1 2 1 00 01 10 2 2 11 0000 0001 2 4 =16 1110 1111 Review 0000 0000 0000 0001 2 8 =256 1111 1110 1111 1111

Review 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000001 11111111 11111111 11111111 11111110 11111111 11111111 11111111 11111111 2 32 = 4,294,967,296

Exercise section.data hello db "Hi!" hellol equ $-hello a dd 1234 section.text mov eax, 123456789 mov dword[a], eax mov dword[a], 0 mov ecx, dword[a] eax ebx ecx edx

The add instruction add dest, source

Exercise section.data a dd 1234 section.text mov eax, 3 mov ebx, 5 eax ebx add eax, ebx ecx edx

Exercise section.data a dd 1234 section.text mov eax, dword[a] add eax, 1 mov dword[a], eax eax ebx ecx edx

Exercise section.data a dd 1234 section.text add dword[a], 1 mov eax, dword[a] eax ebx ecx edx

int x = 3; int y = 5; int sum; Exercise sum = x + y; Translate this code into its assembly equivalent

int x = 3; int y = 5; int z = 10; int sum; sum = x + y + 2*z; Translate this code into its assembly equivalent Exercise

int x = 3; int y = 5; int z = 10; int sum; Exercise sum = x + 2*y - 3*(z-1); Translate this code into its assembly equivalent

Getting a sense of Speed of Execution

Getting a sense of Speed of Execution ; sum = x + 2*y + 3*(z-1) } mov eax,dword[x] add eax, dword[y] add eax, dword[y] mov ebx, dword[z] add ebx, -1 mov ecx, ebx add ebx, ebx add ebx, ecx add eax, ebx mov dword[sum], eax 2.8 GHz CPU 2.8 billion cycles/second 1instruction / cycle cycle =1/(2.8E+9) = 0.35 ns 10 instructions ==> 3.5 ns can compute 280 million similar equations in 1 second

We stopped here last time