|
各位前輩好,以下的程式為在 big_real_mode 讀取記憶體的值
+ O, D; o3 A7 B/ V' U5 E6 g: U7 t+ w
例如: C:\memory.exe(程式檔名) 01000100(Address)& F; }3 L. i5 q0 s' \
- I! y, v4 M' B* y- u4 G
則會顯示01000100位置的值+ t' O) ~0 R# m5 Z( N1 {( m' G
$ j# P$ w7 ?' y) t但是我另外還有要顯示出字串,但是顯示出來都是亂碼
* P" T' u6 k- d5 x* V
7 k- O# _0 |4 }4 U麻煩前輩給我一些指導,謝謝 4 e& _! ?% [$ c3 X& u/ _
7 T7 [. K# [3 F0 O/ R# O8 h' c
/ [1 [6 @8 z! L# n- N& b
.model small
. e" o( D. a1 P5 k.386p; h% X$ z0 o. K) n( S
;------------------------------------------------------------------------------------------------6 D1 \$ C$ f% a5 J
DSEG SEGMENT USE16'data'
5 L+ e1 t* Z0 l$ S- \
+ `* Y/ L. O/ |0 R5 \! fDESC STRUC
2 k) m4 u& R+ Q0 g LimitL DW 0 % V( ]/ D! O+ A( b3 x% |$ A
BaseL DW 0
- S4 x! G( M* C& O9 X BaseM DB 0
; \2 S" y6 p! \, u( e. S Attributes DB 0
% R9 B$ E. I* S( f LimitH DB 0 1 [: z6 v3 }. M) A. G, D' s
BaseH DB 0
' P9 \. m! c: \DESC ENDS* c* ]: D/ O* q3 C
! g6 Z: G3 Q! pPDesc STRUC
7 X: p# q+ i3 O, `* i; s& {! ` Limit DW 0 " j! r: H+ G0 s+ Z
Base DD 0 5 S$ B8 k" K! y+ \% g" e- V
PDesc ENDS
; H* j+ X0 e9 r7 k& d: R! D/ x \2 p& C1 a: [. h: D! q
GDT_def Label Fword( \) |- X- h' a8 c! L, ?4 z
Null_Desc DESC < 0h, 0h, 00h, 00h, 000h, 0>/ [! ^; l8 @: W5 v( O0 [
Data_Desc DESC < 0FFFFh, 0h, 00h, 92h, 0CFh, 0>
R2 b# O5 H9 ~+ Y# xGDT_Addr PDesc <$-GDT_def-1, >
. ]' e9 @2 e, O: m) z! {
* a/ r: v5 q: Zmsg1 BYTE 'The Input Address is'
& h% Z/ G5 U/ w G. |* J. mmsg2 BYTE 'The Data is:','$'
0 J+ a1 g- b0 r5 n. i. `- y* i) b0 T3 V5 Y1 T/ _
DSEG ENDS
+ G5 S. y! O ^# G
) ~" I e" }- n- z. V. }4 Z5 P
1 `5 k, ^$ j; x0 S;------------------------------------------------------------------------------------------------
, O' G- @9 ~* W' S5 N4 X; d; n- x. D6 k' W# U- Z8 ?, Q) Q
ASSUME CS:CSEG,DSSEG
( m' S! A& U5 N/ a$ c
. M% {3 A+ ?+ t9 ?3 L0 aCSEG SEGMENT USE16'code'
/ W5 K# N: w2 B0 Y6 I. X6 I * {6 `5 B6 w: I
push ds
( a6 \; C- D! q! J7 r push es
5 `! T5 v! k8 |: t: r9 f- i push fs
Z) F3 [9 C( f I! z push gs1 F' p% T; w' w9 ~% `& J
3 p# \7 O) H" t+ L+ l2 G9 w
call big_real_mode. |3 [0 j% u6 X5 V3 `) |/ j
* }9 q& l: v0 \
* A; o* r" C" o8 K4 i mov edx,OFFSET msg1;0 F* C6 u* Q; W. `" _" F2 K; [- M
mov ah,09h; 9 o9 _/ D9 ^0 n& D& y% i' k/ T( N
int 21h;
9 l' a& d* }- E5 F5 R mov edx,OFFSET msg2;" l: s" m7 P8 ^3 E! i: `0 o& H
mov ah,09h;& I5 E" h9 o) M* C
int 21h;
9 w: }/ t: M' c1 c$ }! `+ g% _5 n" V
* P5 e0 h* l2 h# l. f) K" C call PSP
7 C+ O8 w2 K! I6 l) s' w 4 x$ u$ Y; P, Q! R
call crlf 2 O# u" J Z5 N3 `- m, W- O9 G
! q) m5 P7 K0 `1 o
mov esi,ebx
. x/ p" J/ [, A mov eax,fs:[esi]: e2 W1 s/ a- o. }( i2 Y: p5 f
out 80h,eax
8 P" {; u; w. q6 E5 j/ t mov ebx,eax
_% R4 D6 }' `. @" V call _8bits5 C, M: L: {$ Y: V
8 z9 T/ I* i, Q4 T% @- K2 w
call real_mode4 Q( O0 K2 G5 K. H5 M
- y; Q$ Z, G |& k$ d y( C. Y pop gs
* ?* S4 o# u0 r4 z2 A" Z: S pop fs+ h2 M4 I" M, ]- ~
pop es; @* m: h" ?- {8 A" f3 M8 W0 I! V* \" u
pop ds. e2 c9 f3 d, e4 ]8 h
* x/ S n4 z9 N .exit
& g- }1 k9 Y$ G+ [3 o' Y. Y;------------------------------------------------------------------------------------------------
3 }7 @) O @1 Bbig_real_mode proc near0 n5 U/ d/ ~4 f3 G3 Y z
in al, 92h5 s' F! |( ~) m" ]6 u
or al, 002
2 f2 k9 ~4 m3 x3 C& [* h out 092h, al
3 _6 s' o3 t7 X5 g$ |1 K out 0edh, al4 ~% a F: k! o. p
cli" n3 e5 P$ ~- a2 ^$ w
mov eax,DSEG
4 X5 ~% e; {( ^3 s. m4 ?$ Q) M/ `8 } L shl eax, 4
% W$ G e, r" ?: u: U+ a xor ebx, ebx0 K: Z. R9 b! h' ~
mov ebx, offset GDT_def# V; U, n) U, K& H1 Q
add eax, ebx! t+ l3 v* K% m9 X, K, R1 n/ k
mov dword ptr GDT_Addr.Base, eax- p3 Q4 ^4 ?" v- c( }5 U, I7 X
lgdt fword ptr GDT_Addr
# F. `, H8 ]) T/ U$ m mov bx, 8" x. `* |' R3 w' @* J# Q
mov eax, cr0
) J! V/ O3 i* [* @; ?$ ~% g+ V( ` or al, 1
$ I7 `* c% r/ A1 P. I0 l& n$ V mov cr0, eax; |& [+ b4 u" T0 I* O# P
jmp PMod
( y% Y3 ]. x( }6 g2 E. YPMod:
) {! ?. C( K8 R! X mov fs, bx% a* R9 \: A" G( ]' _
mov gs, bx1 ]9 [1 H0 T! G" H5 j l
mov eax,cr05 X6 K2 \, m/ d% v$ m h
and al, 0FEh
_6 V" e% o( X! C mov cr0, eax ! v( s: j5 W) j7 m% z8 ?
jmp RMod
3 M; i0 M: d! W, W4 hRMod:; b8 \! [' J$ ` j; ]
xor ax, ax
! q+ T2 Z4 @! q h9 z% t% \ mov fs, ax0 [8 v- X5 K: m3 C$ {
mov gs, ax5 A! n6 l! B/ R8 w1 }* A4 l0 M
, I4 @- W9 F- { sti
. ~# T3 D1 x- G- F B" ~ * ?. G8 D) s$ _! v* H: F
ret
: }3 u$ o4 u- Lbig_real_mode ENDP* V; R( ] f, U5 A
;------------------------------------------------------------------------------------------------1 ^! t1 Q& P* {' A+ ~# `
real_mode proc near. m N7 C3 ~6 Y8 Y0 R6 X1 a8 p* t
in al, 92h
! x& W2 y% w% y* v0 l" ` and al, 02
7 z, _4 C' Q6 n% }* y* F out 92h, al
4 j( |8 U9 `( i. h/ n ret7 j) J) q) `7 A, [) l- A8 t! T, d
real_mode ENDP, z4 Y3 A* }; g# c" \. \
;------------------------------------------------------------------------------------------------
7 ]3 {6 x; V4 n8 x7 ]Get_Commandtail PROC near
W4 L4 d$ G' Z- y$ S ?- u& y push es
# N9 L/ F5 V8 Y7 O2 d8 D' N4 J pusha
' y9 C! X' ^: d3 j6 } mov ah,62h ; p0 D) T% ~6 ~; y; t9 w
int 21h/ y/ G K1 k0 X. x* e% A1 j5 V
mov es,bx
. l! @2 G+ T7 F, @& G# R4 d( X9 ]3 T popa 5 x0 g6 S; |0 O% K, N% e3 ]
pop es
, q( E5 B4 a& s) f" v3 W9 { ret
0 b6 H) N7 X1 z. y* f. P: xGet_Commandtail ENDP o$ n: u5 J+ _& d% `
;------------------------------------------------------------------------------------------------/ k0 K8 h* P* ]4 B: V5 O) ?
PSP proc near! |4 {3 B A* A! i& ]' k' G
mov ah,62h
1 Z- U! E: B6 p. o) P int 21h
0 G; Q1 f4 [4 B4 J mov es,bx
1 h: H7 p: f3 H! G xor ebx,ebx
) t* t, o; R# m- R mov si,82h6 D. M9 N3 y: y
mov al,es:[si]) v6 l! B: \ F" }, v9 v$ ^! Q
call Change
2 I% }, x1 O5 X! `$ V5 n9 g* X4 M0 N mov cl,4* |+ |, _6 ]1 S( @9 ]0 j. k: H7 J
shl ebx,cl
4 x/ ^$ Z* a- _4 x* G5 O3 o add ebx,eax
5 D2 j% Z& r g7 L4 y( H1 G mov al,es:[si+1]
; w) q, I9 i# w! k call Change
! |2 ~' q# L% v mov cl,4; n! `4 `$ I" W" z* G' ^9 J' J) D
shl ebx,cl
, _/ b! b8 U& @3 u7 ?0 E; P add ebx,eax; q9 H9 d! h5 i* Y- I' S1 O
mov al,es:[si+2]9 f% r; V. j/ s
call Change
$ w& [7 D! g r q mov cl,4
+ {" W# ?# R m& J5 ~ shl ebx,cl. M# V' A2 A0 ?; l& Y1 v9 D
add ebx,eax
) e5 X) P' ^$ c" ` mov al,es:[si+3]6 r5 |' E1 p5 O H+ y4 m( _
call Change2 K% k% |' B3 A) y! S. F7 r
mov cl,4. A" _- x+ D3 g
shl ebx,cl
& [6 O8 Z ~2 `* G% x6 ] add ebx,eax3 w. C7 y/ f0 [# r$ M0 @
mov al,es:[si+4]$ H2 A5 U H- X6 ?" n5 I1 g
call Change( v' x! A; R, F, X) B
mov cl,4: ?' {; [7 E# Z8 U9 J# c+ P# r
shl ebx,cl0 N3 E* U8 I- k7 \0 C8 ~
add ebx,eax$ D+ J3 R4 Q' C# y4 j
mov al,es:[si+5]& H* I9 _2 B! R1 W2 ?( J3 Q
call Change
2 j) H$ v7 {* s( \4 z _1 F; g mov cl,4
* M2 C) h9 A* C' v6 Z' A shl ebx,cl- m1 X7 X- I' T, w/ H
add ebx,eax
# J' t" [) E5 s5 J3 g mov al,es:[si+6]
( i; z" S: [0 b4 W' n7 c call Change; F. N1 L$ T5 `% w0 e; t# ]: n
mov cl,4+ c z( G/ T& ^: a' t
shl ebx,cl% K8 I; a$ x& j3 H
add ebx,eax
2 Z! F: d l# G* b# }2 J8 r6 \ mov al,es:[si+7]3 ^5 d; ?. f/ _ R3 c6 p- ? P
call Change% F! H: P) Q4 _1 f" a5 Q3 |
mov cl,4
) z6 a7 d+ o/ K& I+ y) D shl ebx,cl* P: z P6 A8 j; i
add ebx,eax
" n+ d, B7 z( n0 O9 ^ ret
$ R7 g2 O0 U: ~- U* D- Q2 @PSP endp
! i- ]# \# H, P& s e; J;------------------------------------------------------------------------------------------------
2 J4 t. z: E- T# h: C/ a6 k a' \Change proc near" y! K9 ]0 s5 L4 X K1 ]1 @
A:
2 {# t' ]+ |5 S1 v5 i movzx eax,al- I0 ^# c3 ]! m
mov edx,eax
M) @; _" D% Y7 F' v5 M$ O cmp eax,'0'
$ O/ r0 z7 v8 n. W0 G' f' j8 z" a jb A/ l% Y0 \$ A+ r: `. R
cmp eax,'9' 2 D9 m9 M1 _ _0 d* B
ja B& Y- L z( j- R. _4 O
sub eax,'0'& S9 B* w% o/ U7 l: N4 @3 Y) T
jmp short E( m* `- ~' O) N
B:" B9 f2 {! h& b5 t1 F+ l. W
and eax,0dfh
! k% `/ ~% [, x8 v5 F mov edx,eax* N5 [: M1 ~7 ]" A5 X. b
sub eax,37h
+ y% X p, x( ?; K1 V: [9 y, J cmp eax,0ah; [: }& q* U* g( ^9 R3 V
jb A " ^( \6 w( t* X. N8 v% u+ R
cmp eax,0fh
: t q* q: N: G1 H* g6 y6 b0 [ l5 P ja A
! h) ~' L1 t& `' s6 \- r0 B+ M. _+ vE:* y" a4 R+ Y+ I7 G
push eax
* [+ ?) b; |' N) k* \1 V) i/ E call PRT F) |, K1 y* ]/ a( E$ O/ R
pop eax& L# W3 ]* n/ u2 d) {
CExit:7 U2 J8 ~) @* k+ @" g. p/ K6 l; ?
ret
" J6 S/ z! a6 m3 xChange endp
8 b2 `4 ^0 u3 F) q/ @; M) Q# N1 g;------------------------------------------------------------------------------------------------: G1 Q- E* k% e
PRT proc near/ n7 ~# m$ F* e! l! c% }9 @' O
mov ah,02h
4 }$ B8 p% i6 b* Z. g int 21h
) ~' A+ v) M- E. E8 J. e I. p ret% H6 F8 L# b2 ?8 s) U
PRT endp
" ]: I" @2 X3 c/ j; [! ]* t A;------------------------------------------------------------------------------------------------
4 d8 t W* }! m2 }4 a' wcrlf proc near) p* p j+ j3 F' t
mov ah,02h$ L3 t' o" p1 i. g- {/ m
mov dl,0dh$ V" J, n. ?8 o4 d
int 21h' S, @8 s2 o5 T& J9 i* u
mov ah,02h
; r0 u m S& Z8 S! F# H; s% {( M mov dl,0ah
" p0 _% m& z+ [; @' _ int 21h
8 P! a6 a- |* F l. e4 F ret
8 M" H- [% X- S. g, e/ ccrlf endp; R+ ~' b: ]$ b5 W
;------------------------------------------------------------------------------------------------) i* V1 ^7 ` {' Q1 A* A- i2 k+ J0 }
_32bits proc near
( @/ W# o6 B3 L+ g' X( y- [" Z pushad' F- j- c( K6 L
mov cl,47 O; \+ O! V0 i! L+ r
rol ebx,cl
6 Q* ]: n) s( ^- v- Q call print_4_bits& L/ l/ B9 d" q
rol ebx,cl: S9 a; U' S9 z6 t% T* x
call print_4_bits
1 s" Y- V# `9 x* X+ l! T+ ~ rol ebx,cl
0 @. x. o" E# @' Q2 E5 v: X7 z call print_4_bits
$ d% f" P7 w M rol ebx,cl
( @ M6 b* ]' s call print_4_bits
! u. N3 v" P$ R3 W! V/ c rol ebx,cl( D; w7 I M- n( _& p" ^1 I; @
call print_4_bits$ ]7 v4 A: K$ W
rol ebx,cl
5 @' L/ V O) ^& J* K2 | call print_4_bits, S9 X# b5 t# V& L
rol ebx,cl N. L8 ~) z) E7 s/ o
call print_4_bits0 Z2 Q8 n/ Q3 D3 P* K
rol ebx,cl
7 f; A& m. T& c0 ^& D. R4 V5 R call print_4_bits0 Q! d$ d5 [/ ?0 H, o
rol ebx,cl
, c7 m/ H3 q& S( } popad1 r0 {( N. D& C) k6 x& |. P8 k
ret' B5 y( I' X( \& _& U4 y& g. x/ ]- ]
_32bits endp
7 L( X9 H, n/ b! ]' e) o;------------------------------------------------------------------------------------------------
" `$ t: O3 c- \# T `3 h_16bits proc near) I& Q7 J* c$ D2 c) C \' n
pusha
, A5 K w6 _( R" L/ W rol bx,cl& k$ h% @% x) T1 x% u& X
call print_4_bits# X) ^5 ~6 f. A3 X \! u
rol bx,cl$ w `1 P& X( Z( Q
call print_4_bits
0 j& A% }, P e6 S! k) S rol bx,cl& ~. I( R, C9 H p+ b$ x
call print_4_bits
# p; t. {- w; d8 s rol bx,cl/ P" l+ G b+ q! q" y# Q* y
call print_4_bits. Z* W( P7 d7 F$ v6 M
popa7 ?0 _8 X4 w$ k6 Q8 ]
ret
/ a- R) f+ F. F0 I- b2 {_16bits endp1 c" l9 e+ Q( _8 y4 S( z/ A5 T5 B
;------------------------------------------------------------------------------------------------- y. F0 h' k& y7 m
_8bits proc near) ~4 L1 ]8 R ?3 K/ v
pusha
$ T, i! v/ Q2 s9 b rol bx,cl! M; T1 q! U8 u6 [7 \
call print_4_bits
k+ y4 S( x* ^# ^0 q rol bx,cl
+ q: \ l; v q$ k' w; N. h B4 d call print_4_bits
$ ~; L. Q( P/ L' B6 l! G popa
$ g$ b1 a- @0 B7 w. W. q0 k4 t ret" G4 _6 h# E" [4 U, a9 Y$ s6 l& A
_8bits endp
) M- }( y* G$ N;------------------------------------------------------------------------------------------------
; Z4 w7 U3 I$ Y m2 hprint_4_bits proc near
, b2 F' T* |6 u8 f6 p; f) }% M; n mov dx,bx
0 x. u7 F/ M: u and dl,0fh
. L% c% v+ m k1 Z. @* C add dl,30h/ i! L/ w4 a- P% R( ?' ^
cmp dl,3ah0 D' J. j; v# C }1 K9 l0 L6 f
jb print
/ a- J9 r6 a2 @& b add dl,7: `% \9 H, v/ j& s: }" E
print:
% `5 o1 _9 b/ j) f, \" L mov ah,25 \6 `, K+ [3 z0 W7 B3 B% o; \3 \
int 21h2 e6 v2 a$ b' ]/ J0 d) _4 T( @
ret" h+ B6 j0 b$ O2 O& X2 [
print_4_bits endp
2 d. |+ O1 l) r- G;------------------------------------------------------------------------------------------------) o1 W, Y' G1 n7 j8 g% c
CSEG ends# }9 j5 W X q: f4 K! D6 y$ A6 Q
END |
|