Presentation is loading. Please wait.

Presentation is loading. Please wait.

6.1) Assembly Language Program Format 6.2) Features of Assembly Language 6.3) Data Definition CHAPTER 6 ASSEMBLY LANGUAGE PROGRAM FORMAT AND DATA DEFINITION.

Similar presentations


Presentation on theme: "6.1) Assembly Language Program Format 6.2) Features of Assembly Language 6.3) Data Definition CHAPTER 6 ASSEMBLY LANGUAGE PROGRAM FORMAT AND DATA DEFINITION."— Presentation transcript:

1 6.1) Assembly Language Program Format 6.2) Features of Assembly Language 6.3) Data Definition CHAPTER 6 ASSEMBLY LANGUAGE PROGRAM FORMAT AND DATA DEFINITION

2 Format for Assembly Language Program There are 2 types of executable programs: 1..COM program 2..EXE program.COM program –consist of one segment that contains code, data and the Stack –is useful as a small utility program or as a resident program (one that is installed in memory and is available while other programs run).EXE program –consist of separate code, data and stack segments. –is used for more serious programs. Assembly language can be written by using either.COM or.EXE format.

3 Observe that each segment (data, code and stack) of the.EXE program is defined separately whereas in.COM, no separate segment for data and stack. PSP (program segment prefix) stack data segment code segment PSP code segment.EXE.COM ES SS DS CS ES DS CS

4

5 The statement ASSUME in.COM states that the CS, DS, SS and ES registers will have the same starting address for code segment.

6 PAGE directive to establish 60 lines and 132 columns per page TITLE directive to identify the program’s name as A04ASM1 ; symbol is for comment STACK to define the stack segment DATASEG to define the data segment CODESEG to define the code segment

7 ASSUME directive is used to tell the assembler the starting address of segments with the segment registers Initialize the address of data segment in DS Procedure MAINEND directive to tell the assembler that this is the end of the source program Request to end the program and return to the OS

8 Ending Program Execution After executing an assembly language program, the programmer must tell the system to terminate the executing program with the help of DOS interrupt services. INT 21H is the commonly used interrupt service. It used the function code in the AH register to determine the next course of action. INT 21H can also be used to control input from the keyboard, control the screen, disk I/O and output to the printer. INT 21H with function code 4CH is used to terminate program execution. The function code 4CH must be priory entered into AH. Example:

9 Examples of.EXE program Example  addition operation of 2 numbers, 215 and 125. Values 215 and 125 are defined in the data segment using names (FLDD and FLDE) with the size of each is one word (DW = Define Word = 16 bit or 2 bytes). The result is kept in FLDF, which its size is also one word. The AX register is used to hold operand 1 and also the result. Then the result is put into FLDF

10 Examples of.COM program value 215 and 125 is defined in the data segment using names (FLDD and FLDE) with the size of each is one word (DW = Define Word = 16 bit or 2 bytes) The result is kept in FLDF, which its size is also one word. The AX register is used to hold operand 1 and also the result. Then the result is put into FLDF

11 Features of Assembly Language A few features of the Assembly Language that will be discussed here are: 1)Program Comments 2)Reserved Words 3)Identifiers 4)Statements 5)Directives

12 1. Program Comments Comments start with a semicolon ‘;’. All characters written on the right side of the semicolon is considered as a comment (will not be executed). Below are some examples of comments: –In a row of its own ; Comment Example –In the same line with other commands ADD AX, BX; Adds the value of BX and AX registers Note: Comments will not be changed into machine code, hence the length of a comment will not influence the size of the program in machine code

13 2. Reserved Words Certain names in assembly language are reserved for their own purposes, to be used only under special conditions. Reserved words, by category include: –Instructions: such as MOV and ADD which are operations that the computer can execute; –Directives: such as END and SEGMENT which you use to provide information to the assembler; –Operators: such as FAR, SIZE which you use in expressions –Predefined Symbols: such as @Data, @Model which return information to your program during assembly

14 3. Identifiers

15 3. Identifiers (cont.)

16 4. Statements An assembly program has a set of statements: –Instructions such as MOV and ADD that will be translated into machine code or object code. –Directives that tells assembler to perform certain actions like define a data item etc

17 5. Directives Directives are statements that enable the programmer to determine how the source program is arranged. It will not be changed into machine code. The following are a few directives:

18 SEGMENT defines the starting of a segment. Segment name must be stated uniquely and must adhere to the rules of naming. ENDS shows the end of the segment and has the same name like SEGMENT. The maximum size of a segment is 64K. Operands for SEGMENT may contain:

19 Align: option that shows the boundary on which the segment is to begin. The typical requirement is PARA, which causes the segment to align on a paragraph boundary so that the starting address is evenly divisible by 16 or 10H. The omission of the align operand causes the assembler to default to PARA. Combine: option that indicates whether to combine the segment with other segments when they are linked after assembly. The types of combine are STACK, COMMON, PUBLIC and AT. For instance, Stack segment is usually defined as: Segment nameSEGMENTPARASTACK Class: option that is used to group related segments when linking. This book uses the classes ‘code’ for code segment, ‘data’ for data segment and ‘stack’ for stack segment. 5. Directives (cont.)

20 iii) PROC Directive The code segment contains executable code for a program, which consists of one or more procedures, defined initially with the PROC directive with the ENDP directive. Here is the format : Procedure name (procedure-name) must be present, must be unique and must follow assembly language naming conventions

21 iv) END Directive There are 3 END directives:  END: terminates the program (last statement in assembly language)  ENDS: ends a segment  ENDP: ends a procedure v) ASSUME Directive.EXE program uses SS register to address the stack segment, DS register for data segment and CS register for code segment. The ASSUME directive is used to tell the assembler the relation of the three registers with the segment: ASSUMESS:stackname, DS:datasegname, CS:codesegname, … SS:stackname means the SS register is associated with the name for the stack segment. Same applies to DS and CS regarding data segment and code segment.

22 Data Definition Assembler offers a few directives that enable programmers to define data according to its type and length. Format for data definition: [name] Data names are optional because in assembly language programming, data is not necessarily reference by its name. Dn Directive Next slide are the common directives to define data and also directives used in MASM 6.0

23 * Students are advise to obtain themselves

24 The following are some examples of numeric and character data definition Page 60,132 TITLEA04DEFIN (EXE)Define data directives.MODELSMALL.DATA ;DB – Define Bytes: ;----------------------- BYTE1DB?; Uninitialized BYTE2DB48; Decimal constant BYTE3DB30H; Hex constant BYTE4DB01111010B; Binary constant BYTE5DB10 DUP (0); Ten zeros BYTE6DB‘PC FAIR’; Character string BYTE7DB‘12345’; Number as characters BYTE8DB01, ‘Jan’, 02, ‘Feb’; Table of months

25 ;DW – Define Words: ;------------------------- WORD1DW0FFF0H; Hex constant WORD2DW01111010B; Binary constant WORD3DWBYTE8; Address constant WORD4DW2, 4, 6, 7, 9; Table of 5 constants WORD5DW6 DUP (0); Six zeros ;DQ – Define Doublewords: ;--------------------------------- DWORD1DD?; Uninitialized DWORD2DD41562; Decimal value DWORD3DD24, 48; Two constants DWORD4DD BYTE3 – BYTE2; Difference between addresses END

26 DB or BYTE -to define item with the size of one byte. The range of its value is stated in the table before. DW or WORD -to define item with the size of one word or 2 bytes. The range of its value is stated in the table before. Assembler will change numeric constants into binary object code (presented in hexadecimal) and kept in the memory in reverse bytes. For instance, if the real value is 3039H it will be kept as 3930H in the data segment DD or DWORD - to define item with the size of 4 bytes. Its range of values is stated in the table above. As usual data is kept in reverse byte or reverse sequence. For example, if data is 00BC614EH it will be kept as 4E61BC00H.

27 Expressions Expressions in operand may specify an uninitialized value or a constant value. Example: DATAX DB?; Uninitialized item, size of 1 bait DATAYDB25; Initialized item, DATAY with value 25 Uninitialized item is used to store a value which size is defined. The value of a data can be used and edited to suit the program’s needs. Expressions can contain a few constants that is separated by the sign ‘,’ and the quantity is limited to the row length. Example: DATAZDB21, 22, 23, 24, 25, 26, … The assembler defines the above constant byte by byte, from left to right. DATAZ or DATAZ+0 contains the value 21, DATAZ+1 contains 22, DATAZ+2 contains 23 and so forth. Example of instruction MOV AL, DATAZ+3 will enter the value 24 into the CL register

28 Expressions also allows duplication of constants using the format below: Example: DW10DUP(?); Ten words, uninitialized DB5DUP(12); Five bytes containing 0C0C0C0C0C DB3DUP(5 DUP(4)); Fifteen 4s

29 Character Strings Character strings are defined either using single quotes like ‘name’ or double quotes, “name”. The content in quotes will be kept as object code in ASCII format Example: DB“Crazy Sam’s CD Emporium”; double quotes for string, ; single quotes for apostrophe. DB‘Crazy Sam’’s CD Emporium’; single quotes for string, ; two single quotes for apostrophe.

30 Numeric Constants Numeric constant is used to define the numeric value and the memory address. Below are a few numeric format: Binary: use binary digit 0 and 1 followed with radix specifier B. Example: 01001100B. Decimal: use decimal digits of 0 to 9, followed by radix specifier D or none. Example 125D or 125. Hexadecimal: use hexadecimal digits of 0 to 9 and A till F, followed by radix specifier H. Real: it is decimal or hexadecimal constant followed by the radix specifier R. Assembler will change the value into floating point format.


Download ppt "6.1) Assembly Language Program Format 6.2) Features of Assembly Language 6.3) Data Definition CHAPTER 6 ASSEMBLY LANGUAGE PROGRAM FORMAT AND DATA DEFINITION."

Similar presentations


Ads by Google