|
|
各位前輩好,以下的程式為在 big_real_mode 讀取記憶體的值* ?7 o# D6 |) W, a
/ _" j8 f7 X* W3 x0 b$ h4 D9 T% ?! j
例如: C:\memory.exe(程式檔名) 01000100(Address)% _0 M W# a% Q6 q% s" s* {4 F
& m9 e0 M7 a" Q4 d2 f則會顯示01000100位置的值% t( e4 ~7 [5 e e
: a4 e( j( i9 v# P- D但是我另外還有要顯示出字串,但是顯示出來都是亂碼
1 k k3 J' F) t" T
' C2 H6 o) ^6 ]$ @7 P麻煩前輩給我一些指導,謝謝 % i! }; S, N$ z% L! a
4 C e# j' d5 U( B; [: n7 F5 w! ^7 z' `7 f
.model small- j; y; F9 Z( J- {4 b# _3 ~+ e: d' P
.386p
# `4 q/ H7 t' |9 h;------------------------------------------------------------------------------------------------2 R0 t0 E6 W$ [0 I7 {0 _9 I
DSEG SEGMENT USE16'data'
# `5 P) J2 h- u( m* o- s- ^& @2 U9 N! |2 g9 ? r
DESC STRUC7 }$ ?+ C, z2 w* s' x) y
LimitL DW 0 ( E, Y- A* {8 M4 C- @/ _
BaseL DW 0
8 E% W* H& V1 \' V# ?3 A BaseM DB 0 ; l' B# u d% [8 U2 x. u% c, K
Attributes DB 0
: G. _3 g1 v- J* @9 ~4 } LimitH DB 0
7 z9 V( @8 o! m8 Y$ {* `; B BaseH DB 0 $ T& }7 a) M7 A6 S7 X- d O+ M
DESC ENDS
: n* J" W6 ^' a, R! V! f: S7 L
( t+ i+ ?& i, I/ a& j& h- {PDesc STRUC- _6 K5 \- ~! T7 A5 q1 \
Limit DW 0 8 G" N! P4 n* Z7 _
Base DD 0 3 I i+ F( E9 y
PDesc ENDS5 ~6 g' b* C% u5 M }7 |
" R% b: D- w p: ^8 l! m* aGDT_def Label Fword9 m. }' V- M. r5 k3 J8 E
Null_Desc DESC < 0h, 0h, 00h, 00h, 000h, 0>6 c q, z# p4 O7 }! \# ^1 \0 L1 C
Data_Desc DESC < 0FFFFh, 0h, 00h, 92h, 0CFh, 0>2 W% |1 O* C$ M5 Q1 g0 q1 Z
GDT_Addr PDesc <$-GDT_def-1, >
- V. \; S% v; B- q
3 ?$ j0 i3 R7 Y, [5 amsg1 BYTE 'The Input Address is '
7 X: U/ k i7 ^msg2 BYTE 'The Data is:','$'
& h2 I% O0 {& }5 v
2 u o* Q8 n0 X" h" `: n7 rDSEG ENDS# Q6 o- k( w1 d1 q @
- X) v* \' n8 m
" N2 Q; p0 N( C0 z; }; u2 ^1 b
;------------------------------------------------------------------------------------------------
7 t- l1 B, m; T4 k6 p# B6 |
. d$ O) g3 p$ E- }ASSUME CS:CSEG,DS SEG. }. Y" s6 V1 L
' d* M- f+ l$ @
CSEG SEGMENT USE16'code'
: M9 `6 S) p- x, v7 T1 X' p 5 V1 W8 V" m: [; q
push ds
- Z+ \# n. D2 x' N& D' v3 J M push es+ |4 H! m( ^0 R2 K& [; a
push fs. s* ~' n0 a) E5 K1 b \$ Z
push gs
- F' z3 v4 I8 p# S0 U) @, G$ T 2 y2 w( M, R: r9 _9 g/ h
call big_real_mode
! r* a: |1 r! P" M1 Q# A) \5 u0 I6 N
" c6 f& D# j9 t$ s' q( W: |- M mov edx,OFFSET msg1;* k3 E4 H* f5 [+ I) i
mov ah,09h;
1 u/ J% {/ K3 S6 F3 I( j2 c int 21h;
' M9 k& S1 x+ ?( Z8 I mov edx,OFFSET msg2;
# ?; j0 [; c/ J% f6 G, X mov ah,09h;3 b0 e# d' a/ ?
int 21h;4 B _$ t* l; y
0 y( n% y4 S3 o& d3 A$ A X call PSP
1 z5 A& J, {$ W% f$ \2 |, Z ; W" v; \2 j$ i
call crlf
1 r* T( Z" D* V7 u+ x' i# ? " ~" o! q7 F. k2 }4 e
mov esi,ebx% l: K! A( N2 v, P z
mov eax,fs:[esi]
0 A$ s( ^# O8 @6 R9 Z' H" [ out 80h,eax
/ u7 j. C5 y9 b* E mov ebx,eax
) U) j9 \ g8 A+ q call _8bits
- {/ t- r, v. x) F5 {4 I/ q
) ~+ k3 A& j; e5 R0 f) U call real_mode( b# O% J$ |2 r2 l
% D& }; q) L- A& D! ] i pop gs
, j- r% @3 n: E pop fs5 ]* P2 d/ J% x* z" a6 F
pop es
, I. \) j* S1 I: L) } pop ds) U8 W' n Q0 K/ a7 N1 x- J ], O
: O+ N, A- G h" I+ `+ h4 t: E .exit
1 {! j# Q$ g: u' I;------------------------------------------------------------------------------------------------8 F. V. C# t- _7 K+ H3 h) N
big_real_mode proc near
, h/ F: \0 V3 ]% t" @6 z! c: } in al, 92h
0 @/ @5 C& R; I/ ~ or al, 002
" X/ B$ f7 A4 ~- B) F. x- ?' u* e out 092h, al% a/ R9 x3 n8 Z
out 0edh, al
) `. P: C) R+ V cli
|3 ]6 T- ^- P, I3 V) V$ e mov eax,DSEG
$ u3 J9 p( v4 h% R/ G0 g shl eax, 4
- ]+ V) [- U! H. ~ xor ebx, ebx! {8 C: _, V7 b* D$ \
mov ebx, offset GDT_def
) T5 O. z$ |2 y# U8 d add eax, ebx
2 W) {+ P; A; }. M* U; U+ Z9 ` mov dword ptr GDT_Addr.Base, eax1 n) D' l1 A( K2 x- k. J
lgdt fword ptr GDT_Addr
. o; P4 I8 a5 [) B mov bx, 8
9 ]1 u' D) ~/ z mov eax, cr0$ B/ p$ Q, }& j! M/ V5 d
or al, 1
* {8 A: [6 [. l" e mov cr0, eax9 P' Y( E6 D# A
jmp PMod
+ V+ _- P* ^2 z: ^/ CPMod:$ S/ N: ]8 B# [/ S* y8 P+ q& j
mov fs, bx+ |# M& J, E# x/ ~5 _; ~/ R
mov gs, bx
. Z) P$ S/ u n p* C9 e% ~" O mov eax,cr03 |5 T1 V, R9 H, N
and al, 0FEh0 B+ B6 ?! X1 a5 R; A" S
mov cr0, eax
9 c3 @' c5 q \ a9 [& u jmp RMod3 P! U2 o$ G! }+ q+ M4 H
RMod:
- S( V" Y1 i2 h$ u7 a1 o' T3 a xor ax, ax
8 r; M9 K( T' A% R" P mov fs, ax6 {% j; ]# K* j3 Y
mov gs, ax' c- Y, a/ G* v8 w( n
! V; l' n2 ], D- ?+ | sti1 a, q8 k% X! e
8 S% I7 l- Z8 G3 T |2 ?
ret
/ n$ s4 B5 h. T( N* N8 Sbig_real_mode ENDP% h. j1 }1 \! E# o- e, I
;------------------------------------------------------------------------------------------------5 M: P1 Q( ]1 z5 q" `' f4 A; Q
real_mode proc near/ o4 h1 P" B9 `& Y r
in al, 92h+ T0 a+ t, A% J/ l
and al, 02
* C/ B& y i6 U" }' O, r* f out 92h, al
& x( v2 e/ I& j& H& N ret
% a# V+ J; t* i+ W# \real_mode ENDP) M" n2 C; e1 N7 [: w+ P" B/ J {
;------------------------------------------------------------------------------------------------
% c+ |/ v H% M8 LGet_Commandtail PROC near/ y3 N* T( m1 @+ T; U
push es n! X) v% k, [) _
pusha
5 u0 ?6 k! z4 ]) ^, n3 u& h mov ah,62h 6 x, ~7 P' d5 J, n) r7 r
int 21h
' x+ A+ ^, l4 M1 V- u mov es,bx
! {& m! n1 [' U/ A, F! J, t; s popa
, ]+ d6 g$ ?$ p+ ^ pop es
8 a) J* w# G$ r. m. c, @0 E ret
- t* X! W$ n+ fGet_Commandtail ENDP
0 G* z, \/ e8 F" r" M6 b1 k;------------------------------------------------------------------------------------------------6 S. z B: `8 A5 J k* O
PSP proc near
\$ n! G$ k/ q+ N0 V/ w7 ~ mov ah,62h! E# X* r. U8 G
int 21h8 ?& H! g: d/ X. M( F
mov es,bx & i8 d8 t# e( w/ H( `0 J
xor ebx,ebx
' x) P( Q# V% h( u* r mov si,82h. S5 q0 C7 X. r' X
mov al,es:[si]
% Z, A& k0 V# m* V call Change
; F% T; p/ { H t8 T+ B* m mov cl,4 q: q! v$ Y. \4 \ D
shl ebx,cl: g4 N; K- O! ^ v4 \, t9 | \
add ebx,eax
: B- R8 k! Z% V3 [ mov al,es:[si+1] ~' d. r& j$ d; M% m. n
call Change4 X; F/ ^$ M, d3 S) N
mov cl,4
/ Z* [3 }9 k; A+ [ shl ebx,cl
& g* ^& B( ~& C add ebx,eax
# j0 Y6 U4 n$ ]1 o mov al,es:[si+2]) X5 H8 v. L7 i( u8 c" ~
call Change
* C/ _8 f% n2 @* A6 s& a mov cl,4. c2 q' N* P+ \
shl ebx,cl
, [' ~: I! V3 \6 O; l$ |0 M* P add ebx,eax
) V/ R; h9 a, c# B d( d4 S1 ]! N mov al,es:[si+3]7 u, c! u4 ]7 z$ J$ q O
call Change! X0 K$ x1 }# d: O
mov cl,4, M4 T( g" m2 N& l9 |9 \
shl ebx,cl
9 |6 U* ^; f& z0 Z) T) `0 h1 H add ebx,eax
; r- c9 b2 y- D& c6 u, f |# W$ k# ]4 K0 v mov al,es:[si+4]
) O5 g1 e- s$ |, ^4 y {# e" @ call Change" o- G8 r4 ~/ ?
mov cl,4/ Y0 E0 R7 f4 }+ E. u
shl ebx,cl
, y8 N# q) r4 Y. h' w6 p( `, o add ebx,eax& L2 T6 j: y2 m- ?9 K
mov al,es:[si+5]5 f1 g, l$ x* q7 ?. ~
call Change
) Y6 C0 d) |- U9 R$ v l; I+ y mov cl,4. O1 ]3 X7 R- j7 C( I
shl ebx,cl
1 i7 R& a1 I6 I! _6 S- H% J- j add ebx,eax6 t6 z L3 j0 O$ z
mov al,es:[si+6]
2 A) I! K; E% t, P# M3 `6 R# R call Change4 g/ D$ ^, |7 j$ [. \$ t
mov cl,4
% N2 a( t2 K3 A" ~4 } shl ebx,cl1 L0 U/ x! x7 G" {$ p, e5 g
add ebx,eax
& C; _+ n* p# ]5 V: B4 \ mov al,es:[si+7]
H& b# N* `6 }" ~$ {, W+ e9 g call Change X$ m! e4 m# @; Y2 ~" q
mov cl,4+ [6 l, b# {$ @- i
shl ebx,cl
+ a4 F1 e; R3 l( D, V add ebx,eax
5 [" H* r3 [# Q) ]3 d$ X ret/ F) v" N8 |$ L+ ?( X+ Q
PSP endp8 i. ]) c: J& X
;------------------------------------------------------------------------------------------------
8 W! E, F' I6 b0 x. {9 nChange proc near6 V8 T; Z5 D# H) y+ T! Q
A: 7 P: I/ G' H! s' z3 u+ p7 N6 E
movzx eax,al
( K Z' \: z8 F4 W9 p# E mov edx,eax* g5 N- L6 F; {: f: ?
cmp eax,'0'
9 b- q: X# a) B4 S jb A6 ]) G4 V1 ^! A1 ?! w
cmp eax,'9'
: q& f; C* i! g w: R+ c ja B
( W4 T+ t* s; I9 e, }6 R sub eax,'0'; m7 g: B1 c& A$ D
jmp short E( C+ g7 i$ j' g# n
B:
5 v; H/ L! J! E and eax,0dfh
5 |& `& p; w# u# t5 T mov edx,eax
4 c! s. v: A) U/ |( n, x sub eax,37h : q4 C" }2 l2 A+ L+ u6 V
cmp eax,0ah. L8 O9 f" l% z( Z$ e! r( m
jb A * J) w0 g5 H9 Y4 R8 t( P+ V3 W
cmp eax,0fh
2 n1 S* ^) t8 k ja A 0 x* H( N& ?* N# X* A, X
E: J4 y: X9 d- J. B U! h9 W
push eax
% @9 x1 m4 L; Y& g: A8 w y% _: f call PRT
' |8 A4 W2 ~* q y pop eax) P) ]2 j2 c9 P k h
CExit:3 j5 k/ G0 M) m; R% t" `5 \/ d3 P
ret
/ o" t, e* Z8 i. L. Y' \; b( g9 _, \Change endp( y' ^3 i0 C7 |/ s- R* r8 \# ^2 y, c, g
;------------------------------------------------------------------------------------------------! G& z6 b! W" V5 N8 F
PRT proc near$ D Y. d3 n {1 ?3 u% b: T* K$ K0 o
mov ah,02h
% Y+ |6 o! _- A3 Z/ ~9 [& ^: e% K int 21h# K' } ]+ Q' G2 V' c' h/ q e
ret
6 ]' ^/ Z8 k( W9 n, `+ h4 [PRT endp
& ~, X( l' M3 J;------------------------------------------------------------------------------------------------
9 \3 j$ `* I. xcrlf proc near
+ b, D$ d1 f& ^- K& z k' K mov ah,02h
6 q% o' j3 D- \& Z( q mov dl,0dh
. \! `$ b$ a* m8 G8 ` int 21h3 ~. C& Q' {- z3 d6 T) U; ?# v
mov ah,02h
4 j$ \& s: ` H' }, Z& S6 h mov dl,0ah6 A' {* i* z6 W& e/ L/ g2 U4 h
int 21h) e7 h, M8 q* x7 R/ v
ret
" @) O: p$ X& p, p' L) scrlf endp9 p; y4 p; t) X# K. ^8 P
;------------------------------------------------------------------------------------------------
8 x b& j# ? T# F_32bits proc near
# U8 q6 a& Z/ k) x0 V8 w pushad* e1 Z$ [* j% ]6 F
mov cl,4
* g: [* i" w3 I rol ebx,cl" y- J+ l6 E; A
call print_4_bits) \$ B! G5 N# F9 H
rol ebx,cl
h- v* t4 r B: |/ v call print_4_bits
/ [. E2 b0 ]# z rol ebx,cl0 s* ?, c6 [& i
call print_4_bits
$ r2 G3 c( Q! U* F rol ebx,cl, |5 t& \6 z, Y+ W* t
call print_4_bits$ s' X# R) Y5 [. s: N) P
rol ebx,cl
6 b8 }$ F7 @/ ]# q" p call print_4_bits$ O! a8 ] C9 a+ T& H& D
rol ebx,cl
* w! g0 ?. h, p! `4 v$ }; ~' B call print_4_bits. ~- ]( }6 P# B
rol ebx,cl
! E$ q7 i3 B% ~+ G6 d call print_4_bits
0 [3 [1 Y# p' w4 e# d8 y' }: s rol ebx,cl
2 d- {$ w& k1 r) S6 R call print_4_bits1 G' P6 n: Q4 {, L' _$ B# J
rol ebx,cl
4 |7 W* L5 h; I popad
) X$ R+ d# S X3 W4 W3 N: j9 j ret
% E) j0 `3 U- Y$ [ ]3 @0 y_32bits endp9 ?3 s1 ?( s3 j+ f
;------------------------------------------------------------------------------------------------8 b# @3 r8 u+ j
_16bits proc near0 c% v9 _' M) h: a! P: C
pusha
. u: J. w: A9 H rol bx,cl
1 I K) H" O7 q9 l- T5 t& M" [9 l* T call print_4_bits6 D0 w, S( d9 a& P8 b
rol bx,cl
& i3 o: f5 Y. q% ?; ]6 [ call print_4_bits$ r- |. g. W2 x% N0 U, B
rol bx,cl: ~( @$ K0 |' e: W1 @# e
call print_4_bits
0 O# j" H; Z) A6 w0 X9 G rol bx,cl7 ?1 q7 F3 Z5 r3 O3 J! X$ t3 N
call print_4_bits+ _ `* ^/ W; l5 T8 y
popa) |; E$ [/ d* X% J
ret! j& X' h0 q! n W$ u. C$ ^$ }
_16bits endp
6 I# D- v6 s3 ?! _& p" O;------------------------------------------------------------------------------------------------; t0 ~, e2 J' {3 N
_8bits proc near5 E/ T3 s" F/ m, v$ g
pusha , y& \# w- M! S9 T
rol bx,cl% b! e- `8 d) Z+ f( e, O
call print_4_bits5 f+ Q" d$ A* t7 Y9 y# k3 X1 w) R+ u
rol bx,cl$ `4 h' o5 h) }0 V2 e# C( u: q7 V
call print_4_bits
( v4 v: x5 b t, O1 D popa' Q3 j$ _) l! N' U- Y' g# p
ret
- B9 m2 U: L( z0 _; l4 v3 K_8bits endp3 ]1 r5 Q7 t+ V0 {2 Y
;------------------------------------------------------------------------------------------------. M' u$ g h5 B$ S4 G4 d
print_4_bits proc near
; K5 C$ L) l( `2 g6 g; ~' K; I mov dx,bx! q$ v6 K9 W0 q2 s3 X! t
and dl,0fh
- {( ~6 w9 S R& ~1 @ add dl,30h9 }6 m/ s" j& q5 \
cmp dl,3ah
6 d) t9 l# J) Z jb print8 W! p$ q" S$ x6 X. p, n0 s7 @
add dl,7% G& Y# q# q$ e
print:
! Y- f7 ^: O- Z& M0 a* \+ W mov ah,2
5 \3 v2 E# H. f6 g int 21h
4 ~- P) \; f! t8 F( d- i ret
/ w0 I# X& c) j8 Yprint_4_bits endp % j4 k0 H/ B3 g( I! I4 n
;------------------------------------------------------------------------------------------------
8 O F- |4 n) ^$ Z- i6 wCSEG ends
* \9 D: {% O5 O- j; d4 JEND |
|