SlideShare a Scribd company logo
1 of 2
Download to read offline
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

Viewers also liked

第一屆Tesa讀書會
第一屆Tesa讀書會第一屆Tesa讀書會
第一屆Tesa讀書會Vista Cheng
 
English Language Course Certificate
English Language Course CertificateEnglish Language Course Certificate
English Language Course CertificateMohammed AlQahtani
 
Effects of Wall Street Crash in Germany 1929
Effects of Wall Street Crash in Germany 1929Effects of Wall Street Crash in Germany 1929
Effects of Wall Street Crash in Germany 1929ARPUTHA SELVARAJ A
 
La ghirlanda di Pasqua - Disegni da colorare - Sabbiarelli
La ghirlanda di Pasqua - Disegni da colorare - SabbiarelliLa ghirlanda di Pasqua - Disegni da colorare - Sabbiarelli
La ghirlanda di Pasqua - Disegni da colorare - SabbiarelliSabbiarelli
 
Agenda ri ssa meeting cairo 2-3 march 2015
Agenda ri ssa meeting cairo 2-3 march 2015Agenda ri ssa meeting cairo 2-3 march 2015
Agenda ri ssa meeting cairo 2-3 march 2015Nena Agri
 
Il clown - Disegni da colorare - Sabbiarelli
Il clown - Disegni da colorare - SabbiarelliIl clown - Disegni da colorare - Sabbiarelli
Il clown - Disegni da colorare - SabbiarelliSabbiarelli
 
Company Profile
Company ProfileCompany Profile
Company ProfileBrett Otto
 
06 cuestionario 04
06 cuestionario 0406 cuestionario 04
06 cuestionario 04jordysla
 

Viewers also liked (17)

Chuong6 (2)
Chuong6 (2)Chuong6 (2)
Chuong6 (2)
 
Chuong7
Chuong7Chuong7
Chuong7
 
Sherrill Dissertation Summary
Sherrill Dissertation SummarySherrill Dissertation Summary
Sherrill Dissertation Summary
 
第一屆Tesa讀書會
第一屆Tesa讀書會第一屆Tesa讀書會
第一屆Tesa讀書會
 
Positivismo 35 tp
Positivismo 35 tpPositivismo 35 tp
Positivismo 35 tp
 
Revista Jurídica, n. 4, set./dez. 2004
Revista Jurídica, n. 4, set./dez. 2004Revista Jurídica, n. 4, set./dez. 2004
Revista Jurídica, n. 4, set./dez. 2004
 
Frases
FrasesFrases
Frases
 
English Language Course Certificate
English Language Course CertificateEnglish Language Course Certificate
English Language Course Certificate
 
Effects of Wall Street Crash in Germany 1929
Effects of Wall Street Crash in Germany 1929Effects of Wall Street Crash in Germany 1929
Effects of Wall Street Crash in Germany 1929
 
Adab 2
Adab 2Adab 2
Adab 2
 
La ghirlanda di Pasqua - Disegni da colorare - Sabbiarelli
La ghirlanda di Pasqua - Disegni da colorare - SabbiarelliLa ghirlanda di Pasqua - Disegni da colorare - Sabbiarelli
La ghirlanda di Pasqua - Disegni da colorare - Sabbiarelli
 
I gallicismi
I gallicismiI gallicismi
I gallicismi
 
Agenda ri ssa meeting cairo 2-3 march 2015
Agenda ri ssa meeting cairo 2-3 march 2015Agenda ri ssa meeting cairo 2-3 march 2015
Agenda ri ssa meeting cairo 2-3 march 2015
 
Il clown - Disegni da colorare - Sabbiarelli
Il clown - Disegni da colorare - SabbiarelliIl clown - Disegni da colorare - Sabbiarelli
Il clown - Disegni da colorare - Sabbiarelli
 
ABB 1
ABB 1ABB 1
ABB 1
 
Company Profile
Company ProfileCompany Profile
Company Profile
 
06 cuestionario 04
06 cuestionario 0406 cuestionario 04
06 cuestionario 04
 

More from Hồ Lợi

Tóm tắt các hàm chuẩn của c
Tóm tắt các hàm chuẩn của cTóm tắt các hàm chuẩn của c
Tóm tắt các hàm chuẩn của cHồ Lợi
 
Lect04 functions
Lect04 functionsLect04 functions
Lect04 functionsHồ Lợi
 
Ky thuatkhudequy
Ky thuatkhudequyKy thuatkhudequy
Ky thuatkhudequyHồ Lợi
 
Itt epc assignment
Itt epc assignmentItt epc assignment
Itt epc assignmentHồ Lợi
 
Huong danontapc
Huong danontapcHuong danontapc
Huong danontapcHồ Lợi
 
H hai epc_baitap
H hai epc_baitapH hai epc_baitap
H hai epc_baitapHồ Lợi
 
Giaotrinhbaitapkythuatlaptrinh
GiaotrinhbaitapkythuatlaptrinhGiaotrinhbaitapkythuatlaptrinh
GiaotrinhbaitapkythuatlaptrinhHồ Lợi
 
Giao trinh ky thuat lap trinh 2
Giao trinh ky thuat lap trinh 2Giao trinh ky thuat lap trinh 2
Giao trinh ky thuat lap trinh 2Hồ Lợi
 
Giao trinh c c++
Giao trinh c c++Giao trinh c c++
Giao trinh c c++Hồ Lợi
 
Epc assignment
Epc assignmentEpc assignment
Epc assignmentHồ Lợi
 
Epc test practical
Epc test practicalEpc test practical
Epc test practicalHồ Lợi
 
De thic++ --th
De thic++ --thDe thic++ --th
De thic++ --thHồ Lợi
 

More from Hồ Lợi (20)

Xu ly chuoi
Xu ly chuoiXu ly chuoi
Xu ly chuoi
 
Tóm tắt các hàm chuẩn của c
Tóm tắt các hàm chuẩn của cTóm tắt các hàm chuẩn của c
Tóm tắt các hàm chuẩn của c
 
T4
T4T4
T4
 
Nguyen lyoop
Nguyen lyoopNguyen lyoop
Nguyen lyoop
 
Lect04 functions
Lect04 functionsLect04 functions
Lect04 functions
 
Ky thuatkhudequy
Ky thuatkhudequyKy thuatkhudequy
Ky thuatkhudequy
 
Itt epc assignment
Itt epc assignmentItt epc assignment
Itt epc assignment
 
Huong danontapc
Huong danontapcHuong danontapc
Huong danontapc
 
H hai epc_baitap
H hai epc_baitapH hai epc_baitap
H hai epc_baitap
 
Gtrinh oop
Gtrinh oopGtrinh oop
Gtrinh oop
 
Giaotrinhbaitapkythuatlaptrinh
GiaotrinhbaitapkythuatlaptrinhGiaotrinhbaitapkythuatlaptrinh
Giaotrinhbaitapkythuatlaptrinh
 
Giao trinh ky thuat lap trinh 2
Giao trinh ky thuat lap trinh 2Giao trinh ky thuat lap trinh 2
Giao trinh ky thuat lap trinh 2
 
Giao trinh c c++
Giao trinh c c++Giao trinh c c++
Giao trinh c c++
 
File trong c_
File trong c_File trong c_
File trong c_
 
Epc assignment
Epc assignmentEpc assignment
Epc assignment
 
Epc test practical
Epc test practicalEpc test practical
Epc test practical
 
De thic++ --th
De thic++ --thDe thic++ --th
De thic++ --th
 
Dethi c++ -lt
Dethi c++ -ltDethi c++ -lt
Dethi c++ -lt
 
Debug trong c
Debug trong cDebug trong c
Debug trong c
 
D05 stl
D05 stlD05 stl
D05 stl
 

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;