ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
58
Ch??ng 5 : truy c?p tr¨´c ti?p b¨¦ nh¨ª
¡ì1.C?c h?m truy c?p theo ??a ch? ph?n ?o?n
1. H?m pokeb() : D?ng ?? g?i m¨¦t k? t¨´ value v?o b¨¦ nh¨ª t?i ??a ch? ph?n ?o?n off .
Nguy?n m?u c?a h?m trong dos.h l? :
void pokeb(unsigned seg,unsigned off , char value)
2. H?m peekb() : Nh?n m¨¦t byte t?i ??a ch? seg:off . Nguy?n m?u c?a h?m trong dos.h l? :
char peekb(unsigned seg,unsigned off)
3. H?m poke() : G?i m¨¦t s¨¨ nguy?n value v?o b¨¦ nh¨ª t?i ??a ch? seg:off . Nguy?n m?u c?a
h?m trong dos.h l? :
void poke(unsigned seg,unsigned off , int value)
4. H?m peek() : Nh?n m¨¦t word t?i ??a ch? seg:off . Nguy?n m?u c?a h?m trong dos.h l? :
void peek(unsigned seg,unsigned off )
5. H?m movedata() : Sao n byte t? ??a ch? seg_gui:off_gui ??n ??a ch? seg_nhan:off_nhan .
Nguy?n m?u c?a h?m trong menu.h l? :
void movedata(unsigned seg_gui,unsigned off_gui , unsigned seg_nhan,unsigned
off_nhan , int n)
¡ì2. ¡ì?i t? ??a ch? ph?n ?o?n sang ??a ch? th¨´c
1. ¡ì?i t? ??a ch? th¨´c : ¡ì? ??i t? ??a ch? th¨´c sang ??a ch? ph?n ?o?n ta d?ng macro sau :
unsigned FP_SEG(??a ch? th¨´c)
unsigned FP_OFF(??a ch? th¨´c)
2. ¡ì?i t? ??a ch? ph?n ?o?n : ¡ì? ??i t? ??a ch? ph?n ?o?n sang ??a ch? th¨´c ta d?ng macro :
void far *MK_FP(seg:off)
V? d? : Sau khi th¨´c hi?n c?c c?u l?nh:
char buf[100]
unsigned ds,dx;
ds= FP_SEG(buf)
dx= FP_OFF(buf)
th¡Á ds:dx ch?a ??a ch? c?a n?mg buf .
Sau khi th¨´c hi?n c?u l?nh :
char *pchar;
pchar = (char *) MK_FP(0xb800:0)
th¡Á pchar tr¨¢ t¨ªi ??u b¨¦ nh¨ª m?n h¡Ánh . Khi ?? ta c? th? d?ng c?c l?nh g?n ?? truy c?p tr¨´c
ti?p t¨ªi b¨¦ nh¨ª m?n h¡Ánh .
Ch??ng tr¡Ánh 5-1 : L?p ch??ng tr¡Ánh x?c ??nh ??a ch? c?a m¨¦t ng?t .
#include <dos.h>
#include <conio.h>
#include <stdio.h>
void main()
{
unsigned char far *p;
int n,k;
unsigned seg,off;
clrscr();
p=(unsigned char far*)MK_FP(0,0);
59
while(1)
{
printf("nSo hieu ngat(Bam 0 de ket thuc): ");
scanf("%d",&n);
if (n==0)
break;
k=(n-1)*4;
off=p[k]+256*p[k+1];
seg=p[k+2]+256*p[k+3];
printf("nDia chi cua ngat %x : %x",seg,off);
}
}
S¨¨ hi?u c?a ng?t ???c ??nh s¨¨ t? 0 nh?ng n ???c nh?p t? 1 , m?i ng?t chi?m 4 byte
n?n ta c?
k=(n-1)*4;

More Related Content

Chuong5

  • 1. 58 Ch??ng 5 : truy c?p tr¨´c ti?p b¨¦ nh¨ª ¡ì1.C?c h?m truy c?p theo ??a ch? ph?n ?o?n 1. H?m pokeb() : D?ng ?? g?i m¨¦t k? t¨´ value v?o b¨¦ nh¨ª t?i ??a ch? ph?n ?o?n off . Nguy?n m?u c?a h?m trong dos.h l? : void pokeb(unsigned seg,unsigned off , char value) 2. H?m peekb() : Nh?n m¨¦t byte t?i ??a ch? seg:off . Nguy?n m?u c?a h?m trong dos.h l? : char peekb(unsigned seg,unsigned off) 3. H?m poke() : G?i m¨¦t s¨¨ nguy?n value v?o b¨¦ nh¨ª t?i ??a ch? seg:off . Nguy?n m?u c?a h?m trong dos.h l? : void poke(unsigned seg,unsigned off , int value) 4. H?m peek() : Nh?n m¨¦t word t?i ??a ch? seg:off . Nguy?n m?u c?a h?m trong dos.h l? : void peek(unsigned seg,unsigned off ) 5. H?m movedata() : Sao n byte t? ??a ch? seg_gui:off_gui ??n ??a ch? seg_nhan:off_nhan . Nguy?n m?u c?a h?m trong menu.h l? : void movedata(unsigned seg_gui,unsigned off_gui , unsigned seg_nhan,unsigned off_nhan , int n) ¡ì2. ¡ì?i t? ??a ch? ph?n ?o?n sang ??a ch? th¨´c 1. ¡ì?i t? ??a ch? th¨´c : ¡ì? ??i t? ??a ch? th¨´c sang ??a ch? ph?n ?o?n ta d?ng macro sau : unsigned FP_SEG(??a ch? th¨´c) unsigned FP_OFF(??a ch? th¨´c) 2. ¡ì?i t? ??a ch? ph?n ?o?n : ¡ì? ??i t? ??a ch? ph?n ?o?n sang ??a ch? th¨´c ta d?ng macro : void far *MK_FP(seg:off) V? d? : Sau khi th¨´c hi?n c?c c?u l?nh: char buf[100] unsigned ds,dx; ds= FP_SEG(buf) dx= FP_OFF(buf) th¡Á ds:dx ch?a ??a ch? c?a n?mg buf . Sau khi th¨´c hi?n c?u l?nh : char *pchar; pchar = (char *) MK_FP(0xb800:0) th¡Á pchar tr¨¢ t¨ªi ??u b¨¦ nh¨ª m?n h¡Ánh . Khi ?? ta c? th? d?ng c?c l?nh g?n ?? truy c?p tr¨´c ti?p t¨ªi b¨¦ nh¨ª m?n h¡Ánh . Ch??ng tr¡Ánh 5-1 : L?p ch??ng tr¡Ánh x?c ??nh ??a ch? c?a m¨¦t ng?t . #include <dos.h> #include <conio.h> #include <stdio.h> void main() { unsigned char far *p; int n,k; unsigned seg,off; clrscr(); p=(unsigned char far*)MK_FP(0,0);
  • 2. 59 while(1) { printf("nSo hieu ngat(Bam 0 de ket thuc): "); scanf("%d",&n); if (n==0) break; k=(n-1)*4; off=p[k]+256*p[k+1]; seg=p[k+2]+256*p[k+3]; printf("nDia chi cua ngat %x : %x",seg,off); } } S¨¨ hi?u c?a ng?t ???c ??nh s¨¨ t? 0 nh?ng n ???c nh?p t? 1 , m?i ng?t chi?m 4 byte n?n ta c? k=(n-1)*4;