1/2002jnm1 basic elements of assembly language integer constants –if no radix is given, the...
TRANSCRIPT
![Page 1: 1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h Int 21 –A hexadecimal](https://reader035.vdocuments.us/reader035/viewer/2022071718/56649e6f5503460f94b6c705/html5/thumbnails/1.jpg)
1/2002 JNM 1
Basic Elements of Assembly Language
• Integer Constants
– If no radix is given, the integer is assumed to be decimal.• Int 21h Int 21
– A hexadecimal constant beginning with a letter must have a leading 0 • Mov ax, 0A3C9h
![Page 2: 1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h Int 21 –A hexadecimal](https://reader035.vdocuments.us/reader035/viewer/2022071718/56649e6f5503460f94b6c705/html5/thumbnails/2.jpg)
1/2002 JNM 2
Basic Elements of Assembly Language
• Character and String Constants
– A single or a string of characters
– Enclosed in either single or double quotes
– Embedded quotes are permitted
‘An “embedded quote” within quotation marks’
![Page 3: 1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h Int 21 –A hexadecimal](https://reader035.vdocuments.us/reader035/viewer/2022071718/56649e6f5503460f94b6c705/html5/thumbnails/3.jpg)
1/2002 JNM 3
Basic Elements of Assembly Language
• Reserved Words
– Instruction Mnemonics– Directives– Attributes (BYTE or WORD)– Operators– Predefined Symbols
• A complete list of MASM reserved words are in Appendix D (4th Edition)
![Page 4: 1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h Int 21 –A hexadecimal](https://reader035.vdocuments.us/reader035/viewer/2022071718/56649e6f5503460f94b6c705/html5/thumbnails/4.jpg)
1/2002 JNM 4
Names (Identifiers)
• Used to identify variables, constants, procedures, or code labels.– Max 247 characters – Not case-sensitive – First character can be a letter, ‘_’, ‘$’, ‘@’– Subsequent characters may also be digits.– Cannot use an assembler reserved word.
• Should make identifier names descriptive and easy to understand
• Avoid @ as first character.
![Page 5: 1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h Int 21 –A hexadecimal](https://reader035.vdocuments.us/reader035/viewer/2022071718/56649e6f5503460f94b6c705/html5/thumbnails/5.jpg)
1/2002 JNM 5
Examples• Mystring db “this is a string”,0
– Mystring is the name
• Length = $ - mystring – Length is a reserved word (can not use)
• Loop1:– Loop1 is the label for a loop instruction
• Note difference between data names and code labels – in the data section (no colon after the name)
– In the code section (colon after the name)
![Page 6: 1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h Int 21 –A hexadecimal](https://reader035.vdocuments.us/reader035/viewer/2022071718/56649e6f5503460f94b6c705/html5/thumbnails/6.jpg)
1/2002 JNM 6
Assembly Language Statements
Generally fall into two classes:
Instructions - Executable Statements
Directives – statements that provide information to the assembler about how to generate executable code
![Page 7: 1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h Int 21 –A hexadecimal](https://reader035.vdocuments.us/reader035/viewer/2022071718/56649e6f5503460f94b6c705/html5/thumbnails/7.jpg)
1/2002 JNM 7
General Format of a Statement[name] [mnemonic] [operands] [;comment]
• For statements, all of the fields are optional
• Statements are free-form – they can be written in any column with any number of spaces between each operand
• Blank lines are permitted
• Must be written on a single line and not pass column 128 (use / for continuation of line)
![Page 8: 1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h Int 21 –A hexadecimal](https://reader035.vdocuments.us/reader035/viewer/2022071718/56649e6f5503460f94b6c705/html5/thumbnails/8.jpg)
1/2002 JNM 8
Directives• A statement that is recognized and acted upon by
the assembler as the program’s source code is being assembled.
• Used for defining logical segments, choosing a memory module, defining variables, creating procedures, …
• .data (directive to identify the area of a program that contains the data variables)
• Count db 50 (db is a directive that tells the assembler to create storage for a byte named count and initialize it to 50.
![Page 9: 1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h Int 21 –A hexadecimal](https://reader035.vdocuments.us/reader035/viewer/2022071718/56649e6f5503460f94b6c705/html5/thumbnails/9.jpg)
1/2002 JNM 9
Standard Assembler Directives
Directive Description
title Title of the listing file
.model Specify the program's memory model
.stack Set the size of the stack segment
.data Mark the beginning of the data segment
.code Mark the beginning of the code segment
proc Begin procedure
endp End of procedure
end End of program assembly
![Page 10: 1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h Int 21 –A hexadecimal](https://reader035.vdocuments.us/reader035/viewer/2022071718/56649e6f5503460f94b6c705/html5/thumbnails/10.jpg)
1/2002 JNM 10
Data Allocation DirectivesDirective Description Bytes
DB Define byte 1DW Define word 2DD Define Doubleword 4
DF,DP Define far pointer 6DQ Define quadword 8DT Define tenbytes 10
Char1 db ‘A’ hex db 41hSigned1 db -128 dec db 65Signed2 db +127 bin db 01000001bUnsigned db 255 hex2 db 0A3h
![Page 11: 1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h Int 21 –A hexadecimal](https://reader035.vdocuments.us/reader035/viewer/2022071718/56649e6f5503460f94b6c705/html5/thumbnails/11.jpg)
1/2002 JNM 11
More MASM Directives
• There are hundreds of directives.
• Will only use a small number of directives
• Appendix D.7 (4th Edition) is a complete listing of directives and operators
![Page 12: 1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h Int 21 –A hexadecimal](https://reader035.vdocuments.us/reader035/viewer/2022071718/56649e6f5503460f94b6c705/html5/thumbnails/12.jpg)
1/2002 JNM 12
Instructions
• A statement that is executed by the processor at runtime
• Fall into five general categories– Data transfer (mov ax, 5)– Arithmetic (add ax, 20)– Transfer of control (call MySub)– Logical (Jz next1)– Input/output (In al, 20)
![Page 13: 1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h Int 21 –A hexadecimal](https://reader035.vdocuments.us/reader035/viewer/2022071718/56649e6f5503460f94b6c705/html5/thumbnails/13.jpg)
1/2002 JNM 13
General Format of an Instruction
• Label (optional)• Instruction mnemonic (required)• Operand(s) (usually required)• Comment (optional)
• A source code line may have only a label or comment.
Label: Mnemonic ;CommentOperand(s)
![Page 14: 1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h Int 21 –A hexadecimal](https://reader035.vdocuments.us/reader035/viewer/2022071718/56649e6f5503460f94b6c705/html5/thumbnails/14.jpg)
1/2002 JNM 14
Labels
• An identifier that acts as a place marker for either instructions or data
Target:Mov ax, bx
…
Jmp target
![Page 15: 1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h Int 21 –A hexadecimal](https://reader035.vdocuments.us/reader035/viewer/2022071718/56649e6f5503460f94b6c705/html5/thumbnails/15.jpg)
1/2002 JNM 15
Instruction Mnemonics
• A short word that identifies the operation carried out by an instructionMov assign one value to another
Add add two values
Sub subtract one value from another
Call call a procedure
![Page 16: 1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h Int 21 –A hexadecimal](https://reader035.vdocuments.us/reader035/viewer/2022071718/56649e6f5503460f94b6c705/html5/thumbnails/16.jpg)
1/2002 JNM 16
Formatting of Instructions and Number of Operands Needed
Mnemonic destination operand, source operand
HLT ; zero operandsINC AX ; one operandMOV AX, 100 ; two operandsSHLD DX, AX, 4 ; three operands
Different instructions use different numbers of operands as shown above.
![Page 17: 1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h Int 21 –A hexadecimal](https://reader035.vdocuments.us/reader035/viewer/2022071718/56649e6f5503460f94b6c705/html5/thumbnails/17.jpg)
1/2002 JNM 17
Operands
• A memory operand is specified by either the name of a variable or a register that holds the address of a variable.
• A variable name implies the address of the variable;
96 constant operand
2 + 4 constant expression operand
Eax register operand
Count variable operand
![Page 18: 1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h Int 21 –A hexadecimal](https://reader035.vdocuments.us/reader035/viewer/2022071718/56649e6f5503460f94b6c705/html5/thumbnails/18.jpg)
1/2002 JNM 18
Comments• Single line comments begin with a semicolon
; Words after the semicolon are comments. ; Comments may begin anywhere on a line
• You will need to have comments at least every two lines of code for this class
• Block comments begin with the comment directive a user-specified symbol
COMMENT &This line is a comment.So is this line. The ampersand symbol is personal choice.
&