Download presentation
Presentation is loading. Please wait.
Published byIrwan Kusnadi Modified over 6 years ago
1
Defining Types of data expression Dn [name] expression Dn [name] Name: a program that references a data item does so by means of name Dn (Directive): define the data item – see next slide— Expression: is an operand may specify an uninitialized value or constant value an uninitialized value defined by item ? EXAMPLE : DATAX DB ?
2
Defining Types of data (Directive):
Pseudo-op Stands for DB Define Byte DW Define Word DD Define Doubleword DQ Define Quadword DT Define Tenbytes
3
Defining Types of data -Examples
a memory byte is associated with the name ALPHA, and initialized to 4 ALPHA DB 4 A memory byte is associated with the name BYT, and uninitialized. BYT DB ? a memory word is associated with the name WRD, and initialized to -2. WRD DW -2
4
High and Low Bytes of a Word
WORD1 DW 1234H high byte WORD1+1 low byte WORD1
5
Defining Types of data The decimal range (fit a byte):
Unsigned representation: 0 to 255 Signed representation: -128 to 127 The decimal range (fit a word): Unsigned representation: 0 to 65535 Signed representation: to 32767
6
Defining Types of data – Array byte
an array is a sequence of memory bytes or words. Example: B_ARRAY DB 10H,20H,30H Symbol Address Contents B_ARRAY H 10H B_ARRAY H 20H B_ARRAY H 30H
7
Defining Types of data – Array word
Example: W_ARRAY DW ,40,29887,329 Symbol Address Contents W_ARRAY H 1000D W_ARRAY H 40D W_ARRAY H D W_ARRAY H D
8
Defining Types of data :The DUP Operator
It is possible to define arrays whose elements share a common initial value by using the DUP (duplicate) operator. Syntax: Example: Repeat-count(exp) Dn [name] creates an array of 212 uninitialized bytes. DELTA DB 212 DUP (?) set up an array of 100 words, with each entry initialized to 0. GAMMA DW 100 DUP (0)
9
Character String ASCII codes can be initialized with a string of characters using single quotes like ‘PC’ or double quotes like “PC”. Example: LETTERS DB 'ABC' = LETTERS DB 41H,42H,43H Inside a string, the assembler differentiates between upper and lowercase. It is possible to combine characters and numbers in one definition: Example: MSG DB 'HELLO',0AH,0DH, '$'
11
Exercises: Q1. Which of the following names are legal ? a. ?1 b. T =
c. LET’S_GO Q2. If it is legal, give data definition pseudo-op to define each of the following. A word variable A initialized to 52. A byte variable C initialized to 300. A word variable WORD1,unintialized. A byte variable B initialized to -129.
12
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’ Real : end with ‘R’ and the assembler converts a given a decimal or hex constant to floating point number Any number may have an optional sign.
13
Numeric Constant Number Type 11011 1101B 64223 decimal -21843D 1B4DH
FFFFH 0FFFFH decimal binary decimal decimal hex illegal illegal hex
14
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.
15
Registers Information inside the microprocessor is stored in registers. The registers are classified according to the functions they perform In general there are fourteen 16-bit registers: Data registers: There are four general data registers. They hold data for an operation. Address registers: They are divided into segment, pointer, and index registers. They hold the address of an instruction or data. Status register: It is called the FLAGS register. It keeps the current status of the processor.
16
Pointer and Index Registers
Data Registers AX AH AL BH BL BX CX CH CL DX DH DL Segment Registers CS DS SS ES Pointer and Index Registers SI DI SP BP IP FLAGS Register
17
Data Registers: AX, BX, CX, DX
These four registers, in addition to being general-purpose registers, also perform special functions. The high and low bytes of these registers can be accessed separately. Ex. The high byte of AX is called AH, and the low byte is called AL. This arrangement gives us more registers to use when dealing with byte-size data.
18
Data Registers: AX, BX, CX, DX
AX (Accumulator Register) is the preferred register to use in arithmetic, logic, and data transfer instructions BX (Base Register) also serves as an address register. CX (Count Register) Program loop constructions are facilitated by the use of CX, which serves as a loop counter. DX (Data Register) is used in multiplication and division.
19
Address Registers - Segment Registers CS, DS, SS, ES
To keep track of the various program segments, the 8086 is equipped with four segments registers to hold segment numbers: CS (Code Segment): contains the code segment number. DS (Data segment): contains the data segment number. SS (Stack Segment): contains the stack segment number. ES (Extra Segment): is used if a program needs to access a second data segment.
20
MOV Instruction The MOV (move) instruction is used to:
Transfer data between Registers. Transfer data between registers and memory locations. Move a number directly into a register or memory location. Syntax: MOV destination, source Example: MOV AX, WORD1 MOV AX, BX MOV AX, 'A' Note: any register can be used except CS & IP Before After AX AX WORD WORD1
21
Legal Combinations of operands for MOV
Destination Operand General Segment Memory Source operand register register location Constant General register yes yes yes no Segment register yes no yes no Memory location yes yes no no Constant yes no yes no Illegal: MOV WORD1, WORD2 • Legal: MOV AX, WORD2 MOV WORD1, AX Illegal: MOV DS, CS • Legal: MOV AX, CS MOV DS, AX
22
Type Agreement of Operands
The operands of any two-operand instruction must be of the same type (i.e. Both bytes or words). Illegal: MOV AX, BYTE1 However, the assembler will accept both of the following: MOV AH, 'A' moves 41H into AH MOV AX, 'A' moves 0041H into AX
23
LEA Instruction LEA (Load Effective Address) puts a copy of the source offset address into the destination. Syntax: LEA destination, source Where destination is a general register and source is a memory location Example: MSG DB 41H, 42H, 43H LEA DX, MSG puts the offset address of the variable MSG into DX. Data Definition + Basic Instructions 17
24
ADD and SUB Instructions
The ADD (add) and SUB (subtract) instructions are used to: Add/subtract the contents of: Two registers. A register and a memory location. Add/subtract a number to/from a register or memory location. Syntax: ADD destination, source SUB destination, source Examples: ADD WORD1, AX SUB AX, DX Before After 01BC BC AX AX DF WORD WORD1 Before After FFFF AX AX DX DX
25
Legal Combinations of operands for ADD & SUB
Destination Operand General Memory Source Operand register location General register yes yes Memory location yes no Constant yes yes Illegal: ADD BYTE1, BYTE2 Legal: MOV AL, BYTE2 ADD BYTE1, AL
26
INT Instruction To invoke a DOS or BIOS routine, the INT (interrupt) instruction is used. Format: INT interrupt_number where interrupt_number is a number that specifies a routine.
27
INT 21h INT 21h may be used to invoke a large number of DOS functions.
A particular function is requested by placing a function number in the AH register and invoking INT 21h. Some of the functions are: INT21h functions expect input values to be in certain registers and return output values in other registers. Function number Routine 1 single-key input 2 single-character output 9 character string output
28
INT 21h Function 1: Single-Key Input Input: AH = 1
Output: AL = ASCII code if character key is pressed = 0 if non-character key is pressed To invoke the routine, the following instructions should be executed: MOV AH,1 ; input key function INT 21H ; ASCII code in AL
29
INT 21h Function 2: Display a character or execute a control function
Input: AH = 2 DL = ASCII code of the character Output AL = ASCII code of the character To invoke the routine, the following instructions should be executed: MOV AH, 2 ; display character function MOV DL, '?' ; character is '?' (or any other character) INT 21H ; display character
30
INT 21h Function 2 may be used to perform control functions.
If DL contains the ASCII code of a control character, INT 21h causes the control function to be performed. The principal control characters are : ASCII code (Hex) Symbol Function 07H BEL beep (sounds a tone) 08H BS backspace 09H HT tab 0AH LF line feed (new line) 0DH CR carriage return (start of current line)
31
INT 21h Function 9: Display a string Input: AH = 9
DX = offset address of string. The string must end with a '$' character To invoke the routine, the following instructions should be executed: MOV MOV DS, AX MOV AH, 9 ; display string function LEA DX, MSG ; get message (Load Effective Address) INT 21H ; display string A program containing a data segment should begins with these two instructions
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.