You are on page 1of 15

Byte variables

• Syntax:
Name DB initial value

Examples:

ALPHA DB 4
BYTDB ?

12/12/2020 1
Word variables
• Syntax:
Name DW initial value
Example:
WRD DW -2
• The assembler stores integers with the least significant byte in
the lowest address of the memory area allocated to the integer
Example:
WD DW 1234H
low byte WD contains 34h, high byte contains 12h

12/12/2020 2
Character strings
• An array of characters can be initialized by a string of characters.

• Inside a string, the assembler differentiates between upper and lower cases
(different ASCII codes).

• It is possible to combine characters and numbers in one definition

12/12/2020 3
Character strings
Examples:
1)
LETTERS DB ‘AaBCbc‘
Is equivalent to
LETTERS DB 41H,61H,42H,43H,62H,63H
2)
MSG DB ‘ABC‘,0AH,0DH,‘$‘
Is equivalent to
MSG DB 41H,42H,43H,0AH,0DH,24H

12/12/2020 4
BASIC INSTRUCTIONS
MOV and XCHG

12/12/2020 5
MOV instruction
• Is used to transfer data :
• between registers,
• between a register & a memory location.
Or
• To move a number directly into a register or memory location.

12/12/2020 6
Syntax
MOV destination , source
Example:
MOV AX , WORD1
This reads “ Move WORD1 to AX “
The contents of register AX are replaced by the contents of the
memory location WORD1.

12/12/2020 7
Mov AX , WORD1

Before After

0006 0008

AX AX

0008 0008

WORD1 WORD1

12/12/2020 8
MOV AX , BX

• AX gets what was previously in BX , BX is unchanged.

12/12/2020 9
MOV AH , ‘A’

• This is a move of the 041h ( the ASCII code of “A” ) into register AH.

• The previous value of AH is overwritten


( replaced by new value )

12/12/2020 10
XCHG instruction
• (Exchange) operation is used to exchange

the contents of

• two registers, or
• a register and a memory location

12/12/2020 11
Syntax

XCHG destination , source

12/12/2020 12
Example

XCHG AH , BL

This instruction swaps the contents of AH and BL.

12/12/2020 13
XCHG AH , BL

Before After

1A 00 05 00

AH AL AH AL

00 05 00 1A

BH BL BH BL

12/12/2020 14
Example

XCHG AX , WORD1

• This swaps the contents of AX and memory location WORD1.

12/12/2020 15

You might also like