Top Banner
Assembly Language for Intel- Assembly Language for Intel- Based Computers Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, 2006-2007. All rights reserved. You may modify and copy this slide show for your personal use, or for use in the classroom, as long as this copyright statement, the author's name, and the title are not changed.
18

Assembly Language for Intel-Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, 2006-2007. All rights reserved. You may modify.

Jan 15, 2016

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Assembly Language for Intel-Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, 2006-2007. All rights reserved. You may modify.

Assembly Language for Intel-Based Assembly Language for Intel-Based ComputersComputers

Chapter 16: Expert MS-DOS Programming

(c) Pearson Education, 2006-2007. All rights reserved. You may modify and copy this slide show for your personal use, or for use in the classroom, as long as this copyright statement, the author's name, and the title are not changed.

Page 2: Assembly Language for Intel-Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, 2006-2007. All rights reserved. You may modify.

Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. 2Web site Examples

Expert MS-DOS ProgrammingExpert MS-DOS Programming

• Interrupt Handling • Terminate and stay Resident Programs

Page 3: Assembly Language for Intel-Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, 2006-2007. All rights reserved. You may modify.

Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. 3Web site Examples

Interrupt Handling Interrupt Handling

Page 4: Assembly Language for Intel-Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, 2006-2007. All rights reserved. You may modify.

Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. 4Web site Examples

Interrupt Vectoring ProcessInterrupt Vectoring Process

Page 5: Assembly Language for Intel-Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, 2006-2007. All rights reserved. You may modify.

Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. 5Web site Examples

OverviewOverview

• Interrupt handler (interrrupt service routine) – performs common I/O tasks• can be called as functions

• can be activated by hardware events

• Examples:• keyboard handler

• divide by zero handler

• Ctrl-Break handler

• serial port I/O

Page 6: Assembly Language for Intel-Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, 2006-2007. All rights reserved. You may modify.

Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. 6Web site Examples

Interrupt Handling Interrupt Handling

Executing Interrupt Handlers:-

• software interrupt • Hardware Interrupt

Page 7: Assembly Language for Intel-Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, 2006-2007. All rights reserved. You may modify.

Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. 7Web site Examples

Interrupt Handling Interrupt Handling

Interrupt Control Instructions:-

• STI instruction (enable external interrupts)

• CLI instruction (disable external interrupts)

Page 8: Assembly Language for Intel-Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, 2006-2007. All rights reserved. You may modify.

Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. 8Web site Examples

Writing a Custom Interrupt Handler

Page 9: Assembly Language for Intel-Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, 2006-2007. All rights reserved. You may modify.

Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. 9Web site Examples

Ctrl-Break Handler Example

Page 10: Assembly Language for Intel-Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, 2006-2007. All rights reserved. You may modify.

Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. 10Web site Examples

Ctrl-Break Handler Example

Page 11: Assembly Language for Intel-Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, 2006-2007. All rights reserved. You may modify.

Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. 11Web site Examples

Ctrl-Break Handler Example

Page 12: Assembly Language for Intel-Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, 2006-2007. All rights reserved. You may modify.

Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. 12Web site Examples

Terminate and Stay Resident ProgramsTerminate and Stay Resident Programs

• (TSR): Installed in memory, stays there until removed• by a removal program, or by rebooting

Mov ah,31h

Mov dx, code_Length

Int 21h

Page 13: Assembly Language for Intel-Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, 2006-2007. All rights reserved. You may modify.

Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. 13Web site Examples

Interrupt Vector TableInterrupt Vector Table

• Each entry contains a 32-bit segment/offset address that points to an interrupt service routine

• Offset = interruptNumber * 4

Page 14: Assembly Language for Intel-Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, 2006-2007. All rights reserved. You may modify.

Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. 14Web site Examples

TSR Example: printing a character when print TSR Example: printing a character when print screen button is pressedscreen button is pressed

.Model tiny

.code

Jmp init

Start_TSR:

push ax

push es

mov ax,0b800h

mov es,ax

mov es:[0],’A’

mov es:[1],07

pop es

pop ax

iret

Init:

mov ax,0

mov ds,ax

Cli

Mov word ptr ds:[20],offset start_TSR

Mov word ptr ds:[22],CS

sti

Mov dx, offset init

Mov ah,31h

Int 21h

End

Page 15: Assembly Language for Intel-Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, 2006-2007. All rights reserved. You may modify.

Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. 15Web site Examples

TSR Example: make the print screen button TSR Example: make the print screen button acts as the Caps Lock acts as the Caps Lock

.Model tiny

.code

Jmp init

Start:

push ax

push es

mov ax, 40h

mov es, ax

xor byte ptr es : [17h], 01000000b

pop es

pop ax

iret

Init:

mov ax, 0

mov ds, ax

Cli

Mov word ptr ds:[20],offset start

Mov word ptr ds:[22],CS

sti

Mov dx, offset init

Mov ah,31h

Int 21h

End

Page 16: Assembly Language for Intel-Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, 2006-2007. All rights reserved. You may modify.

Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. 16Web site Examples

TSRTSR

1 1 1 1 1 1 1 1

7 6 5 4 3 2 1 0 (bit position)

Insert mode onCaps lock is onNum lock is onScroll lock is onALT key held downCTRL key held downLeft shift key held downRight shift key held down

Page 17: Assembly Language for Intel-Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, 2006-2007. All rights reserved. You may modify.

Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. 17Web site Examples

TSR Example: toggles the Caps Lock every TSR Example: toggles the Caps Lock every 55ms 55ms

.Model tiny

.code

Jmp init

Start:

push ax

push es

mov ax, 40h

mov es, ax

xor word ptr es : [17h], 01000000b

pop es

pop ax

iret

Init:

mov ax, 0

mov ds, ax

Cli

Mov word ptr ds:[1ch*4],offset start

Mov word ptr ds:[1ch*4+2],CS

sti

Mov dx, offset init

Mov ah,31h

Int 21h

End

Page 18: Assembly Language for Intel-Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, 2006-2007. All rights reserved. You may modify.

Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. 18Web site Examples

TSR Example: toggles the Caps Lock 3 times TSR Example: toggles the Caps Lock 3 times

.Model tiny

.codeJmp initCount db 0Start:

push axpush escmp cs:[offset count], 3je Fininc cs:[offset count]mov ax, 40hmov es, ax xor word ptr es : [17h], 01000000b

Fin:pop espop axiret

Init:

mov ax, 0

mov ds, axCli

Mov word ptr ds:[1ch*4],offset start

Mov word ptr ds:[1ch*4+2],CS

sti

Mov dx, offset init

Mov ah,31h

Int 21h

End