|
各位前輩好,以下的程式為在 big_real_mode 讀取記憶體的值5 G& N0 I' z: O: f. j
6 n$ w# v6 \+ T: v- W1 X
例如: C:\memory.exe(程式檔名) 01000100(Address)
1 J$ x$ Z: d; I" C* V/ x
( i. t& H7 v7 ]* r$ I$ q則會顯示01000100位置的值
& t- M" Q$ m/ ?, x! B0 ?( O6 T8 E/ W0 _; H
但是我另外還有要顯示出字串,但是顯示出來都是亂碼
0 H" {1 X0 d3 V9 ?6 |% l. j- }* w' n/ X" y, M& K
麻煩前輩給我一些指導,謝謝 $ ?7 h; R; y$ K! Y
+ I+ z, Q9 v# R5 b% g4 r; n' q+ B0 v0 V- \/ T
.model small) Z8 f% N% [, E$ x* n
.386p { K& w' k+ D& g+ B$ P# J
;------------------------------------------------------------------------------------------------
$ S/ G5 l- Q6 a) C7 c5 iDSEG SEGMENT USE16'data'
7 ^% x. Q( @; P# X% M+ L* ?) X; h; m O" \8 `' N
DESC STRUC
3 i+ j( s2 _6 l. x/ Y$ t LimitL DW 0
* T3 e, k! q) ~ BaseL DW 0
9 |+ m" x; [0 t$ k& n/ @ BaseM DB 0
7 ?8 q/ G$ k1 x7 `, E Attributes DB 0
) f( ^; s% @% M/ n1 L6 F" \2 b& V0 P LimitH DB 0 & s- F0 i3 [# \% N9 R% M+ I5 ] `
BaseH DB 0
. X8 |" s6 _: `. P2 V3 j# HDESC ENDS
/ P6 v) [ A2 M4 H* H/ P/ G8 f `, U. m$ w. [" S
PDesc STRUC
3 a! p. g7 @- U. b4 I1 @ ] Limit DW 0 7 D2 m" C' i! F9 c2 `! O! O Y7 t
Base DD 0
: t; v; x9 f% K) VPDesc ENDS$ ?, R. j3 f9 i' M, q" T$ e. H+ J" K, n
% x! ^4 T+ H1 a, _' jGDT_def Label Fword
+ t! a6 b) J g& k. x% I9 UNull_Desc DESC < 0h, 0h, 00h, 00h, 000h, 0>1 Z2 K/ r( r2 p
Data_Desc DESC < 0FFFFh, 0h, 00h, 92h, 0CFh, 0>
# m9 D5 n: C o3 |GDT_Addr PDesc <$-GDT_def-1, >7 V8 G7 ]0 E$ ]% F1 o9 z: r! E3 v9 i
K, \/ T. T( F& V9 @
msg1 BYTE 'The Input Address is'
) M# N* H" H9 z. N6 Omsg2 BYTE 'The Data is:','$'
; b0 g$ l* E& e2 d' k* @, Y( I; Z' J0 ~! Y: X: N1 ^' O5 T# m9 A/ _
DSEG ENDS$ L! b$ ]0 i7 |% q1 a
) C: X+ y, \! y0 I
7 i/ t) n: ]5 C% z8 o7 O$ k& r;------------------------------------------------------------------------------------------------
3 X5 B- C4 h& r/ {' e# z1 ]& a/ D' W5 n: z9 C; R4 H
ASSUME CS:CSEG,DSSEG
2 X3 ^: w2 J2 K" E0 @( W
3 q3 o& C1 P$ f0 F3 N0 j3 DCSEG SEGMENT USE16'code'
$ R+ A6 o; i2 Y! H
, ^) H% u" q) W' [' u+ j push ds
% b( g4 l* F& Q5 U9 d6 }4 X9 C6 F$ D push es7 H* F) j: P1 M
push fs
4 Q" o# {# W$ z push gs
6 E5 F3 ]$ x( ^ s+ m! I' e7 L( K 1 B5 p) D$ K5 s; X; o& h
call big_real_mode& Y5 e2 K, ^1 D5 y7 @
! v' C# s% I$ F8 M$ f9 ^
. u/ A9 ]0 \% _( m2 r5 M/ x mov edx,OFFSET msg1;+ e# o% t& S* [2 k3 \
mov ah,09h;
, ]1 [- `7 i* l int 21h;3 A: t- x5 Y0 ~% t. |+ t7 b
mov edx,OFFSET msg2;
+ @0 w7 F% m) l5 q mov ah,09h;. {! G9 q9 c: x
int 21h;& i) T6 x5 i7 n5 M0 h4 x
3 J7 Z1 A9 L' B! }) C, W) R; {) g# [
call PSP
1 C7 E7 f! u- u5 I) X
% g8 E K/ v/ [) ^! e call crlf J2 T7 w. m. q
; t( f1 O/ i+ a4 f5 B2 } mov esi,ebx; k; W( d( a7 B1 [
mov eax,fs:[esi]
; \2 d# S$ F6 Y& D9 i out 80h,eax2 C8 I7 g5 I4 L
mov ebx,eax
+ `: w" C3 K8 t+ S! W call _8bits
# I9 I0 @( [1 }% @! X* G3 r0 ^
7 G8 A( X1 b+ b' ` call real_mode
* v, s: @; f9 j! t * c& m- K6 |% S& g3 m& g4 D8 j& }
pop gs
9 d7 _# P1 a4 D pop fs
( J' d) o" w5 j pop es
7 \4 c, ?9 o9 ^ pop ds$ Q/ K6 {3 l) c. K
. C4 a7 H3 u0 i3 w1 x* o .exit" X4 ?! o: r0 K
;------------------------------------------------------------------------------------------------
* _7 @6 T7 D% q" m$ T3 Obig_real_mode proc near
8 h' c! J! h( z' r: n# ] in al, 92h' G; V, u5 Z7 k2 o
or al, 0026 {8 C: T) U- w0 W; t
out 092h, al- }; h0 N/ F) e! ]5 K5 G
out 0edh, al" A9 H: z# t# l2 B! I9 ?0 _3 w- h: f
cli1 r. u: M7 L' E/ X
mov eax,DSEG
; ?* H6 @- h! L0 A8 A. A8 d shl eax, 41 @: G/ p. z2 w
xor ebx, ebx- y# s0 L0 E7 H; h
mov ebx, offset GDT_def; k, [4 E! [7 K$ V& ]* W" s( P
add eax, ebx
; J* R2 z4 g; L9 w1 f+ ] mov dword ptr GDT_Addr.Base, eax
0 @2 @, Y" s b9 C, ?. ^ lgdt fword ptr GDT_Addr
% c, ?" b+ q, k- e8 ? mov bx, 88 s& o9 q- b7 ?! c
mov eax, cr0- d l! q/ G# ?
or al, 1
( [6 \! ^# {! F# z. P, e6 [0 c) [, u- Q mov cr0, eax
2 ?. o, H2 t7 K- T h- L4 Y" d jmp PMod! w6 m, A* X0 O4 \' {, A. M
PMod:
5 Q$ V+ p7 d# m6 m- l6 j+ } mov fs, bx) k5 \. a8 w: w% G
mov gs, bx
" w) V1 F& X# z7 e9 R6 m1 j mov eax,cr0
7 x4 n$ b. ]/ d5 K0 g& Z" X& f and al, 0FEh% P" v( Z S9 b3 V
mov cr0, eax + E* i& r, g% f- F1 V
jmp RMod
$ B3 o' ?, m% a, i) l' P5 p; YRMod:
3 p6 `& q& {2 N& Z6 N( E xor ax, ax' Z2 @5 }( D0 l: W7 |3 a
mov fs, ax
# b9 Y' ^1 h) J; }) e1 b mov gs, ax
1 I" V: R6 k9 j( J$ V4 W
+ S$ ~# u. X, D% s5 p( [ sti- v, R/ T& u A; g. w6 s6 ~
$ B3 I0 ]6 s5 w7 ^" D ret7 r4 ?) A' [! F
big_real_mode ENDP- ]5 Q7 a K/ p: G; D& F& a+ {) E1 t; e
;------------------------------------------------------------------------------------------------9 @# a7 Y+ Y4 ~/ r) ~
real_mode proc near. E0 D; x2 e6 U& D6 m' S
in al, 92h
. x& G$ n5 @9 f$ d and al, 02
2 f* V$ @9 g- K1 y6 C6 Z1 n out 92h, al
5 l0 }$ `+ J: P- B2 C' X ret! s- U3 m: x& ?/ R. f
real_mode ENDP
; v( h" ~3 {8 O;------------------------------------------------------------------------------------------------, `9 n5 b1 Z/ t8 _6 C. P4 h
Get_Commandtail PROC near
6 m% P ^" E$ c, [- ^1 ]% J push es
9 { R% h K2 d c) z pusha
; ~6 |4 D+ w4 G4 |; t mov ah,62h : a8 [% Y2 g! w
int 21h
, I. ]: V' I6 \ mov es,bx
, a. F" o8 e) Y0 L& l7 w' o popa
7 l$ i6 ]- B6 M* i8 m pop es' v) n4 Q7 N, I6 @, m0 U
ret' X: i0 }) H4 s5 p
Get_Commandtail ENDP5 N& c" H5 }6 O5 N9 h
;------------------------------------------------------------------------------------------------$ M1 T, o8 }+ c& r2 M/ G( c
PSP proc near
m% w o# O6 z, H mov ah,62h; l. x) v9 U; H5 d( w m
int 21h4 Y$ N0 x; w, c- ?! I
mov es,bx
( {4 L% g2 D2 ~ xor ebx,ebx
/ N# C+ c; t4 |" e: G" U0 e# x' k mov si,82h6 w K& u9 {( m7 |' m$ q
mov al,es:[si]6 C4 l* Y# w- {6 ?5 V5 ]0 R3 u! ~
call Change
' J X( t2 \% V: V n mov cl,4
& l! z1 \7 A! f shl ebx,cl
: A$ Q/ r% F& U) p0 L- q5 R2 g0 | add ebx,eax
% j @& [) W+ B6 p% G* r/ ]* s mov al,es:[si+1]
) Y( y% m6 y* c. j& x8 ^( v! t call Change! Z9 P; C" l! ^$ K
mov cl,4
6 F0 T0 H+ O7 Z7 n% B1 ^4 N9 q* ` shl ebx,cl
/ S: j, u4 a& F$ } add ebx,eax
4 | C% J, i/ b# q# A mov al,es:[si+2]
2 \7 i, ^9 c' B" U% m- A! k call Change
, m" V0 B1 N$ K4 X, b4 h7 H mov cl,4
" m' h/ r- L; d' R" S8 Z shl ebx,cl
, Y2 G% z! J* O4 \" U* Z6 w) U add ebx,eax# W e3 b3 N/ i/ w
mov al,es:[si+3]$ [ J( e6 {8 }2 D j
call Change/ T+ n) h8 y9 m
mov cl,4
8 A: G8 y; D/ x9 B shl ebx,cl
- k3 S5 W: ]0 Q- I, l- f add ebx,eax
; \; r; F7 ^3 J: D" b: k3 L mov al,es:[si+4]7 j. p/ K& W/ Y
call Change, ~. e# T( X; c
mov cl,4
! x% W! B) b% }% F5 N shl ebx,cl- ^+ m# I- d0 E* Q3 [
add ebx,eax0 B8 g& i, D5 e" w: n6 J
mov al,es:[si+5]
. c1 l7 v/ D% L% F call Change
. @8 J& H. C0 i mov cl,4* w8 [! O, v5 q6 ^
shl ebx,cl
2 L7 l, j( [3 { add ebx,eax
3 `9 G/ U" @ d, `# w8 q mov al,es:[si+6]2 k& ^5 D4 b4 {# S+ d3 N' s
call Change
0 ?( }! c6 a1 o1 E+ ]) {' A" k mov cl,4
- `% H; |' Q) Z& o( }& I" m shl ebx,cl
: s) |1 s' @" L5 n$ J) _+ X' ~ add ebx,eax4 q' d4 X) M! f
mov al,es:[si+7]
, N1 P0 p; d# a: g call Change1 H2 |5 W8 ~, M4 @2 c6 H6 j! E n
mov cl,4- K+ X9 @% k6 k5 Y% J& R+ W
shl ebx,cl
' g+ s2 {8 i8 S e/ P0 P add ebx,eax8 @' U. u, j2 ^9 ?( V, s
ret
+ @" Q' ~8 v- B6 tPSP endp* w" {3 V8 r5 m- M1 d
;------------------------------------------------------------------------------------------------) z' [6 Z0 [5 P0 ^* _. c
Change proc near
& O* r; w4 ?8 [; q, q! B, ?6 MA:
" r4 k$ C" e5 O. b- Q movzx eax,al6 a$ j8 G% v1 a3 \
mov edx,eax2 j E+ h: o5 d1 y
cmp eax,'0'
9 f/ e" }" p+ G6 n' m3 U% _' n& S jb A
! N4 X4 P m4 { cmp eax,'9'
1 K3 i. p/ J/ W7 O/ {8 Y+ Z ja B
6 ~* q' e- e, b0 E% r sub eax,'0'
$ ?. F. P* \1 D. Y7 G2 } jmp short E b9 |2 w; `7 {2 ?+ S; s
B:( k6 Z) n, T" _
and eax,0dfh
! ?6 |3 [1 b$ A+ |! E mov edx,eax# E: ^" r, b. d' [4 ^
sub eax,37h 5 @0 Y6 V) n: E$ h
cmp eax,0ah5 W- N# U6 |2 M' H0 D' ]3 e1 c3 `
jb A ! c2 N/ r9 N M, L% y
cmp eax,0fh- v0 }+ l* G$ Q& y) D: q8 q
ja A 2 ], a9 x v) g$ l, o8 C/ r
E:4 f* g9 V0 T: {* f; B% R5 [; H e
push eax
$ ~6 w1 U7 j- v& h2 y8 H. B call PRT 6 M$ H( c5 C4 J
pop eax
1 }# S' F# X8 n u4 d; r4 qCExit:# l$ {2 b* E$ B- E4 @2 K% }7 T, T
ret5 x6 ^5 C+ R9 a4 r; O
Change endp+ }+ Q0 f2 J) d
;------------------------------------------------------------------------------------------------
2 k7 n- P h0 ?PRT proc near# k! ]8 f, I8 `
mov ah,02h
0 U/ `0 f" @& l' ?6 U& i int 21h
1 V) S! R4 N0 }% g ret
' p/ n* a- i+ d" g" ?# EPRT endp
7 y; @" f% C- ~. o$ U8 f7 I/ ~;------------------------------------------------------------------------------------------------. o: Z1 C# j: K: _$ e0 A
crlf proc near' x$ |3 |; m& c
mov ah,02h# t1 Q& }) P2 o H! H
mov dl,0dh* c- D; S; r: P. u8 g
int 21h
+ ^, q$ E$ |# G( D5 A- H+ ? mov ah,02h G2 W w2 }: G- z
mov dl,0ah: b( @# L& }$ ?# f' Y; z
int 21h
& G# j- p# l/ v1 m( G ret$ q+ F, k. Q% F2 i3 O/ n
crlf endp. S1 D+ [$ i$ i' H$ E
;------------------------------------------------------------------------------------------------
* {. ~' `3 t0 u2 X. N; N) E_32bits proc near
& \& I! U/ A2 l3 s pushad
$ k0 T/ F* j% C; R" h0 r mov cl,4- H+ L: `% o( P
rol ebx,cl
7 S" C! ]1 J1 u' c4 T3 g2 e. E call print_4_bits
3 |! }, o/ ]2 M, `$ p rol ebx,cl
: x; j; {+ ?2 b/ Z, W call print_4_bits
2 N- \" |6 q! q# H% `; M A! D rol ebx,cl9 h- z [/ _0 a5 x, s6 @) x
call print_4_bits- J5 ^& m; Y# `3 R; O
rol ebx,cl
+ a4 [$ @0 K; ?& N' U7 i8 Z3 T& y3 U call print_4_bits
1 O7 Z$ _& ~/ Q: K) i8 X8 i rol ebx,cl
8 |/ D2 T A( z7 ]8 g' t call print_4_bits
6 l6 q) N% I) v% A$ C# K1 i rol ebx,cl6 b1 Q$ q5 e. [
call print_4_bits- x0 H8 \- v! l; M% v% A* r1 R( A
rol ebx,cl- A, \$ P, b M6 F- t/ t* @* @
call print_4_bits
# W1 E% D2 V- [+ B& i; F rol ebx,cl9 M% w/ c# i9 b# y( @
call print_4_bits; o( R. p& W1 @' R1 M
rol ebx,cl
2 l* i) f! V* y8 f+ j& u popad6 O2 f2 x, {; _( g0 S- L* D f
ret
2 u* g( U5 [3 ]* d_32bits endp3 T, I9 R, H& U1 {0 u8 _( g2 A
;------------------------------------------------------------------------------------------------
- e( g3 Y: t: O! h_16bits proc near) v( A- L2 ]. Y- l9 ]
pusha
/ b: U2 S% f* R& A$ h# |; S7 f rol bx,cl8 r7 S' u" ?! V2 g. b% t) q: p+ R
call print_4_bits
: a3 D f0 O+ W3 M, x, m0 T, M rol bx,cl
9 m6 s$ u3 q: L3 | H/ I5 } call print_4_bits0 q; w6 V6 z; l- l1 a
rol bx,cl
" p: H. w6 s/ Y- z5 i& w$ L call print_4_bits, b( @/ \# a+ T1 ~! b/ }1 o
rol bx,cl; u. I1 ?6 R* X) J8 q* t5 h* Q
call print_4_bits
& }3 H p3 h1 i5 x: M! c6 K popa
) T M8 O$ ?7 l. T ret
c3 D( v: J' _6 |. v_16bits endp
3 @2 u* m' C! ^, m# ?;------------------------------------------------------------------------------------------------
' g0 r/ n' j" @" h& B$ C_8bits proc near
& g' ^. E, z, N3 y: R0 l; K pusha . D4 e3 R, T$ L
rol bx,cl
* n6 g. x3 d) w call print_4_bits. ^0 r# F7 x* Y) b7 e0 z5 k" Y
rol bx,cl
; Z/ t( y3 S7 Z6 \! B! M; G call print_4_bits$ j; {. E9 d) a
popa. E( `4 J; z1 ?1 s3 ^9 D2 y
ret+ T& K+ X4 v+ e7 f6 S' x: S
_8bits endp
: A$ ^: r2 j8 V9 g3 {. I/ |5 e;------------------------------------------------------------------------------------------------
. y; e) T) n4 ?print_4_bits proc near
; @& p/ l/ w9 r9 k" Y! [) t( _ mov dx,bx( h* F& Y! d' R2 n
and dl,0fh
( }6 N! |" C3 L1 T8 h add dl,30h
5 D9 E( A1 |% Q! Z( K( E6 N8 z4 ] cmp dl,3ah
: r P7 D% f$ {! S+ l6 C. H- R jb print
4 n% S! q, U3 ]% q add dl,7
( H0 g5 S; d& f* v* D, x( h2 J* nprint:
/ R, O' l2 N4 l$ }% R mov ah,2
r7 r" @3 _! x( M3 _+ `" c) O6 E int 21h, @# ]" N2 c5 l3 M* V9 k& s
ret
- M% @- s7 S+ z& |; x3 B6 E7 Dprint_4_bits endp
% P) X; d) r: n# ~" F;------------------------------------------------------------------------------------------------
4 F$ G, G' L" f5 L& yCSEG ends
2 {+ x1 m$ V6 b, w) d- CEND |
|