|
|
各位前輩好,以下的程式為在 big_real_mode 讀取記憶體的值% r9 X8 E4 ]5 ^) T% |
8 F/ d1 o) p) G) w( a9 K, a' c* t
例如: C:\memory.exe(程式檔名) 01000100(Address)
d$ g* V7 g9 X; J2 ?" F1 _# \
' y0 f9 S; h9 }則會顯示01000100位置的值, [7 K/ n! }% k8 D1 Y
4 P3 u5 F/ Z4 u. J0 u; E& O
但是我另外還有要顯示出字串,但是顯示出來都是亂碼
3 q2 A% _4 O. P, w6 t
& a. [ q$ O$ X麻煩前輩給我一些指導,謝謝
) }* [8 v" ]0 j6 |
0 \. w* }9 U5 x+ Q; o- ^3 C" t5 u1 s! b% D8 t Q4 a. ^
.model small j) j( w; U( Y0 Z# C1 \
.386p' N" h: l! X$ J& d7 L* y
;------------------------------------------------------------------------------------------------ P- d# f9 s. F9 W; Y
DSEG SEGMENT USE16'data' 1 |" ^ t2 J% n B n
% {3 I- o, n$ [' F
DESC STRUC6 T2 l/ n+ L$ O, ]* ], m6 q/ c
LimitL DW 0
+ e% V( O* h9 A% \% k, j2 G) Y BaseL DW 0
( w8 Z5 f; k* J% H6 @ BaseM DB 0
3 W/ f1 L9 T; X( Y Attributes DB 0
" J/ _4 j$ d7 }2 D/ j3 l) H! R2 K LimitH DB 0 5 Q; w1 m; v8 Z
BaseH DB 0 % R" k g) v$ N* e8 N$ n
DESC ENDS2 z. n2 z- |, n+ S
6 H9 X4 v0 i4 C: I, O5 @6 L( h; BPDesc STRUC% G9 `4 ~; r4 N& _
Limit DW 0 7 h5 Y/ ]0 K# j5 u2 y" ?
Base DD 0
( n% }# @1 ]1 Q- L1 |$ i% uPDesc ENDS4 G" ^2 a- t# d# |
7 L* A; H6 d" ~! M& @2 xGDT_def Label Fword
9 }+ v, ]0 B8 v# ANull_Desc DESC < 0h, 0h, 00h, 00h, 000h, 0> P9 g% B% I; }6 G, Y k7 U8 ?' E
Data_Desc DESC < 0FFFFh, 0h, 00h, 92h, 0CFh, 0>4 E9 _# A; X8 e+ f1 S" d
GDT_Addr PDesc <$-GDT_def-1, >/ y+ h. L. o3 L* O9 |# K7 A6 k6 ^0 w
. y0 p i7 Z" C5 a+ kmsg1 BYTE 'The Input Address is '
+ | Y, @) [1 [/ G" {% z! emsg2 BYTE 'The Data is:','$'" X5 c8 k s- _( M9 ^7 e1 o
# Y& K$ Y: T" V$ w8 ~3 W7 y1 e1 BDSEG ENDS0 f. Y# O/ g* p( V8 C* W) u
8 D* j- p" s# N F( a3 e" L% j \
7 N7 @1 h1 T% l% e, S
;------------------------------------------------------------------------------------------------ + X& z- J7 b! u: U+ Q5 I: K2 U
9 \9 W' _, l: ?( w2 p# f9 D7 d
ASSUME CS:CSEG,DS SEG
, `. |9 I6 P. J L" N5 Q
7 `1 p0 l8 k2 x7 E9 ?% v* vCSEG SEGMENT USE16'code'# {% R9 s6 D* o9 k! H5 }
) j- P& r+ z- f$ U- { push ds
1 U. H7 Y7 `# \ I$ D0 @1 C push es
0 Y0 I) T5 u- u2 y6 @ push fs( [: t+ l. E& T6 j" e
push gs R6 _; H( ~: S; x, N8 j0 O
% k6 x; \) }# h% n call big_real_mode6 H8 O* L3 V0 Z. n, c) c
1 t7 R% g3 x1 _' q5 \
& [" e; w; U" @- k1 {+ \4 O mov edx,OFFSET msg1;, l$ }8 W8 e- V* Z- ?/ n6 o& D% H
mov ah,09h;
! T5 }6 e& ]$ | ^9 v6 E9 L int 21h;
' y# i9 F* `' [ mov edx,OFFSET msg2;0 [: d4 p- G4 W( X& M
mov ah,09h;
+ U r# p7 m2 h8 A( ~: z/ ~ int 21h; k% {# P7 N& k6 m0 b- _
; y) Q0 u l0 R5 X4 n
call PSP 7 o& i3 x) h- g$ ?
1 i' F* d5 w8 ? call crlf
$ }; D* h( p6 Z$ b/ f! _9 v % [- q8 @% y$ D& w
mov esi,ebx
; a6 k j# B. O3 k, H2 m mov eax,fs:[esi]& P: B: p, q1 a7 V, |
out 80h,eax
) a: t3 M1 B) ]: p& j- p& z mov ebx,eax
# W, }( d5 J! h C! m5 c call _8bits4 D6 v1 p- F4 t- f" R
! ^$ _. ~2 a6 j3 W9 A
call real_mode
) {) L' J) @ Q. l$ V# g8 l
- ]& i4 A5 \5 ?+ Q pop gs
- m/ \# L3 G; {/ M% @: q pop fs
# I) p, p. D) G' U* w9 ?3 R pop es
8 \4 O, n( `7 p6 L5 N pop ds0 z7 [ a2 M; X0 k; K5 e
% J& W/ o9 D3 ?3 ^2 r& f .exit
7 Q, ?2 P) `& J) {. L9 }3 w;------------------------------------------------------------------------------------------------2 ?* B0 M/ A9 s7 h& W
big_real_mode proc near$ C$ a5 R# @, u3 O: s ^
in al, 92h' y" ?2 f3 w# I1 \$ N6 [
or al, 002
* P, D) x& O! W, q out 092h, al& y5 t0 `0 H+ F5 [
out 0edh, al
9 l) P1 l' M0 h cli/ U! i# |1 C# a: W
mov eax,DSEG
w% B; {6 [# h8 n) S$ Q$ l- l2 ?. k shl eax, 4
# l" x) N$ g0 ?# _ xor ebx, ebx, H% k" _, m; I+ G# ^) M; f
mov ebx, offset GDT_def( d' m. a; G- b- Y3 w# {, o0 ?
add eax, ebx8 Y7 C# j( R4 D! D( w" n: J( R
mov dword ptr GDT_Addr.Base, eax6 c% [5 J# T b; F" D$ [
lgdt fword ptr GDT_Addr( ^. Q% M. c$ [
mov bx, 8
, J* H$ V7 U; @% Q7 J mov eax, cr00 E9 x4 ?7 {1 O7 _* h, f; a8 l2 _6 R
or al, 1
4 B L7 R) n# |( X mov cr0, eax0 e; {, K& F5 t8 h4 _
jmp PMod
7 t# d# i d) z8 v: @; F! @. Z/ _PMod:
\1 K) y* w) H mov fs, bx% J O9 p7 D6 x$ K* B: E* b' k* c) }
mov gs, bx/ S5 C/ Q' q. \: T. N- n, G
mov eax,cr0$ c) ~! H. T. c
and al, 0FEh
! }2 u" B& `- A mov cr0, eax
8 c7 m4 p! O; L- `$ l6 j, x# Q. } jmp RMod" [* b) B, {+ m/ c$ C! R
RMod:
4 Y" m( W) I5 ~$ K# N* B3 b0 l xor ax, ax
' o% j8 J$ {. r# _/ b mov fs, ax" Z; B1 ]* }4 o# ^( X
mov gs, ax
+ C8 n6 Y7 @4 ^+ l : I3 Z9 l2 W1 \% ~6 e) t6 O
sti2 ^5 W9 X4 T+ y/ s/ k
1 D& d2 a. N) i& i: e. o5 L! ]
ret
# ~9 B- V$ n a% {3 h! W: s, }! D6 pbig_real_mode ENDP9 N J O) ^+ q: j
;------------------------------------------------------------------------------------------------1 e3 \. S/ D* Y/ L
real_mode proc near6 [- W% F# g2 F/ T; F
in al, 92h
$ K- Q$ F$ b) O" I/ S; ] and al, 02
- n. E8 @ l! B; k8 @- l out 92h, al
. f( \% E! ^8 o0 t ret+ X6 U% T5 V& u! l* ]& C
real_mode ENDP% u7 d+ p3 f" X: S$ ?' s4 s- r
;------------------------------------------------------------------------------------------------
: \. M" f( q& I% ?2 ^Get_Commandtail PROC near8 ~, @, \ L6 `
push es 3 [) W& h, o6 x. }! |
pusha
( N f( x# V' ? mov ah,62h + B" I2 f7 F2 M' V; ~' F
int 21h& u# c5 j1 q- v. d& ]
mov es,bx6 e2 o5 W; W0 ?# ^' f C; \2 G6 b
popa
3 o2 C; k9 q. g$ N9 k" e4 R0 X* U pop es3 h9 H/ x' k. v8 d2 S; l
ret- m) z9 y6 k$ \ q O1 T
Get_Commandtail ENDP. w8 ^9 }# T# ?3 t9 c6 `1 K
;------------------------------------------------------------------------------------------------
4 @. s3 n+ P8 N+ O) r6 sPSP proc near7 i5 ]2 _" Z0 M7 {
mov ah,62h
?4 g% P; m7 d. W4 [0 f int 21h
* A& `6 [6 ~! b% Q mov es,bx
# S5 W8 Z. r3 T; n; _2 Q xor ebx,ebx y" O" \9 J, f! K T2 g* r
mov si,82h& {1 c2 L0 g4 S5 i) A
mov al,es:[si]! I4 m& p- W/ H, Y
call Change7 o ?* I) @) L& Q
mov cl,4. S1 ~; | o% U
shl ebx,cl8 C, ]6 t% \/ \: J8 D& f
add ebx,eax$ B8 P& [1 ]' l2 O* t$ Z; N
mov al,es:[si+1]
3 d8 o5 L& O! x call Change
) K- M z4 m3 y mov cl,4+ e L! H6 B. S- Z$ B! s
shl ebx,cl4 ?8 m; J% R" T, t1 C
add ebx,eax
4 g1 C/ n' @7 _. u% \ mov al,es:[si+2]
, k% s% N/ \+ ~0 W" v9 }9 | call Change2 Z% d1 _* q1 a+ w
mov cl,4! B9 d* [" |: n1 ^. e0 F0 J
shl ebx,cl
$ W* r. \4 }3 Q2 g# w; S# m: X add ebx,eax
2 Z: s! u! I7 |! l mov al,es:[si+3]$ e7 b! K8 K% n! ?/ q3 ^
call Change: y0 O& G; h4 v8 I1 D7 h
mov cl,43 H" p1 k. f. x# c7 D2 i9 D
shl ebx,cl
6 ^ b7 ]* f, Y. i8 K add ebx,eax3 I; r% B( v7 s2 Z% c
mov al,es:[si+4]
7 [0 y" n4 W/ t) g call Change
# R+ t8 B6 \ O$ Y% E" E7 i mov cl,44 e0 n0 f/ F, u. m$ E- {
shl ebx,cl
; ?0 o( c+ u+ [* @$ E add ebx,eax' b. W4 T8 a0 g, C
mov al,es:[si+5]
0 w. y, k& U6 P# p call Change
M3 u0 G8 N! ?+ y mov cl,4; J8 m" d) h* B" K
shl ebx,cl2 q! |8 m0 T: w: v5 I2 Z/ i
add ebx,eax8 N* \ U0 T' ~& y' t/ y1 H7 D- P A6 d
mov al,es:[si+6]$ @; u$ p! d! y+ q0 [" F1 ^3 X4 }
call Change
3 \0 }; u5 g6 `( H mov cl,47 s1 N4 J5 U1 t; r5 u; C
shl ebx,cl
1 n# o+ X; E8 S! C9 d add ebx,eax
2 V$ o, f( y% f# x# A mov al,es:[si+7]
4 }- R% U J: m; S. L! { call Change
9 W" o5 [' A" G! h mov cl,4
0 D! l8 L3 H8 ~, t$ F$ ~$ C) `/ ^ shl ebx,cl: M4 u8 s1 }# }5 V0 F
add ebx,eax
. L7 o+ d! \* U; \! Z2 h ret
% H; t: p; L: |' SPSP endp* }( z! t7 Z- u* w2 b6 D. F0 I
;------------------------------------------------------------------------------------------------
* j1 |! m# S" | U( V$ l' E! lChange proc near
% r; }. h; B: W/ [A:
; B/ N3 K' _4 B& h movzx eax,al
' W p Q; J Q! h. J ~9 i mov edx,eax
E* J' M; H( x: c% r cmp eax,'0'
( O9 x1 H- |- F4 L. b jb A
4 N& I: U/ Z# z r cmp eax,'9' - U6 v8 R) S. t4 |2 }# P
ja B
) ]; {8 b) H% K' i sub eax,'0'3 ~! ~- e8 A3 a9 s) ^, n6 O* J
jmp short E9 R8 A6 S s \. D, k. a
B:
; p% z; C9 I, s9 h" v/ H9 D and eax,0dfh ( O2 C' Y" `0 v( h8 t$ f0 R
mov edx,eax/ K! p4 r% L, ]! a' w
sub eax,37h
# x8 a% N- X0 m! L8 C, r cmp eax,0ah
" w' K. b; }/ ~/ X9 w; a jb A
6 @: l0 E3 @0 d! w" i) L cmp eax,0fh( D6 ^9 ]/ b) M' v# c' q
ja A
7 h# X8 l, W" J- @E: {: J) l7 k5 s7 m7 M1 m
push eax 3 @' C' \ Q$ z; \! Y$ v
call PRT & T: M" p3 I5 o; P; J
pop eax
6 n7 N4 c% U# SCExit:
/ F' W3 Z, x! h j% R9 f, @ ret
$ w1 L, b& P! Z' OChange endp( z# X+ V6 W4 }- V; G: s( M
;------------------------------------------------------------------------------------------------6 z% ?$ \$ x* J# D) A( Y$ U# r
PRT proc near5 M Z! O; H) A) I
mov ah,02h
; T. W& A C% M: G int 21h
5 Z9 U" Z* }$ Y0 o5 H1 b; D! I0 M ret ^& c: z4 Y$ n. Q3 l; P% S
PRT endp& p4 C8 \' F0 ?
;------------------------------------------------------------------------------------------------& k, o) ]6 m& b. t# _( o/ F+ i
crlf proc near3 q4 |" R ^* t) v
mov ah,02h
2 O/ S. Z8 }8 q: j2 P& B mov dl,0dh3 s6 f. o( X# H( `7 O( F2 V: m" w
int 21h
. U/ M* K8 N0 C6 V0 D! |( G* u mov ah,02h0 D" ?+ _+ x8 b2 m
mov dl,0ah9 t; ~# a/ H6 U7 G% K# V' B: p6 u
int 21h1 M3 r. B7 u3 X n, U( I, g
ret
8 F. e8 J L' A1 v3 q$ B0 x% Rcrlf endp
* c8 n) Q+ N T N;------------------------------------------------------------------------------------------------* c. u3 I' R, r
_32bits proc near
0 ^! j- U4 _+ p- w A4 t8 q! F) j pushad! q5 Y: L- L1 @+ Z. ~- {* W8 f: G
mov cl,4
" e. o' @( h/ I rol ebx,cl+ |: ^3 l- c* z- c! x3 g' C" `, I. p
call print_4_bits1 @/ g6 S/ S, x+ `0 w
rol ebx,cl
3 k2 Y1 o7 B3 J call print_4_bits
% u6 G% |" O. q0 ^, p rol ebx,cl
: q2 i2 Q5 I8 F {0 _6 r call print_4_bits" b3 j- X, n& {+ l. `3 S! a I) F
rol ebx,cl# q% N! g5 D+ X. y5 a' B
call print_4_bits
# Q: `& h2 N: { rol ebx,cl
0 {' y g" `9 j1 @3 S call print_4_bits$ V1 x* L5 k9 n8 h. O
rol ebx,cl2 C4 {! p8 D9 o n4 Y8 l) i Z3 j
call print_4_bits
5 D; t% @; r: _ B rol ebx,cl* Z- v( ^. A7 Q6 J5 I/ D+ W
call print_4_bits( c) k7 j2 c& p! B8 ?
rol ebx,cl
% H8 K& J4 J% K- n. m* J) L/ y6 z call print_4_bits& {+ U. h6 M- Y, R
rol ebx,cl
7 F+ q2 d1 b8 `( t2 Z3 p3 N popad
! c9 F, w- F) ~ ret& m6 Q0 N) |* |7 G2 S- J6 _8 E
_32bits endp$ N( d+ a5 B# N
;------------------------------------------------------------------------------------------------9 E* p! C, H2 {! l
_16bits proc near2 i: g& o n1 C( O% L
pusha " U5 F5 q& V3 L" \# ]" e, H
rol bx,cl
9 h% U1 P/ B# z5 n- p: `' x call print_4_bits1 P' ~& u3 q" N( ?: \$ i
rol bx,cl
& K6 a3 O; w7 \) s m! |5 C2 b call print_4_bits
) I6 z; i, n+ M* |7 g5 I1 O rol bx,cl* Z: r: g5 m- Z; x
call print_4_bits# a+ i& y( A/ M
rol bx,cl* Z( @7 v. b C& H g1 b# n7 @
call print_4_bits
: N2 X% k9 Z+ d popa
$ I/ \! v! o E' x1 G& j ret f5 F0 w6 b7 b' Z2 _
_16bits endp& ]' u3 {( e% G" g$ {/ m- D
;------------------------------------------------------------------------------------------------
9 I( i9 @% P2 {. F_8bits proc near7 m. e& t5 k8 N) X$ W. |; {
pusha 3 L" z: D1 f! D0 A7 a& ^' s& F
rol bx,cl8 ? l6 A5 g- ~* t+ `- O
call print_4_bits! @! q& M1 C; y& o3 E5 e
rol bx,cl. \0 p8 Q7 Y$ _6 Q$ x
call print_4_bits* e9 E4 `' t& z3 l
popa
3 Y s* }5 I; u j! W ret
i% x. ^8 x) j( Z1 M2 h_8bits endp
( E% ]/ R; n6 p- s% e;------------------------------------------------------------------------------------------------
2 u0 Q$ f$ R) k5 S) r6 e! }8 Tprint_4_bits proc near0 G. G$ ~0 g+ a
mov dx,bx
% k$ h% j% F. f( j and dl,0fh
8 ]( L& o/ N& T2 q( [ add dl,30h, }- x! B( E: Y3 Q2 h1 U
cmp dl,3ah( j, L9 E7 c$ \8 Y# }
jb print' ]/ X: S; e+ k* O6 I, o
add dl,7
! k. O( R. o, }9 F; g7 S; V' dprint: " \- P# J6 @# q+ p5 q' Y
mov ah,2 U7 T' O" u1 y. [# f
int 21h& n. O/ x( q( m/ N. [
ret# W' z1 L3 S5 T1 N4 O7 ]
print_4_bits endp
; F S) l d5 @% t G;------------------------------------------------------------------------------------------------6 o1 I; b5 H* I) [" k1 W9 B6 N! C
CSEG ends
3 T0 I- l% v B. ]! D. ?; Y! y& vEND |
|