14
Assembly Language – Lab 2 Registers, Instructions, ASCII Table 1

Assembly Language – Lab 2

  • Upload
    max

  • View
    43

  • Download
    1

Embed Size (px)

DESCRIPTION

Assembly Language – Lab 2. Registers, Instructions, ASCII Table. Registers. Data Registers: Accumulator Register (AX), Base Register (BX), Count Register (CX), Data Register (DX). Address Registers: - PowerPoint PPT Presentation

Citation preview

Page 1: Assembly Language –  Lab 2

1

Assembly Language – Lab 2Registers, Instructions, ASCII Table

Page 2: Assembly Language –  Lab 2

2

Registers

• Data Registers: Accumulator Register (AX), Base Register (BX),

Count Register (CX), Data Register (DX).

Address Registers:

• Segment Registers: Code Segment (CS), Data Segment (DS),

Stack Segment (SS), Extra Segment (ES).

• Pointer and Index Registers: Stack Pointer (SP), Base Pointer (BP),

Source Index (SI), Destination Index (DI).

• Instruction Pointer (IP).

Page 3: Assembly Language –  Lab 2

3

MOV Instruction• Syntax: MOV destination, source

• Example: MOV DL,42 ; 42 in decimal is ‘*’

Note: any register can be used except CS & IP

Before After

DH DL DH DL 00 00 00 2A

Page 4: Assembly Language –  Lab 2

4

Legal Combinations of operands for MOV

Page 5: Assembly Language –  Lab 2

5

MOV Syntax – Legal form • list of possible combination of MOV operands:

MOV <REG>,<REG>MOV <REG>,<MEM>MOV <MEM>,<REG>MOV <REG>,<CONST>MOV <MEM>,<CONST>

• Example: MOV VAR1, AX MOV AX, BX

Page 6: Assembly Language –  Lab 2

6

MOVE-and-Fill Instruction (MOVSX-MOVZX)

MOVSX MOVZX

Move a byte or word source to a word or double-word destination.Use with signed arithmetic valuesExample:MOVSX CX,10110000B -CX= 11111111 10110000

Move a byte or word source to a word or double-word destination.Use with unsigned arithmetic valuesExample:MOVZX CX,10110000B-CX= 00000000 10110000

Page 7: Assembly Language –  Lab 2

7

XCHG Instruction• Used to exchange the contents of:

Two registers. A register and a memory location.

• Syntax: XCHG destination, source• Example: XCHG AH, BL

Before After

AH AL AH AL

BH BL BH BL

3E 00 02 00

00 02 00 3E

Page 8: Assembly Language –  Lab 2

8

Basic Arithmetic Instruction• ADD• SUB• INC• DEC

Page 9: Assembly Language –  Lab 2

9

ADD and SUB Instructions• Syntax: ADD destination, source SUB destination, source• Examples ADD WORD1, AX SUB AX, BX

Before After 01AC 01AC AX AX 0432 05DE

WORD1 WORD1

Before After 01BD 03C8 AX AX0585 0585

BX BX

Page 10: Assembly Language –  Lab 2

10

INC and DEC Instructions• Syntax: INC destination DEC destination

• Examples: INC VAR1 DEC VAR2

Before After

VAR1 VAR1 0007 0008

Before After

VAR2 VAR2 FFFF FFFE

Page 11: Assembly Language –  Lab 2

11

INT Instruction• Invoke a DOS or BIOS routine. When one wants to read from

the keyboard or disk or mouse, or write to the screen, an INT (interrupt) is used.

• Format: INT interrupt_number

Page 12: Assembly Language –  Lab 2

12

INT 21h• A particular function is requested by placing a function number

in the AH register and invoking INT 21h.• Some of the functions are:

Function number Routine1 single-key input2 single-character output9 character string output

Page 13: Assembly Language –  Lab 2

13

INT 21hFunction 1: Single-Key Input Function 2: Display a

character or execute a control function

Function 9: Display a string

MOV AH,1 INT 21H

MOV AH, 2 MOV DL, '?‘ INT 21H

MOV AX, @DATA MOV DS, AX MOV AH, 9 LEA DX, MSG INT 21H

Page 14: Assembly Language –  Lab 2

14