assembly language -- overview cisp 310 prof. chapman

22
Assembly Language -- Overview CISP 310 Prof. Chapman

Upload: evan-mccoy

Post on 27-Dec-2015

239 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Assembly Language -- Overview CISP 310 Prof. Chapman

Assembly Language -- Overview

CISP 310Prof. Chapman

Page 2: Assembly Language -- Overview CISP 310 Prof. Chapman

CRC CISP 310 Chapman

Assembly Language Is…

Not A High-Level Language

Page 3: Assembly Language -- Overview CISP 310 Prof. Chapman

CRC CISP 310 Chapman

High-Level Languages (HLL)

void main() { do something }

*.c file

Compiler not text,binary

*.obj file

not text,binary

*.exe file

Linker

C libraryfiles (existing *.obj files)

Page 4: Assembly Language -- Overview CISP 310 Prof. Chapman

CRC CISP 310 Chapman

High-Level Languages (HLL)

C language program

*.c file

Programmer’s focus is on getting the syntax and structured logic correct inthe source code

Page 5: Assembly Language -- Overview CISP 310 Prof. Chapman

CRC CISP 310 Chapman

High-Level Languages

C++ languageprogram

Object-oriented (OO)

*.cpp file

Programmer’s focus is on getting the syntax and OO logic correct

Page 6: Assembly Language -- Overview CISP 310 Prof. Chapman

CRC CISP 310 Chapman

HLL Development Techniques

Compiler catches syntax mistakes

Compiler translates from text into processor-specific binary codes (object file)

Page 7: Assembly Language -- Overview CISP 310 Prof. Chapman

CRC CISP 310 Chapman

HLL Development Techniques

Memory for data storage and program code itself is automatically allocated

Linker creates *.exe file

Page 8: Assembly Language -- Overview CISP 310 Prof. Chapman

CRC CISP 310 Chapman

Assembly is Not a HLL

An assembly programmer has to deal directly with the processor memory (RAM)

The instructions are much more cryptic like “move data to a different memory address”

Page 9: Assembly Language -- Overview CISP 310 Prof. Chapman

CRC CISP 310 Chapman

Assembly is Not a HLL

We must write code to enable I/O between keyboard, files, and monitor (generally using operating system procedures)

We must use a different design philosophy besides OO

Page 10: Assembly Language -- Overview CISP 310 Prof. Chapman

CRC CISP 310 Chapman

Assembly is Not a HLL

Loop and if logic is implemented differently in assembly than with HLL

Page 11: Assembly Language -- Overview CISP 310 Prof. Chapman

CRC CISP 310 Chapman

HLL OO Procedure

Let’s look at the code that defines the effect of clicking thisButton control (VB.NET language)

Page 12: Assembly Language -- Overview CISP 310 Prof. Chapman

CRC CISP 310 Chapman

' called when Call Peedy button is clicked Private Sub btnCall_Click(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles btnCall.Click m_objMSpeaker.Show(0)

' move Peedy to a specified location m_objMSpeaker.MoveTo(Convert.ToInt16(Cursor.Position.X - 100), Convert.ToInt16(Cursor.Position.Y + 130))

m_objMSpeaker.Play("Wave")

' tell Peedy what to say m_objMSpeaker.Speak("Hello, I'm Peedy. Please say or select the name of the person whose phone number you would like to find.", "")

m_objMSpeaker.Speak("If you wish to say the name, press the Scroll Lock key then speak the name.", "")

m_objMSpeaker.Play("RestPose")

cboName.Enabled = True btnCall.Enabled = False End Sub ' btnCall_Click

HLL comment

subroutine with 7 HLL statements

Page 13: Assembly Language -- Overview CISP 310 Prof. Chapman

CRC CISP 310 Chapman

HLL Translated Into Assembly

Every high-level instruction is equivalent to a group of many assembly instructions

Each assembly instruction is cryptic

Page 14: Assembly Language -- Overview CISP 310 Prof. Chapman

CRC CISP 310 Chapman

m_objMSpeaker.Speak("Hello, I'm Peedy. Please say or select the name of the person whose phone number you would like to find.", "")

This HLL statement

Eight Assembly statements000000f5 mov esi,dword ptr [ebx+000000ECh] 000000fb push dword ptr ds:[02050024h] 00000101 mov ecx,esi 00000103 mov edx,dword ptr ds:[020529C4h] 00000109 mov eax,dword ptr [ecx] 0000010b mov eax,dword ptr [eax+0Ch] 0000010e mov eax,dword ptr [eax+000001ACh] 00000114 call dword ptr [eax+5Ch]

=

Page 15: Assembly Language -- Overview CISP 310 Prof. Chapman

CRC CISP 310 Chapman

Sample AssemblyAssembly Instruction

000000f5 mov esi,dword ptr [ebx+000000ECh]

operation code operands

register (memory)

hexadecimalconstant

Page 16: Assembly Language -- Overview CISP 310 Prof. Chapman

CRC CISP 310 Chapman

Assembly Language Is…

Not Self-Documenting

Page 17: Assembly Language -- Overview CISP 310 Prof. Chapman

CRC CISP 310 Chapman

What Does This Accomplish?

000000f5 mov esi,dword ptr [ebx+000000ECh]

000000fb push dword ptr ds:[02050024h]

00000101 mov ecx,esi

00000103 mov edx,dword ptr ds:[020529C4h]

00000109 mov eax,dword ptr [ecx]

0000010b mov eax,dword ptr [eax+0Ch]

0000010e mov eax,dword ptr [eax+000001ACh]

00000114 call dword ptr [eax+5Ch]

00000117 nop Huh?

Page 18: Assembly Language -- Overview CISP 310 Prof. Chapman

CRC CISP 310 Chapman

What’s Difficult About Assembly?

Cannot easily see purpose of code segment (see previous slide)

Not portable (separate assembly instructions for Intel, Motorola, … processors)

Page 19: Assembly Language -- Overview CISP 310 Prof. Chapman

CRC CISP 310 Chapman

What’s Right With Assembly?

Every language is based on machine code, and assembly is closest to machine code

Assembly is necessary to write high-level language translators Java/C++/C#/VB.NET/Fortran/…)

Page 20: Assembly Language -- Overview CISP 310 Prof. Chapman

CRC CISP 310 Chapman

What’s Right With Assembly?

We can write I/O code to communicate between our program and peripherals (cameras, iPods, etc.)

We can write instructions that are optimized for our processor, creating very very small and very very fast programs

Page 21: Assembly Language -- Overview CISP 310 Prof. Chapman

CRC CISP 310 Chapman

What You Will Learn

At the end of this course, you will be able to create simple command-line programs that accept input from the keyboard and display text output to the monitorYou will finally understand the structure of memory and the inner workings of the processor chip

Page 22: Assembly Language -- Overview CISP 310 Prof. Chapman

CRC CISP 310 Chapman

Ending Metaphor

HLL programmers: authors who develop the content of a book but leave the details of typesetting, printing, sales, and distribution to someone else

Assembly programmers: authors who can both write and publish, sell, and distribute their own books. They understand programming at a deeper level than a HLL programmer.