2.1 intro to assembly and machine language

21
Microprocessor Systems EE 180

Upload: johnneilbibera

Post on 07-Jan-2016

237 views

Category:

Documents


3 download

DESCRIPTION

Assembly and Machine Language

TRANSCRIPT

Page 1: 2.1 Intro to Assembly and Machine Language

7/17/2019 2.1 Intro to Assembly and Machine Language

http://slidepdf.com/reader/full/21-intro-to-assembly-and-machine-language 1/21

Microprocessor

SystemsEE 180

Page 2: 2.1 Intro to Assembly and Machine Language

7/17/2019 2.1 Intro to Assembly and Machine Language

http://slidepdf.com/reader/full/21-intro-to-assembly-and-machine-language 2/21

Functional Representation of SimpleMPU

Page 3: 2.1 Intro to Assembly and Machine Language

7/17/2019 2.1 Intro to Assembly and Machine Language

http://slidepdf.com/reader/full/21-intro-to-assembly-and-machine-language 3/21

Microcomputer Programming

LanguagesMicrocomputers are usually programmed

using semi-English language statementsassembly language!" #n addition toassem$ly languages% microcomputers use amore understanda$le human-orientedlanguage called &high-level language'"

(o matter )hat type of language is used to)rite programs% microcomputers onlyunderstand $inary num$ers"

Page 4: 2.1 Intro to Assembly and Machine Language

7/17/2019 2.1 Intro to Assembly and Machine Language

http://slidepdf.com/reader/full/21-intro-to-assembly-and-machine-language 4/21

Micro Prog langMachine Language

*ssem$ly Language

+igh-Le,el Language

Page 5: 2.1 Intro to Assembly and Machine Language

7/17/2019 2.1 Intro to Assembly and Machine Language

http://slidepdf.com/reader/full/21-intro-to-assembly-and-machine-language 5/21

Machine Language* microprocessor has a uniue set of machine

language instructions de.ned $y itsmanufacturer"

 

(o t)o microprocessors $y t)o di/erentmanufacturers ha,e the same machine

language instruction set"

For eample% the #ntel 808 microprocessoruses the code 01281 for its addition

instruction )hereas the Motorola 8000 uses

Page 6: 2.1 Intro to Assembly and Machine Language

7/17/2019 2.1 Intro to Assembly and Machine Language

http://slidepdf.com/reader/full/21-intro-to-assembly-and-machine-language 6/21

*t the most elementary le,el% a microprocessor

program can $e )ritten using its instruction set in$inary machine language" *s an eample% aprogram )ritten for adding t)o num$ers using the#ntel 808 machine language is

Page 7: 2.1 Intro to Assembly and Machine Language

7/17/2019 2.1 Intro to Assembly and Machine Language

http://slidepdf.com/reader/full/21-intro-to-assembly-and-machine-language 7/21

4$,iously% the program is ,ery di5cult tounderstand% unless the programmerremem$ers all the 808 codes% )hich isimpractical"

it is almost impossi$le to )rite an error-free

program at the .rst try

Page 8: 2.1 Intro to Assembly and Machine Language

7/17/2019 2.1 Intro to Assembly and Machine Language

http://slidepdf.com/reader/full/21-intro-to-assembly-and-machine-language 8/21

 6o increase the programmer7s e5ciency in

)riting a machine language program%headecimal num$ers rather than $inarynum$ers are used" 6he follo)ing is the sameaddition program in headecimal% using the

#ntel 808 instruction set

Page 9: 2.1 Intro to Assembly and Machine Language

7/17/2019 2.1 Intro to Assembly and Machine Language

http://slidepdf.com/reader/full/21-intro-to-assembly-and-machine-language 9/21

9hallenge#t is easier to detect an error in a headecimal

program% $ecause each $yte contains only ::::: headecimal digits"

Page 10: 2.1 Intro to Assembly and Machine Language

7/17/2019 2.1 Intro to Assembly and Machine Language

http://slidepdf.com/reader/full/21-intro-to-assembly-and-machine-language 10/21

9hallenge#t is easier to detect an error in a headecimal

program% $ecause each $yte contains only 3headecimal digits"

Page 11: 2.1 Intro to Assembly and Machine Language

7/17/2019 2.1 Intro to Assembly and Machine Language

http://slidepdf.com/reader/full/21-intro-to-assembly-and-machine-language 11/21

*ssem$ly LanguageEach line in an assem$ly language program

includes four .elds

1" La$el .eld3" #nstruction% mnemonic% or op-code .eld

3 . Operand feld

;" 9omment .eld

Page 12: 2.1 Intro to Assembly and Machine Language

7/17/2019 2.1 Intro to Assembly and Machine Language

http://slidepdf.com/reader/full/21-intro-to-assembly-and-machine-language 12/21

*s an eample% a typical program for adding t)o 1-$it num$ers)ritten in 808 assem$ly language is

0F; < +L6 < +*L6 -= Stop the program

Page 13: 2.1 Intro to Assembly and Machine Language

7/17/2019 2.1 Intro to Assembly and Machine Language

http://slidepdf.com/reader/full/21-intro-to-assembly-and-machine-language 13/21

4$,iously% programming in assem$lylanguage is more con,enient thanprogramming in machine language% $ecauseeach mnemonic gi,es an idea of the type ofoperation it is supposed to perform" 6herefore%)ith assem$ly language% the programmerdoes not ha,e to .nd the numerical op-codesfrom a ta$le of the instruction set% andprogramming e5ciency is signi.cantlyimpro,ed"

Page 14: 2.1 Intro to Assembly and Machine Language

7/17/2019 2.1 Intro to Assembly and Machine Language

http://slidepdf.com/reader/full/21-intro-to-assembly-and-machine-language 14/21

 6ypes of *ssem$lersOne-Pass Assembler" 6his assem$ler goes through the

assem$ly language program once and translates it into amachine language program" 6his assem$ler has the pro$lem ofde.ning for)ard references" 6his means that a >UMP instruction

using an address that appears later in the program must $ede.ned $y the programmer after the program is assem$led"

Two-Pass Assembler. 6his assem$ler scans the assem$lylanguage program t)ice" #n the .rst pass% this assem$lercreates a sym$ol ta$le" * sym$ol ta$le consists of la$els )ith

addresses assigned to them" 6his )ay la$els can $e used for >UMP statements and no address calculation has to $e done $ythe user" 4n the second pass% the assem$ler translates theassem$ly language program into the machine code" 6he t)o-pass assem$ler is more desira$le and much easier to use"

Page 15: 2.1 Intro to Assembly and Machine Language

7/17/2019 2.1 Intro to Assembly and Machine Language

http://slidepdf.com/reader/full/21-intro-to-assembly-and-machine-language 15/21

Macroassembler. 6his type of assem$ler translates aprogram )ritten in macrolanguage into the machinelanguage" 6his assem$ler lets the programmer de.ne all

instruction seuences using macros" (ote that% $y usingmacros% the programmer can assign a name to aninstruction seuence that appears repeatedly in aprogram

Cross Assembler. 6his type of assem$ler is typically

resident in a processor and assem$les programs foranother for )hich it is )ritten" 6he cross assem$lerprogram is )ritten in a high-le,el language so that it canrun on di/erent types of processors that understand thesame high-le,el language"

Page 16: 2.1 Intro to Assembly and Machine Language

7/17/2019 2.1 Intro to Assembly and Machine Language

http://slidepdf.com/reader/full/21-intro-to-assembly-and-machine-language 16/21

Resident Assembler. 6his type of assem$lerassem$les programs for a processor in )hichit is resident"

Meta-assembler. 6his type of assem$ler canassem$le programs for many di/erent typesof processors" 6he programmer usuallyde.nes the particular processor $eing used"

Page 17: 2.1 Intro to Assembly and Machine Language

7/17/2019 2.1 Intro to Assembly and Machine Language

http://slidepdf.com/reader/full/21-intro-to-assembly-and-machine-language 17/21

 6he assem$ler must ?no) )here

one .eld starts and another endsMost assem$lers allo) the programmer to use a

special sym$ol or delimiter to indicate the$eginning or end of each .eld" 6ypicaldelimiters used are spaces% commas%semicolons% and colons

Spaces are used $et)een .elds"

9ommas %! are used $et)een addresses in anoperand .eld"

* semicolon @! is used $efore a comment"

* colon ! or no delimiter is used after a la$el"

Page 18: 2.1 Intro to Assembly and Machine Language

7/17/2019 2.1 Intro to Assembly and Machine Language

http://slidepdf.com/reader/full/21-intro-to-assembly-and-machine-language 18/21

 6he user must de.ne the type of num$ersystem used in some )ay" 6his is usually done$y using a letter follo)ing the num$er" 6ypicalletters used areA for $inary

B for octal

+ for headecimal

Page 19: 2.1 Intro to Assembly and Machine Language

7/17/2019 2.1 Intro to Assembly and Machine Language

http://slidepdf.com/reader/full/21-intro-to-assembly-and-machine-language 19/21

*ssem$lers generally reuire headecimalnum$ers to start )ith a digit"

* 0 is typically used if the .rst digit of theheadecimal num$er is a letter"

 6his is done to distinguish $et)een num$ersand la$els"

For eample% most assem$lers )ill reuire thenum$er *C+ to $e represented as 4*C+"

Page 20: 2.1 Intro to Assembly and Machine Language

7/17/2019 2.1 Intro to Assembly and Machine Language

http://slidepdf.com/reader/full/21-intro-to-assembly-and-machine-language 20/21

Sample *ssem$ly code

Page 21: 2.1 Intro to Assembly and Machine Language

7/17/2019 2.1 Intro to Assembly and Machine Language

http://slidepdf.com/reader/full/21-intro-to-assembly-and-machine-language 21/21

(et topic*ssem$ly Language #nstruction Formats

#nstruction Sets

*ddressing ModesSu$routine 9alls

+igh Le,el Language