Assembly Language (CSW 353)

Slides:



Advertisements
Similar presentations
Week 3. Assembly Language Programming  Difficult when starting assembly programming  Have to work at low level  Use processor instructions >Requires.
Advertisements

Assembly Language for Intel-Based Computers, 4 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and.
Basic Concepts COE 205 Computer Organization and Assembly Language
Data Representation Computer Organization &
Data Representation COE 205
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
Table 1. Software Hierarchy Levels.. Essential Tools An assembler is a program that converts source-code programs into a machine language (object file).
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
1 Introduction Chapter 1 n What is Assembly Language? n Data Representation.
Course overview Computer Organization and Assembly Languages Yung-Yu Chuang 2007/09/17 with slides by Kip Irvine.
Basic Concepts Computer Organization and Assembly Language.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#1) By Dr. Syed Noman.
Codes and number systems Introduction to Computer Yung-Yu Chuang with slides by Nisan & Schocken ( ) and Harris & Harris (DDCA)
Assembly Language for Intel-Based Computers, 5th Edition
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and copy this slide show for your personal use, or for.
Computers Organization & Assembly Language
CSU0014 Assembly Languages Homepage: Textbook: Kip R. Irvine, Assembly Language for Intel-Based Computers,
Summer 2014 Chapter 1: Basic Concepts. Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Chapter Overview Welcome to Assembly Language.
Assembly Language for x86 Processors 7th Edition
1 Modified from  Modified from 1998 Morgan Kaufmann Publishers Chapter Three: Arithmetic for Computers citation and following credit line is included:
Comp Sci 251 Intro 1 Computer organization and assembly language Wing Huen.
Chapter 1: Basic Concepts
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
Assembly Language for x86 Processors 7 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and copy this.
Number Systems. Today Decimal Hexadecimal Binary –Unsigned Binary –1’s Complement Binary –2’s Complement Binary.
CPU Internal memory I/O interface circuit System bus
Chapter 19 Number Systems. Irvine, Kip R. Assembly Language for Intel-Based Computers, Translating Languages English: Display the sum of A times.
CSNB374: Microprocessor Systems Chapter 1: Introduction to Microprocessor.
Introduction to Programming Instructor: Yong Tang Brookhaven National Laboratory Working on accelerator control (BNL Phone #)
Computer Organization and Assembly Languages 2007/11/10
Sahar Mosleh California State University San MarcosPage 1 Assembly language and Digital Circuit By Sahar Mosleh California State University San Marcos.
1 Chapter 1: Introduction Appendix A: Binary and Hexadecimal Tutorial Assembly Language for Intel-Based Computers, 3rd edition Kip R. Irvine.
1 Chapter 1: Basic Concepts Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine 9/6/2003.
Data Representation COE 308 Computer Architecture
CSC235 Computer Organization & Assembly Language
Invitation to Computer Science, C++ Version, Fourth Edition
Today's Agenda What is Computer Architecture?
Data Representation ICS 233
Lec 3: Data Representation
Assembly Language for x86 Processors 6th Edition
Data Representation.
3.1 Denary, Binary and Hexadecimal Number Systems
Data Representation Binary Numbers Binary Addition
Integer Real Numbers Character Boolean Memory Address CPU Data Types
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
Microprocessor Systems Design I
Microprocessor and Assembly Language
Microprocessor Systems Design I
COMP211 Computer Logic Design Lecture 1. Number Systems
Microprocessor and Assembly Language
Fundamentals & Ethics of Information Systems IS 201
University of Gujrat Department of Computer Science
Assembly Language for x86 Processors 6th Edition
Data Representation COE 301 Computer Organization
Number Representations and Basic Processor Architecture
Data Representation in Computer Systems
Information Representation
Computer Organization and Assembly Languages Yung-Yu Chuang 2006/09/18
Computer Organization and Assembly Language
University of Gujrat Department of Computer Science
Data Representation ICS 233
Comp Org & Assembly Lang
UNIT – 3 & 4. Data Representation and Internal
Computer Organization and Assembly Language
Networks & I/O Devices.
Part I Data Representation and 8086 Microprocessors
Data Representation COE 308 Computer Architecture
Presentation transcript:

Assembly Language (CSW 353) Introduction of Assembly Language http://www.bu.edu.eg/staff/rashaabdelkreem14 Assembly Language

Introduction of Assembly Language

Content Course Description Basic Concepts of Assembly Language Welcome to Assembly Language Virtual Machine Concept Data Representation Boolean Operations Assembly Language

Course Description Prerequisites: Textbook References: Structured Programming Language Textbook References: Assembly Language for Intel-Based Computers. Assembly language for x86 processors The Art of Assembly Language Resources: http://web.sau.edu/LillisKevinM/csci240/masmdocs/ http://kipirvine.com/asm/4th/asmsources/ http://forum.codecall.net/topic/62064-assembly-language-resources/ Assembly Language

Course Description Grading : Final Exam 65 Year work 10 Oral 10 Laboratory and Practice 15 Sum 100 Timing: Lecture 3 Practice 2 Exam 3 Assembly Language

Content Course Description Basic Concepts of Assembly Language Welcome to Assembly Language Virtual Machine Concept Data Representation Boolean Operations Assembly Language

Basic Concepts Welcome to Assembly Language Virtual Machine Concept Some Good Questions to Ask Virtual Machine Concept Data Representation Boolean Operations Assembly Language

Welcome to Assembly Language Some Good Questions to Ask What is Assembly Language? Why Learn Assembly Language? What is Machine Language? How is Assembly related to Machine Language? What is an Assembler? How is Assembly related to High-Level Language? Is Assembly Language portable? Assembly Language

What is Assembly Language? A low-level processor-specific programming language design to match the processor’s machine instruction set. Each assembly language instruction matches exactly one machine language instruction. We will focus on Intel based Assembly Instructions. It covers many different versions of CPUs that followed, from Intel; the 80188, 80186, 80286, 80386, 80486, Pentium, Pentium Pro, and so on. It describes the basics of 32-bit assembly language programming. Assembly Language

What is Assembly Language? A Hierarchy of Languages Assembly Language

Why Learn Assembly Language? To learn how high-level language code gets translated into machine language. To learn the computer’s hardware by direct access to memory, video controller, sound card, keyboard… To speed up applications by direct access to hardware. Assembly Language

What is Machine Language ML? Machine languages are lowest-level programming language and are the only languages understood by computers without translation. While easily understood by computers, machine languages are almost impossible for humans because they consist entirely of binary digits. Every CPU has its own specific machine language. Assembly Language

The accumulator. General-purpose register. What is Machine Language ML? Each ML instruction contains an op code (operation code) and zero or more operands. Examples: Opcode Operand Meaning ------------------------------------------- 40 increment the AX register 05 0005 add 0005 to AX The accumulator. General-purpose register. Assembly Language

How is Assembly related to Machine Language? Native to a processor: executed directly by hardware Instructions consist of binary code: 1s and 0s Assembly language Slightly higher-level language Readability of instructions is better than machine language One-to-one correspondence with machine language instructions Assemblers translate assembly to machine code Compilers translate high-level programs to machine code Either directly, or Indirectly via an assembler Assembly Language

What is an Assembler? An assembler is a type of computer program that interprets software programs written in assembly language into machine language, code and instructions that can be executed by a computer. For Example, MASM (Macro Assembler from Microsoft) Assembly Language

How is Assembly related to High-Level Language? Assembly Language

Basic Concepts Welcome to Assembly Language Virtual Machine Concept Some Good Questions to Ask Assembly Language Applications Virtual Machine Concept Data Representation Boolean Operations Assembly Language

Virtual Machine Concept A virtual machine (VM) is a software program or operating system that exhibits the behavior of a separate computer. is capable of performing tasks such as running applications and programs in a separate computer. VM (virtual machine) is a layer of abstraction that gives a program one simplified interface for interacting with a variety of physical computers and their operating systems. Assembly Language

Translating languages English: Display the sum of A times B plus C. C++: cout << (A * B + C); General Data Register Intel Machine Language: A1 00000000 F7 25 00000004 03 05 00000008 E8 00500000 Assembly Language: mov eax,A mul B add eax,C call WriteInt Assembly Language

Virtual machines Abstractions for computers Assembly Language

High-level language Level 5 Application-oriented languages Programs are compiled into assembly language (Level 4) cout << (A * B + C); Assembly Language

Assembly language Level 4 Instruction mnemonics that have a one-to-one correspondence to machine language Calls functions written at the operating system level (Level 3) Programs are translated into machine language (Level 2) mov eax, A mul B add eax, C call WriteInt Assembly Language

Operating system Level 3 Provides services Programs translated and run at the instruction set architecture level (Level 2) Assembly Language

Instruction set architecture Level 2 Also known as conventional machine language Executed by Level 1 program (microarchitecture, Level 1) A1 00000000 F7 25 00000004 03 05 00000008 E8 00500000 Assembly Language

Micro-architecture Level 1 Interprets conventional machine instructions (Level 2) Executed by digital hardware (Level 0) Assembly Language

Digital logic Level 0 CPU, constructed from digital logic gates System bus Memory Assembly Language

Basic Concepts Welcome to Assembly Language Virtual Machine Concept Some Good Questions to Ask Assembly Language Applications Virtual Machine Concept Data Representation Boolean Operations Assembly Language

Data representation Computer is a construction of digital circuits with two states: on and off You need to have the ability to translate between different representations to examine the content. Common number systems: binary, octal, decimal and hexadecimal Assembly Language

Binary representations Electronic Implementation Easy to store with bi-stable elements Reliably transmitted on noisy and inaccurate wires 0.0V 0.5V 2.8V 3.3V 1 Assembly Language

Binary numbers Digits are 1 and 0 (a binary digit is called a bit) 1 = true 0 = false MSB –most significant bit LSB –least significant bit Bit numbering: A bit string could have different interpretations Assembly Language

Unsigned binary integers Each digit (bit) is either 1 or 0 Each bit represents a power of 2: Every binary number is a sum of powers of 2 Assembly Language

Translating binary to decimal Weighted positional notation shows how to calculate the decimal value (Dec) of each binary bit: dec = (Dn-1  2n-1) + (Dn-2  2n-2) + ... + (D1  21) + (D0  20) D = binary digit binary 00001001 = decimal 9: (1  23) + (1  20) = 9 Assembly Language

Translating unsigned decimal to binary Repeatedly divide the decimal integer by 2. Each remainder is a binary digit in the translated value: 37 = 100101 Assembly Language

Binary addition Starting with the LSB, add each pair of digits, include the carry if present. Assembly Language

Integer storage sizes Standard sizes: Practice: What is the largest unsigned integer that may be stored in 20 bits? Assembly Language

Large measurements Kilobyte (KB), bytes Megabyte (MB), bytes Gigabyte (GB), bytes Terabyte (TB), bytes Petabyte, bytes Exabyte, bytes Zettabyte, bytes Yottabyte, bytes Assembly Language

Hexadecimal integers All values in memory are stored in binary. Because long binary numbers are hard to read, we use hexadecimal representation. Assembly Language

Translating binary to hexadecimal Each hexadecimal digit corresponds to 4 binary bits. Example: Translate the binary integer 000101101010011110010100 to hexadecimal: Assembly Language

Converting hexadecimal to decimal Multiply each digit by its corresponding power of 16: dec = (D3  163) + (D2  162) + (D1  161) + (D0  160) Examples: Hex 1234 = (1  163) + (2  162) + (3  161) + (4  160) = decimal 4,660. Hex 3BA4 = (3  163) + (11 * 162) + (10  161) + (4  160) = decimal 15,268. Assembly Language

Converting decimal to hexadecimal decimal 422 = 1A6 hexadecimal Assembly Language

Hexadecimal addition Divide the sum of two digits by the number base (16). The quotient becomes the carry value, and the remainder is the sum digit. 1 1 36 28 28 6A 42 45 58 4B 78 6D 80 B5 Important skill: Programmers frequently add and subtract the addresses of variables and instructions. Assembly Language

Hexadecimal subtraction When a borrow is required from the digit to the left, add 10h to the current digit's value: -1 C6 75 A2 47 24 2E Practice: The address of var1 is 00400020. The address of the next variable after var1 is 0040006A. How many bytes are used by var1? Assembly Language

Signed integers The highest bit indicates the sign. 1 = negative, 0 = positive If the highest digit of a hexadecimal integer is > 7, the value is negative. Examples: 8A, C5, A2, 9D Assembly Language

Two's complement notation For Binary Steps: Complement (reverse) each bit Add 1 Note that 00000001 + 11111111 = 00000000 Assembly Language

Hexadecimal Two’s Complement Steps: Complement (reverse) each digit (to reverse the bits of a hexadecimal digit is to subtract the digit from 15.) Add 1 Assembly Language

Unsigned 2’s Complement Subtraction Example: Find 0101 01002 – 0100 00112 84 -67 = 84 +(-67) = 17 0101 0100 0101 0100 – 0100 0011 + The carry of 1 indicates that no correction of the result is required. 1 1011 1101 0001 0001 2’s comp 84-67

Unsigned 2’s Complement Subtraction Example: Find 010000112 – 010101002 67 - 84= 67+ (-84) = -17 01000011 01000011 – 01010100 + The carry of 0 indicates that a correction of the result is required. Result = – (00010001) 2’s comp 10101100 11101111 00010001 2’s comp 67 - 84

Ranges of signed integers The highest bit is reserved for the sign. This limits the range: Assembly Language

Basic Concepts Welcome to Assembly Language Virtual Machine Concept Some Good Questions to Ask Assembly Language Applications Virtual Machine Concept Data Representation Boolean Operations Assembly Language

Boolean algebra Boolean expressions created from: NOT, AND, OR Assembly Language

Digital gate diagram for NOT: Inverts (reverses) a Boolean value Truth table for Boolean NOT operator: Digital gate diagram for NOT: Assembly Language

Digital gate diagram for AND: Truth if both are true Truth table for Boolean AND operator: Digital gate diagram for AND: Assembly Language

Digital gate diagram for OR: True if either is true Truth table for Boolean OR operator: Digital gate diagram for OR: Assembly Language

Implementation of gates Assembly Language

Operator Precedence Examples showing the order of operations: Assembly Language

Truth Tables (1 of 2) A Boolean function has one or more Boolean inputs, and returns a single Boolean output. A truth table shows all the inputs and outputs of a Boolean function Example: X  Y Assembly Language

Truth Tables (2 of 2) Example: X  Y Assembly Language

Summary Assembly language helps you learn how software is constructed at the lowest levels Assembly language has a one-to-one relationship with machine language Each layer in a computer's architecture is an abstraction of a machine layers can be hardware or software Boolean expressions are essential to the design of computer hardware and software Assembly Language