12
Flow Diagram: Push flags, CS, IP Pop IP,CS,flags Push AX,BX,CX,DX,ES,DS,SI,DI,BP POP BP,DI,SI,DS,ES,DX,CX,BX,AX

Flow Diagram:

Embed Size (px)

DESCRIPTION

Flow Diagram:. Push AX,BX,CX,DX,ES,DS,SI,DI,BP. Push flags, CS, IP. POP BP,DI,SI,DS,ES,DX,CX,BX,AX. Pop IP,CS,flags. Typical Reentrant Routine:. Push AX, Push BX, Push CX, Push DX, Push ES, Push DS, Push SI, Push DI, Push BP ---------- ---------- ---------- ---------- - PowerPoint PPT Presentation

Citation preview

Page 1: Flow Diagram:

Flow Diagram:

Push flags, CS, IP

Pop IP,CS,flags

Push AX,BX,CX,DX,ES,DS,SI,DI,BP

POP BP,DI,SI,DS,ES,DX,CX,BX,AX

Page 2: Flow Diagram:

Typical Reentrant Routine:

--------------------Int--------------------

Push AX, Push BX, Push CX, Push DX,Push ES, Push DS, Push SI, Push DI, Push BP----------------------------------------Pop BP, Pop DI, Pop SI , Pop DS,Pop ES, Pop DX,Pop CX, Pop BX, Pop AX,IRET

Page 3: Flow Diagram:

Animation:

FlagsCSIP

AXBX

ESDX

DS

CX

SIDIBP

Page 4: Flow Diagram:

void main (){

x = sum(4, 5);printf (“%d”, x);a = 10; b = 20; x = sum(a, b);printf (“%d”, x);

}int sum (int i, int j){

return i+j;}

Example:

SP

RP

54

SP

RP

ba

Page 5: Flow Diagram:

void interrupt newint ( unsigned int BP, unsigned int DI, unsigned int SI,

unsigned int DS, unsigned int ES, unsigned int DX, unsigned int CX, unsigned int BX, unsigned int AX, unsigned int CS, unsigned int IP, unsigned int flags)

{a = AX;b = BX;d = ES;

}

Accessing Stack Example:

Page 6: Flow Diagram:

void main ( ) {setvect(0x65,newint);_AX = 0x1234;Geninterrupt (0x65);a = _AX;Printf (“%x”, a);}

Example:void interrupt newint(unsigned int BP, unsigned int DI, unsigned int SI, unsigned int DS, unsigned int ES, unsigned int DX, unsigned int CX, unsigned int BX, unsigned int AX, unsigned int CS, unsigned int IP, unsigned int flags){

AX = 0xF00F;}

Page 7: Flow Diagram:

On EntryAH = Service # = 03AL = No of Blocks to writeBX = Offset Address of DataCH = Track No. , CL = SectorDH = Head #DL = Drive #(Starts from 0x80 for fixed disk & 0 for removable disks)

ES = Segment Address of data buffer.On Exit

AH = return CodeCarry flag = 0 ( No Error AH = 0)Carry flag = 1 ( Error AH = Error Code)

Disk Interrupt ( int# 13H Service# 3)

Page 8: Flow Diagram:

Addressing of Block Specified:Head, Sec, Track

#pragma inline#include <dos.h> #include <bios.h>void interrupt (*oldtsr) ( );void interrupt newtsr (unsigned int BP, …, flags);void main ( ){

oldtsr = getvect (0x13);setvect = (0x13, newtsr);keep (0, 1000);

}

Page 9: Flow Diagram:

void interrupt newtsr(unsigned int BP, unsigned int DI, unsigned int SI, unsigned int DS, unsigned int ES, unsigned int DX, unsigned int CX, unsigned int BX, unsigned int AX, unsigned int CS, unsigned int IP, unsigned int flags){ _ES = ES; _DX = DX;if ( _AH = = 0x03) _CX = CX;_BX = BX;if(( _DH= =1 && _CH= =0 _AX = AX;&& _CL= =1)&& _DL>=0x80) *oldtsr;{ asm pushf;

asm clc; asm pop flags;asm pushf; AX = _AX; BX = _BX;asm pop flags; CX = _CX; DX = _DX;return; ES = _ES;

} }

Page 10: Flow Diagram:

Key Pressed

Move Scan Code from 60H port toAL

Convert to ASCII& place it in keyboard buffer

Int 15HService 4FH

Keyboard Interrupt Hook (int# 15H Service# 4FH)

Page 11: Flow Diagram:

Example:

#include <dos.h> #include <bios.h>#include <stdio.h>void interrupt (*oldint15) ( );void interrupt newint15(unsigned int BP, …, flags);void main ( ){

oldint15 = getvect (0x15);setvect (0x15, newint15);keep (0, 1000);

}

Page 12: Flow Diagram:

void interrupt newint15(unsigned int BP, unsigned int DI, unsigned int SI, unsigned int DS, unsigned int ES, unsigned int DX, unsigned int CX, unsigned int BX, unsigned int AX, unsigned int CS, unsigned int IP, unsigned int flags){

if (*(((char*)&AX) + 1) = = 0x4F ){

if (*((char*)&AX) = = 0x2C)*(((char*)&AX)) = 0x1E;

else if (*((char*)&AX) = = 0x1E)*((char*)&AX) = = 0x2C;

}}