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

Lecture 2 Chapter 4 Requirements for coding in Assembly Language 1

Embed Size (px)

DESCRIPTION

Defining Types of data 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 ? 3 expression Dn[name]

Citation preview

Page 1: Lecture 2 Chapter 4 Requirements for coding in Assembly Language 1

Lecture 2Chapter 4 –Requirements for coding in Assembly

Language

1

Page 2: Lecture 2 Chapter 4 Requirements for coding in Assembly Language 1

Chapter Outline

Assembly Language Features

Simplified segment Directive

Defining Types of data

Equate Directive

2

Page 3: Lecture 2 Chapter 4 Requirements for coding in Assembly Language 1

Defining Types of data

[name] Dn expression

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 valuean uninitialized value defined by item ? EXAMPLE : DATAX DB ?

3

[name] Dn expression

Page 4: Lecture 2 Chapter 4 Requirements for coding in Assembly Language 1

Defining Types of data (Directive):

Pseudo-op Stands forDB Define ByteDW Define WordDD Define DoublewordDQ Define QuadwordDT Define Tenbytes

4

Page 5: Lecture 2 Chapter 4 Requirements for coding in Assembly Language 1

Defining Types of data -Examples• Syntax: name DB initial_value

• Example: ALPHA DB 4 a memory byte is associated with the name ALPHA, and initialized to 4. BYT DB ? a memory byte is associated with the name BYT, and uninitialized. WRD DW -2 a memory word is associated with the name WRD, and initialized to -2.• The decimal range is:

• Unsigned representation: 0 to 255• Signed representation: -128 to 127

5

Page 6: Lecture 2 Chapter 4 Requirements for coding in Assembly Language 1

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 ContentsB_ARRAY 200H 10HB_ARRAY+1 201H 20HB_ARRAY+2 202H 30H

6

Page 7: Lecture 2 Chapter 4 Requirements for coding in Assembly Language 1

Defining Types of data – Array word

• Example: W_ARRAY DW 1000,40,29887,329

Symbol Address ContentsW_ARRAY 0300H 1000DW_ARRAY+2 0302H 40DW_ARRAY+4 0304H 29887DW_ARRAY+6 0306H 329D

7

Page 8: Lecture 2 Chapter 4 Requirements for coding in Assembly Language 1

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: DELTA DB 212 DUP (?) creates an array of 212 uninitialized bytes.

GAMMA DW 100 DUP (0) set up an array of 100 words, with each entry initialized to 0.

8

[name] Dn Repeat-count(exp)

Page 9: Lecture 2 Chapter 4 Requirements for coding in Assembly Language 1

High and Low Bytes of a Word• WORD1 DW 1234H

low byteWORD1

high byteWORD1+1

9

Page 10: Lecture 2 Chapter 4 Requirements for coding in Assembly Language 1

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 lower case.

• It is possible to combine characters and numbers in one definition: Example: MSG DB 'HELLO',0AH,0DH, '$'

10

Page 11: Lecture 2 Chapter 4 Requirements for coding in Assembly Language 1

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.

11

Page 12: Lecture 2 Chapter 4 Requirements for coding in Assembly Language 1

Numeric Constant

Number Type

110111101B64223-21843D1,2341B4DH1B4DFFFFH0FFFFH

decimalbinarydecimaldecimalillegalhexillegalillegalhex

12

Page 13: Lecture 2 Chapter 4 Requirements for coding in Assembly Language 1

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. 13