Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 4 –Requirements for coding in Assembly Language

Similar presentations


Presentation on theme: "Chapter 4 –Requirements for coding in Assembly Language"— Presentation transcript:

1 Chapter 4 –Requirements for coding in Assembly Language
Lecture 2 Chapter 4 –Requirements for coding in Assembly Language

2 Chapter Outline Numeric Constant . Named Constants .
Program Structure .

3 Numeric Constant In an assembly language program we may express data as: Binary: bit string followed by ‘B’ or ‘b’ Decimal: string of decimal digits followed by an optional ‘D’ or ‘d’ Hex: begins with a decimal digit and ends with ‘H’ or ‘h’ Octal : end with ‘O’ or ‘o’ Any number may have an optional sign.

4 Numeric Constant Number Type 11011 1101B 64223 decimal -21843D 1B4DH
FFFFH 0FFFFH decimal binary decimal decimal hex illegal illegal hex

5 Named Constants - EQU (Equates)
To assign a name to a constant, we can use the EQU pseudo-op. Syntax: name EQU constant Examples: LF EQU 0AH MOV DL,0AH = MOV DL,LF PROMPT EQU 'Any Thing' MSG DB 'Any Thing' = MSG DB PROMPT Note: no memory is allocated for EQU names.

6 Directives SEGMENT Directive Data Segment Stack segment Code Segment
END Directive ex: ENDP directive ends a procedure ex: END directive ends the entire program and appears as the last statement 9

7 Program Structure - Memory Models
The size of code and data a program can have is determined by specifying a memory model using the .MODEL directive. Syntax: .MODEL memory_model Model Description SMALL code in 1 segment data in 1 segment MEDIUM code > 1 segment data in 1 segment COMPACT code in 1 segment data > 1 segment LARGE code > 1 segment data > 1 segment no array larger than 64k bytes HUGE code > 1 segment data > 1 segment arrays may be larger than 64k bytes

8 Program Structure - Memory Models
The appropriate model is SMALL, unless there is a lot of code or data. .MODEL directive should come before segment definitions. A segment is 216 (64 k)

9 Program Structure - Stack Segment
The purpose of the stack segment declaration is to set aside a block of memory (the stack area) to store the stack. The stack area should be big enough to contain the stack at its maximum size. Syntax: .STACK size ; where size is an optional number that specifies ; the stack area size in bytes. Example: .STACK 100H ; sets aside 100H bytes for the stack area. ; (reasonable size for most applications). If size is omitted, 1KB is set aside for the stack area.

10 Program Structure - Data Segment
A program’s data segment contains all the variable definitions. Constant definitions are often made here as well. (they may be placed elsewhere in the program since no memory allocation is involved). To declare a data segment, we use the directive .DATA, followed by variable and constant declarations. Example: .DATA WORD1 DW 2 MSG DB ‘this is a message’

11 Program Structure - Code Segment
The code segment contains a program’s instructions. Syntax: .CODE name ; where name is an optional name of segment. There is no need for a name in a SMALL program. Inside a code segment, instructions are organized as procedures.

12 Program Structure - Code Segment
The simplest procedure definition is: name PROC ; name: is the name of the procedure. ; body of the procedure ; PROC & ENDP: are pseudo-ops that name ENDP ; delineate the procedure Example of a code segment definition: .CODE MAIN PROC ; main procedure instructions MAIN ENDP ; other procedures go here

13 A General Form of a .SMALL model program
Program Structure - A General Form of a .SMALL model program .MODEL SMALL .STACK 100H .DATA ; data definitions go here .CODE MAIN PROC ; instructions go here MAIN ENDP ; other procedures go here END MAIN


Download ppt "Chapter 4 –Requirements for coding in Assembly Language"

Similar presentations


Ads by Google