chapt_03 (1)
TRANSCRIPT
-
7/25/2019 chapt_03 (1)
1/51
Assembly Language for Intel-BasedAssembly Language for Intel-Based
Computers, 4Computers, 4thth
EditionEdition
Chapter 3: Assembly Language
Fundamentals
!" #earson Edu!ation, $%%$& All rights reser'ed& (ou may modify and !opy this slide sho) for your personal use, or foruse in the !lassroom, as long as this !opyright statement, the author*s name, and the title are not !hanged&
+ Chapter !orre!tionseb" Assembly language sour!eseb"
Slides prepared by Kip R. Irvine
Revision date: 09/15/2002
ip .& Ir'ine
http://www.nuvisionmiami.com/books/asm/corrections.htmhttp://www.nuvisionmiami.com/kip/asm.htmhttp://www.nuvisionmiami.com/kip/asm.htmhttp://www.nuvisionmiami.com/books/asm/corrections.htm -
7/25/2019 chapt_03 (1)
2/51
Irvine, Kip R. Assembly eb site E/amples 2
Chapter 0'er'ie)Chapter 0'er'ie)
+ Basi! Elements of Assembly Language
+ E/ample: Adding and 1ubtra!ting Integers
+ Assembling, Lin2ing, and .unning #rograms
+ efining ata+ 1ymboli! Constants
+ .eal-Address ode #rogramming
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
3/51
Irvine, Kip R. Assembly eb site E/amples
Basi! Elements of Assembly LanguageBasi! Elements of Assembly Language
+ Integer !onstants+ Integer e/pressions
+ Chara!ter and string !onstants
+ .eser'ed )ords and identifiers
+ ire!ti'es and instru!tions
+ Labels
+ nemoni!s and 0perands
+Comments+ E/amples
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
4/51
Irvine, Kip R. Assembly eb site E/amples !
Integer ConstantsInteger Constants
+ 0ptional leading 5 or 6 sign
+ binary, de!imal, he/ade!imal, or o!tal digits
+ Common radi/ !hara!ters:
+ h 6 he/ade!imal
+ d 6 de!imal+ b 6 binary
+ r 6 en!oded real
E/amples: 3%d, 7Ah, 4$, 88%8b9e/ade!imal beginning )ith letter: %Ah
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
5/51
Irvine, Kip R. Assembly eb site E/amples "
Integer E/pressionsInteger E/pressions
+ 0perators and pre!eden!e le'els:
+ E/amples:
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
6/51
Irvine, Kip R. Assembly eb site E/amples #
Chara!ter and 1tring ConstantsChara!ter and 1tring Constants
+ En!lose !hara!ter in single or double ;uotes
+ *A*,
-
7/25/2019 chapt_03 (1)
7/51Irvine, Kip R. Assembly eb site E/amples $
.eser'ed ords and Identifiers.eser'ed ords and Identifiers
+ .eser'ed )ords Appendi/ " !annot be used as
identifiers+ Instru!tion mnemoni!s, dire!ti'es, type attributes,
operators, predefined symbols
+ Identifiers
+ 8-$4@ !hara!ters, in!luding digits+ !ase insensiti'e by default"
+ first !hara!ter must be a letter, , , or
+ ire!ti'es+ !ommand understood by the assembler
+ not part of Intel instru!tion set
+ !ase insensiti'e
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
8/51Irvine, Kip R. Assembly eb site E/amples %
ire!ti'esire!ti'es
+ Commands that are re!ogni>ed and a!tedupon by the assembler
+ Dot part of the Intel instru!tion set
+ sed to de!lare !ode, data areas, sele!t
memory model, de!lare pro!edures, et!&+ ifferent assemblers ha'e different dire!ti'es
+ DA1 = A1, for e/ample
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
9/51Irvine, Kip R. Assembly eb site E/amples &
Instru!tionsInstru!tions
+ Assembled into ma!hine !ode by assembler+ E/e!uted at runtime by the C#
+ ember of the Intel IA-3$ instru!tion set
+ #arts
+ Label
+ nemoni!
+ 0perand
+ Comment
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
10/51Irvine, Kip R. Assembly eb site E/amples '0
LabelsLabels
+ A!t as pla!e mar2ers+ mar2s the address offset" of !ode and data
+ Follo) identifer rules
+ ata label
+ must be uni;ue
+ e/ample: myArray not follo)ed by !olon"
+ Code label
+ target of Gump and loop instru!tions
+ e/ample: L1: follo)ed by !olon"
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
11/51Irvine, Kip R. Assembly eb site E/amples ''
nemoni!s and 0perandsnemoni!s and 0perands
+ Instru!tion nemoni!s
+
-
7/25/2019 chapt_03 (1)
12/51
Irvine, Kip R. Assembly eb site E/amples '2
CommentsComments
+ Comments are good
+ e/plain the program*s purpose+ )hen it )as )ritten, and by )hom
+ re'ision information
+ tri!2y !oding te!hni;ues
+ appli!ation-spe!ifi! e/planations+ 1ingle-line !omments
+ begin )ith semi!olon "
+ ulti-line !omments
+ begin )ith C0EDJ dire!ti'e and a programmer-!hosen !hara!ter
+ end )ith the same programmer-!hosen !hara!ter
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
13/51
Irvine, Kip R. Assembly eb site E/amples '
Instru!tion Format E/amplesInstru!tion Format E/amples
+ Do operands+ st! set Carry flag
+ 0ne operand
+ in! ea/ register
+ in! myByte memory
+ J)o operands
+ add eb/,e!/ register, register
+ sub myByte,$ memory, !onstant
+ add ea/,37 K $ register, !onstant-e/pression
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
14/51
Irvine, Kip R. Assembly eb site E/amples '!
E/ample: Adding and 1ubtra!ting IntegersE/ample: Adding and 1ubtra!ting Integers
TITLE Add and Subtract (AddSub.asm)
; This program adds and subtracts 32-bit integers.
INL!"E Ir#ine32.inc
.codemain $%&
mo# ea'****h ; EA+ , ****h
add ea'****h ; EA+ , ****h
sub ea'2****h ; EA+ , 3****h
ca// "ump%egs ; disp/a0 registers
e'it
main EN"$
EN" main
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
15/51
Irvine, Kip R. Assembly eb site E/amples '"
E/ample 0utputE/ample 0utput
#rogram output, sho)ing registers and flags:
EA+,***3**** E1+,"*** E+,****** E"+,
ESI,******** E"I,******** E1$,**2* ES$,**2
EI$,****2 EL,*****2*4 ,* S,* 5,* &,*
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
16/51
Irvine, Kip R. Assembly eb site E/amples '#
1uggested Coding 1tandards1uggested Coding 1tandards 8 of $"8 of $"
+1ome approa!hes to !apitali>ation+ !apitali>e nothing
+ !apitali>e e'erything
+ !apitali>e all reser'ed )ords, in!luding instru!tionmnemoni!s and register names
+ !apitali>e only dire!ti'es and operators
+ 0ther suggestions
+ des!ripti'e identifier names
+spa!es surrounding arithmeti! operators+ blan2 lines bet)een pro!edures
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
17/51
Irvine, Kip R. Assembly eb site E/amples '$
1uggested Coding 1tandards1uggested Coding 1tandards $ of $"$ of $"
+ Indentation and spa!ing
+ !ode and data labels 6 no indentation
+ e/e!utable instru!tions 6 indent 4- spa!es
+ !omments: begin at !olumn 4%-4, aligned 'erti!ally
+ 8-3 spa!es bet)een instru!tion and its operands
+ e/: mo' a/,b/
+ 8-$ blan2 lines bet)een pro!edures
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
18/51
Irvine, Kip R. Assembly eb site E/amples '%
Alternati'e Hersion of Add1ubAlternati'e Hersion of Add1ub
TITLE Add and Subtract (AddSubA/t.asm)
; This program adds and subtracts 32-bit integers..364.7&"EL 8/atstdca//.STA9 *:4
E'it$rocess $%&T& dE'itode&9E E'it$rocess*
main EN"$EN" main
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
19/51
Irvine, Kip R. Assembly eb site E/amples '&
#rogram Jemplate#rogram Jemplate
TITLE $rogram Temp/ate (Temp/ate.asm)
; $rogram "escriptione
+ segment type
+ E/ample: add1ub&map
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://addsubmap.txt/http://addsubmap.txt/http://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
25/51
Irvine, Kip R. Assembly eb site E/amples 2"
efining ataefining ata
+ Intrinsi! ata Jypes
+ ata efinition 1tatement
+ efining B(JE and 1B(JE ata
+ efining 0. and 10. ata
+ efining 0. and 10. ata
+ efining M0. ata
+ efining JB(JE ata
+ efining .eal Dumber ata
+ Little Endian 0rder
+ Adding Hariables to the Add1ub #rogram
+ e!laring ninitiali>ed ata
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
26/51
Irvine, Kip R. Assembly eb site E/amples 2#
Intrinsi! ata JypesIntrinsi! ata Jypes 8 of $"8 of $"
+ B(JE, 1B(JE
+ N-bit unsigned integer N-bit signed integer
+ 0., 10.
+ 87-bit unsigned O signed integer
+ 0., 10.+ 3$-bit unsigned O signed integer
+ M0.
+ 74-bit integer
+ JB(JE+ N%-bit integer
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
27/51
Irvine, Kip R. Assembly eb site E/amples 2$
Intrinsi! ata JypesIntrinsi! ata Jypes $ of $"$ of $"
+ .EAL4
+ 4-byte IEEE short real
+ .EALN
+ N-byte IEEE long real+ .EAL8%
+ 8%-byte IEEE e/tended real
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
28/51
Irvine, Kip R. Assembly eb site E/amples 2%
ata efinition 1tatementata efinition 1tatement
+ A data definition statement sets aside storage inmemory for a 'ariable&
+ ay optionally assign a name label" to the data
+1ynta/:PnameQ diretiveinitiali!erP,initiali!erQ & & &
+ All initiali>ers be!ome binary data in memory
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
29/51
Irvine, Kip R. Assembly eb site E/amples 2&
efining B(JE and 1B(JE ataefining B(JE and 1B(JE ata
#a/ue 1?TE @A@ ; character constant
#a/ue2 1?TE * ; sma//est unsigned b0te
#a/ue3 1?TE 2 ; /argest unsigned b0te
#a/ue S1?TE -26 ; sma//est signed b0te
#a/ue S1?TE 2 ; /argest signed b0te
#a/ue4 1?TE B ; uninitia/iCed b0te
Ea!h of the follo)ing defines a single byte of storage:
A 'ariable name is a data label that implies an offset an address"&
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
30/51
Irvine, Kip R. Assembly eb site E/amples 0
efining Bytesefining Bytes
/ist 1?TE *2*3**
/ist2 1?TE *2*3**
1?TE *4**6*
1?TE 662636
/ist3 1?TE B32h******b
/ist 1?TE *Ah2*hDA22h
E/amples that use multiple initiali>ers:
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
31/51
Irvine, Kip R. Assembly eb site E/amples '
efining 1tringsefining 1trings 8 of 3"8 of 3"
+ A string is implemented as an array of !hara!ters+ For !on'enien!e, it is usually en!losed in ;uotation mar2s
+ It usually has a null byte at the end
+ E/amples:
str 1?TE FEnter 0our nameF*
str2 1?TE @Error< ha/ting program@*
str3 1?TE @A@@E@@I@@&@@!@
greeting 1?TE F=e/come to the Encr0ption "emo program F
1?TE Fcreated b0 9ip Ir#ine.F*
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
32/51
Irvine, Kip R. Assembly eb site E/amples 2
efining 1tringsefining 1trings $ of 3"$ of 3"
+ Jo !ontinue a single string a!ross multiple lines, end
ea!h line )ith a !omma:
menu 1?TE FhecGing AccountF*dh*ah*dh*ah
F. reate a ne accountF*dh*ah
F2. &pen an e'isting accountF*dh*ah
F3. redit the accountF*dh*ah
F. "ebit the accountF*dh*ah
F. E'itF*ah*ah
FhoiceH F*
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
33/51
Irvine, Kip R. Assembly eb site E/amples
efining 1tringsefining 1trings 3 of 3"3 of 3"
+ End-of-line !hara!ter se;uen!e:
+ %h = !arriage return
+ %Ah = line feed
str 1?TE FEnter 0our name< F*"h*Ah
1?TE FEnter 0our address< F*
neLine 1?TE *"h*Ah*
Idea: efine all strings used by your program in the samearea of the data segment&
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
34/51
Irvine, Kip R. Assembly eb site E/amples !
sing the # 0peratorsing the # 0perator
+ se # to allo!ate !reate spa!e for" an array or
string&
+ Counter and argument must be !onstants or !onstante/pressions
#ar 1?TE 2* "!$(*) ; 2* b0tes a// eua/ to Cero
#ar2 1?TE 2* "!$(B) ; 2* b0tes uninitia/iCed
#ar3 1?TE "!$(FSTA9F) ; 2* b0tes< FSTA9STA9STA9STA9F
#ar 1?TE *3 "!$(*)2*
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
35/51
Irvine, Kip R. Assembly eb site E/amples "
efining 0. and 10. ataefining 0. and 10. ata
+ efine storage for 87-bit integers
+ or double !hara!ters
+ single 'alue or multiple 'alues
ord =&%" 43 ; /argest unsigned #a/ueord2 S=&%" J3246 ; sma//est signed #a/ue
ord3 =&%" B ; uninitia/iCed unsigned
ord =&%" FA1F ; doub/e characters
m0List =&%" 23 ; arra0 o8 ords
arra0 =&%" "!$(B) ; uninitia/iCed arra0
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
36/51
Irvine, Kip R. Assembly eb site E/amples #
efining 0. and 10. ataefining 0. and 10. ata
#a/ "=&%" 2346h ; unsigned
#a/2 S"=&%" J26346 ; signed
#a/3 "=&%" 2* "!$(B) ; unsigned arra0
#a/ S"=&%" J3J2J* ; signed arra0
1torage definitions for signed and unsigned 3$-bitintegers:
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
37/51
Irvine, Kip R. Assembly eb site E/amples $
efining M0., JB(JE, .eal ataefining M0., JB(JE, .eal ata
uad K=&%" 23462346h
#a/ T1?TE *********2346:Ahr>a/ %EAL -2.
r>a/2 %EAL6 3.2E-24*
r>a/3 %EAL* .4E*:4
ShortArra0 %EAL 2* "!$(*.*)
1torage definitions for ;uad)ords, tenbyte 'alues,
and real numbers:
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
38/51
Irvine, Kip R. Assembly eb site E/amples %
Little Endian 0rderLittle Endian 0rder
+ All data types larger than a byte store their indi'idualbytes in re'erse order& Jhe least signifi!ant byte o!!ursat the first lo)est" memory address&
+ E/ample:#a/ "=&%" 2346h
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
39/51
Irvine, Kip R. Assembly eb site E/amples &
Adding Hariables to Add1ubAdding Hariables to Add1ub
TITLE Add and Subtract >ersion 2 (AddSub2.asm)
; This program adds and subtracts 32-bit unsigned; integers and stores the sum in a #ariab/e.INL!"E Ir#ine32.inc.data#a/ "=&%" ****h#a/2 "=&%" ****h#a/3 "=&%" 2****h
8ina/>a/ "=&%" B.codemain $%&
mo# ea'#a/ ; start ith ****hadd ea'#a/2 ; add ****hsub ea'#a/3 ; subtract 2****h
mo# 8ina/>a/ea' ; store the resu/t (3****h)ca// "ump%egs ; disp/a0 the registerse'it
main EN"$EN" main
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
40/51
Irvine, Kip R. Assembly eb site E/amples !0
e!laring nitiali>ed atae!laring nitiali>ed ata
+ se the &dataR dire!ti'e to de!lare an unintiali>ed data segment:
.dataB
bigArra0 "=&%" *** "!$(B)
+ Hersus
.data sma//Arra0 "=&%" * "!$(*)
bigArra0 "=&%" *** "!$(B)
Ad'antage: the program*s EE file si>e is redu!ed&
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
41/51
Irvine, Kip R. Assembly eb site E/amples !'
1ymboli! Constants1ymboli! Constants
+ E;ual-1ign ire!ti'e
+ Cal!ulating the 1i>es of Arrays and 1trings
+ EM ire!ti'e
+ JEJEM ire!ti'e
nli2e a 'ariable definition, a symboli! !onstant does nouse any storage&
1ymbols are used only during the assembly time&
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
42/51
Irvine, Kip R. Assembly eb site E/amples !2
E;ual-1ign ire!ti'eE;ual-1ign ire!ti'e
+ name= e"pression
+ e/pression is a 3$-bit integer e/pression or !onstant"
+ may be redefined
+ nameis !alled a symboli! !onstant
+ good programming style to use symbols
EscGe0 , 2
mo# a/ EscGe0
ount , Arra0 ount "up(*)
ount , *
7o# a/ ount
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
43/51
Irvine, Kip R. Assembly eb site E/amples !
Cal!ulating the 1i>e of a Byte ArrayCal!ulating the 1i>e of a Byte Array
+ !urrent lo!ation !ounter: + subtra!t address of list
+ differen!e is the number of bytes
/ist 1?TE *2*3**
ListSiCe , (M - /ist)
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
44/51
Irvine, Kip R. Assembly eb site E/amples !!
Cal!ulating the 1i>e of a ord ArrayCal!ulating the 1i>e of a ord Array
+ !urrent lo!ation !ounter: + subtra!t address of list
+ differen!e is the number of bytes
+ di'ide by $ the si>e of a )ord"
/ist =&%" ***h2***h3***h***h
ListSiCe , (M - /ist) 2
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
45/51
Irvine, Kip R. Assembly eb site E/amples !"
Cal!ulating the 1i>e of a ouble)ord ArrayCal!ulating the 1i>e of a ouble)ord Array
+ !urrent lo!ation !ounter: + subtra!t address of list
+ differen!e is the number of bytes
+ di'ide by 4 the si>e of a double)ord"
/ist "=&%" 23
ListSiCe , (M - /ist)
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
46/51
Irvine, Kip R. Assembly eb site E/amples !#
EM ire!ti'eEM ire!ti'e
+ efine a symbol as either an integer or te/t e/pression&+ Cannot be redefined
$I EK! O3.4H
press9e0 EK! OF$ress an0 Ge0 to continue...F*H
.data
prompt 1?TE press9e0
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
47/51
Irvine, Kip R. Assembly eb site E/amples !$
JEJEM ire!ti'eJEJEM ire!ti'e
+ efine a symbol as either an integer or te/t e/pression&
+ Called a te/t ma!ro+ Can be redefined
continue7sg TE+TEK! OF"o 0ou ish to continue (?N)BFH
roSiCe ,
.data
prompt 1?TE continue7sg
count TE+TEK! P(roSiCe Q 2) ; e#a/uates the e'pression
mo#e TE+TEK! Omo#H
setupAL TE+TEK! Omo#e a/countH
.code
setupAL ; generates< Fmo# a/*F
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
48/51
Irvine, Kip R. Assembly eb site E/amples !%
.eal-Address ode #rogramming.eal-Address ode #rogramming 8 of $"8 of $"
+ ?enerate 87-bit 1-01 #rograms+ Ad'antages
+ enables !alling of 1-01 and BI01 fun!tions
+ no memory a!!ess restri!tions
+ isad'antages+ must be a)are of both segments and offsets
+ !annot !all in3$ fun!tions indo)s S on)ard"
+ limited to 74% program memory
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
49/51
Irvine, Kip R. Assembly eb site E/amples !&
.eal-Address ode #rogramming.eal-Address ode #rogramming $ of $"$ of $"
+ .e;uirements
+ IDCLE Ir'ine87&in!
+ Initiali>e 1 to the data segment:
mo# a'Rdata
mo# dsa'
Add d 1 b 87 Bi H i
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
50/51
Irvine, Kip R. Assembly eb site E/amples "0
Add and 1ubtra!t, 87-Bit HersionAdd and 1ubtra!t, 87-Bit Hersion
TITLE Add and Subtract >ersion 2 (AddSub2.asm)
INL!"E Ir#ine4.inc.data#a/ "=&%" ****h#a/2 "=&%" ****h#a/3 "=&%" 2****h8ina/>a/ "=&%" B.code
main $%&mo# a'Rdata ; initia/iCe "Smo# dsa'mo# ea'#a/ ; get 8irst #a/ueadd ea'#a/2 ; add second #a/uesub ea'#a/3 ; subtract third #a/ue
mo# 8ina/>a/ea' ; store the resu/tca// "ump%egs ; disp/a0 registerse'it
main EN"$EN" main
http://www.nuvisionmiami.com/books/asmhttp://../Masm615/Exampleshttp://../Masm615/Exampleshttp://www.nuvisionmiami.com/books/asm -
7/25/2019 chapt_03 (1)
51/51
46 69 6E 69 7346 69 6E 69 73