|
|
各位前輩好,以下的程式為在 big_real_mode 讀取記憶體的值& R+ d& k$ u6 q& P* w
7 t! X1 r+ Y3 a! B7 I8 E8 O- [例如: C:\memory.exe(程式檔名) 01000100(Address)+ L7 ^1 v3 s. N" m, g
$ t, T9 E" b# P# o2 _! B6 k則會顯示01000100位置的值: S8 K0 ~3 h! f! B; P3 y
7 d" s% D% i) v X7 v% l/ u- Y* \; R但是我另外還有要顯示出字串,但是顯示出來都是亂碼
" b& T9 l6 A; @# x' a
/ X+ S. v: H/ t+ t+ Y( \& G麻煩前輩給我一些指導,謝謝 . y0 x) U: X4 P. K; Y& y
' A' {! f0 E; Q% S
& d5 d6 w7 Y( H Q1 ~) [.model small& \% B7 e" c$ V/ O' d2 Z
.386p
5 n/ B* w3 @& \( d/ F5 I" D9 \;------------------------------------------------------------------------------------------------( ]! s& ]+ Q+ q1 ~( Q7 c7 M3 A$ }
DSEG SEGMENT USE16'data' : s$ G6 V: c2 g1 k8 A% y' D1 h
! m+ [# ]% H# l V, E
DESC STRUC
8 g& o$ Z* ]: N' K$ a0 b, J LimitL DW 0 , f$ H% d4 Y* p E
BaseL DW 0 9 r1 r# S9 X$ p& y' ~0 \: V
BaseM DB 0 ! }" a1 `) ]* }' \2 A
Attributes DB 0 4 v3 l2 b' B, ]. A9 b
LimitH DB 0
/ |+ D7 M+ Q7 ], Q BaseH DB 0
[5 A$ j% [" oDESC ENDS
+ ]3 |8 s7 |1 M
- |1 F5 i ^- s& X4 y/ n& n( tPDesc STRUC
* X) e* ]# D! r7 F4 C Limit DW 0 9 s1 `, e: |8 E! W2 A$ ]/ C0 |- F
Base DD 0 : N6 Q" b! R% l! Y
PDesc ENDS0 C1 p h t& F' [" g; c
3 Z% |/ ?, ^% ^# V& hGDT_def Label Fword V( W: t0 u% \+ J
Null_Desc DESC < 0h, 0h, 00h, 00h, 000h, 0>
2 I( M8 [8 D1 t; m8 P# t# E2 JData_Desc DESC < 0FFFFh, 0h, 00h, 92h, 0CFh, 0>
3 l& w- U+ [. wGDT_Addr PDesc <$-GDT_def-1, >
+ s E5 V' P+ M H. [) D' X
& ^) b+ J' ~; amsg1 BYTE 'The Input Address is '
+ Y7 I- p8 j, H2 C mmsg2 BYTE 'The Data is:','$'
+ y* O, N$ `; ?6 k
& J# Z" T6 L% v% A# I8 V0 R0 F% yDSEG ENDS/ F: B9 f5 F/ w$ _
* T1 m0 t' w, O! {+ e) p6 @! [
' L: Z! h+ T1 C
;------------------------------------------------------------------------------------------------ 1 j" V/ e$ B- p2 n
( C/ I# s+ |4 k7 I. f; h% \
ASSUME CS:CSEG,DS SEG
' z7 j+ U! ~9 L% P" V5 u, g5 Z
5 } O! r9 c: J! d2 J- m4 `: SCSEG SEGMENT USE16'code'4 u8 k% `2 }- h0 l0 w
) r# h j) o: ^& ?' M+ A. J push ds
% \. | I! ^/ p+ {& V' X5 Y push es
! J1 u/ K' j! D" k push fs
* Z0 ~" A; { ] N. X6 a push gs
" Q* `. d" J; Y7 n# M( d+ q" N 9 a3 A4 R0 \( g5 ~( J3 l, \
call big_real_mode
7 `4 v! C4 d6 @/ r
7 z3 c; e* x6 U- T/ D( w 8 D" }9 i- z' ]6 ? [/ |- M3 A
mov edx,OFFSET msg1;2 _- n' l+ K/ _% `0 u! J% J
mov ah,09h; ) {( }6 K) C+ r' V$ x* g
int 21h;
' z( S' B" R' I5 v$ m) h- o mov edx,OFFSET msg2;
" z$ M# [7 \8 D" I0 A! q mov ah,09h;
# [4 J3 [: Y( B3 e/ t- y int 21h;# E# x- h- @: G
& x' Z6 d! w I! b7 t$ C7 G# j' }, K
call PSP
4 \" D% l. f) A2 k3 P" C) _- G3 a
7 T0 c7 V- O! D& Q& @ call crlf
6 H8 k" J' `; d- i; A* X; d7 V
2 \2 v$ |# h* H* R4 M mov esi,ebx" |5 \; p4 O$ V2 @( r1 b/ y
mov eax,fs:[esi]9 s- l. G' X9 ?8 K( d( r, u
out 80h,eax$ J+ D( t0 b8 O) t1 V
mov ebx,eax
. M) d; K3 e! O( `: \( S3 U call _8bits) B4 @: x- ^! ?) }
" W* z: X- K# I2 o& _
call real_mode& ?% c/ t# W; D: x; ^
: G: c' ?) V5 u4 [. V pop gs! Y8 }$ ]/ u) d6 Z5 ~
pop fs
3 G* m6 n! i# H; _) H& Q' g4 Z: o pop es5 r* O/ W3 A# a! i1 U0 U) u
pop ds
' g: y6 N7 P+ ^ - i+ `8 H. x. `6 c' \4 ?7 o" b2 }
.exit
% z/ N1 G5 p: k;------------------------------------------------------------------------------------------------: U9 N0 W& {. t& S8 Q
big_real_mode proc near
+ ~2 {. h7 G, O# S9 x2 m in al, 92h+ Q# ?& a: W! p7 ?
or al, 002* Q( H- [8 k9 L: @' Z
out 092h, al
2 n& H3 u% l2 K& \- F% X0 f out 0edh, al
8 H* G6 V. j3 A& z/ t o7 L- T8 C cli
0 p4 v" d" v' d5 X8 X6 ^ mov eax,DSEG; q- @/ ]/ ~* G) E% A5 l
shl eax, 4' e6 O. W4 j! R% ~
xor ebx, ebx6 T w. d* ?3 i+ K* h
mov ebx, offset GDT_def
) [% ~' O/ n. |5 z- l' p. V3 x add eax, ebx4 h: R$ H& i: {5 P
mov dword ptr GDT_Addr.Base, eax8 A" ~4 m2 {9 t1 R
lgdt fword ptr GDT_Addr
. n7 _9 W" p6 C5 w* R2 j$ F mov bx, 89 b3 [) { g& `( A0 z
mov eax, cr0
. t( h! L1 c- v3 _# _ or al, 1
7 @0 B1 n# F2 d1 y5 X2 V mov cr0, eax& G# Q" l/ `9 m1 g( K9 _) N5 I
jmp PMod
: U4 ]; K) D/ G1 x3 ~PMod:% x; t" A) S& \8 ] Y# }+ R- G
mov fs, bx
2 W k9 W( H& _. d3 {" r' W mov gs, bx' j2 y. o9 c% c+ q# [2 O& i+ t
mov eax,cr0
; o1 u. {0 n9 ~ and al, 0FEh+ ]$ r% V$ B$ |
mov cr0, eax
( I$ H9 U# D0 A8 s; ^# c' z" F jmp RMod% [3 S ? v ]& t4 E4 V& {/ V
RMod:" z+ @+ X- o" Y
xor ax, ax7 A" y" T' f8 ?
mov fs, ax3 \! O: P9 U( X! t
mov gs, ax
5 N6 A0 Q6 `. `
% Y7 h9 M! c2 h, [ sti
4 J0 S1 i; [& y3 ]) r 3 ?8 q4 B6 u3 B
ret1 c; C8 X" v& i# {* s
big_real_mode ENDP
3 X5 N8 s5 |, c. R2 c) D;------------------------------------------------------------------------------------------------; P5 e2 O+ ~% t# D+ F$ V, K
real_mode proc near& P0 V# @( Z! e A6 q. m# z
in al, 92h
: |$ r% H1 x6 f$ V8 I' M and al, 02
$ p' M& ]1 M. @. J: _ out 92h, al " P' g7 ~0 n0 T' `' L% a
ret4 Y2 ?* U7 l, t: d8 W8 l5 s$ Y
real_mode ENDP- w4 `6 H" V1 H
;------------------------------------------------------------------------------------------------
5 ?9 y! A! h0 J3 U7 D c$ E( p+ bGet_Commandtail PROC near
4 s# o& R% c5 Y( t5 q( s, c6 o7 V push es " o+ L+ ?6 I% a0 r
pusha" h$ Y+ E3 p" j
mov ah,62h % P$ b0 @' E. ]1 P. _8 x8 M
int 21h
. z5 M* Z6 g: v4 E; G# h mov es,bx( x3 S4 s' I- i) I$ N
popa 2 P( c: D1 n+ b8 H& T9 }
pop es
$ H1 w& v' {& c: V3 Y; ^ ret
: c9 `4 T: Q; a/ N8 ]Get_Commandtail ENDP7 |) t7 c3 F( v
;------------------------------------------------------------------------------------------------
4 S$ u! s' R5 Y: p, P) @$ g$ ]+ yPSP proc near
. r* }* v* D" v/ I; i$ K5 F' ` mov ah,62h: a& V2 y3 }: z W6 J2 t* a, i
int 21h, y \' F% x& ~
mov es,bx 4 M% Z- n( k, P! M$ ?* ^, X1 t
xor ebx,ebx
0 c. G% y/ @7 Y/ g mov si,82h7 J+ ~4 V2 j' d* I
mov al,es:[si]' d- h7 N. Z$ H2 ~6 |, X( ^
call Change) l' `$ ?: t G S
mov cl,4
4 @; Z5 ?. Q# H0 H- R shl ebx,cl
1 {* O- G! Z% ^" U1 R add ebx,eax4 b! `/ H+ M2 Z5 R1 @3 o, c% b/ H
mov al,es:[si+1]
) Y& _* n' K) g8 F' r3 z call Change; I: p: n' x' c8 N, F$ e1 p
mov cl,4; u7 i) |0 c5 l" o
shl ebx,cl
( ~7 ]$ W6 C7 H: Z; t# V$ f' f add ebx,eax# `5 s0 U8 M' ]6 y' p* F
mov al,es:[si+2]
, L4 ^: x- h+ d/ ]% k call Change& `9 H$ [* U1 h
mov cl,4
% l' t0 T6 w$ B9 w8 i shl ebx,cl
" R9 p& B7 \+ u% X+ V# O add ebx,eax
/ y) V/ n! z* S6 | mov al,es:[si+3]
& b5 G" T3 c; p4 L. F call Change; A. [" {2 U( h5 q" }- c ^
mov cl,44 @$ h9 a: E: q7 e
shl ebx,cl) Z% _& \7 G3 Y7 t
add ebx,eax
+ I7 p# w9 J$ A+ x mov al,es:[si+4]
: P7 j# b+ c& F$ W% F call Change c. U* J' ]! D" x A3 S
mov cl,4
4 s! L0 F# s' k$ m- f8 [, ] shl ebx,cl
* Q) G# N. f1 q1 } add ebx,eax- ^/ H% G+ ^ z* G# S. |
mov al,es:[si+5]
% ]: A6 z* _$ P call Change
. y- l, Q; l7 \$ Y mov cl,4* p/ @, S3 @% O0 P) `
shl ebx,cl- O5 S X9 y6 H9 \! B
add ebx,eax4 h# |, F# T. y z- J0 \
mov al,es:[si+6]
( `! c5 c# _ b4 b/ G" F call Change
1 l0 y6 U* D a mov cl,4
/ W4 |7 |/ ^ t" _8 A shl ebx,cl* o* i0 f! N) m
add ebx,eax
( h {3 j# M( _) C' [7 A mov al,es:[si+7]
: m; x" T, Q. J& R( { call Change7 c" ~0 g) `6 J* h
mov cl,46 d, [! O. D) A# O
shl ebx,cl! c* s" b' f* M# S$ y& R
add ebx,eax
& U6 f& N. G$ n! c9 Z ret+ \ U2 Y- H* o. B `
PSP endp
( e4 e" Y) E- k7 @( R! c7 R;------------------------------------------------------------------------------------------------- M4 G1 H7 W( `2 A! b8 M
Change proc near! H. c" S) p" M) D' w4 g
A: 2 L' l- |/ x" [+ R. S0 N' }
movzx eax,al
# u- c; x( m$ k$ h a; U% @ mov edx,eax$ h# E, Y. R/ K' s4 _! M
cmp eax,'0' & U' y4 V1 H# E
jb A
# M. X9 v% N& p4 I cmp eax,'9'
5 w" o2 H, e2 K6 Q1 Y/ q ja B
* H/ p0 C1 P( S3 _3 f5 C& ` sub eax,'0'2 K h7 \: X/ [# ?* p$ M. {
jmp short E+ ?* Z$ m" g0 l$ ]5 X6 {7 I) a
B:
. h0 [& W) Z6 G: P1 b" ? j V and eax,0dfh
; d! ?* u% M; x: |, B6 g mov edx,eax
6 _! f. C; d4 _. Q sub eax,37h ) t. b/ A' R5 v6 h: C4 s+ ^: |
cmp eax,0ah Y _: ~; k5 p' G: L; ] W# P
jb A
3 V- h' Z/ D# r1 ]# ]4 Q cmp eax,0fh
# @& p3 j, q9 ^. _) o" R ja A ; m- b" h' r5 G' N: L- G; Y
E:$ L7 M- h) ]8 z9 y5 R9 Q! [
push eax 6 C( E% Q0 o5 s9 F' E' K
call PRT
! q! a: y* P+ s& b' K: J5 W% L pop eax
5 O: P: w* ]3 U: v- \( @CExit:
4 t% O& T9 @$ c, i. V$ G4 P1 ~ ret: C! S9 G* ]: V) K" c( w: L/ O+ g
Change endp
+ Y( Y% c2 [' @" P( T3 {;------------------------------------------------------------------------------------------------% }- ^/ y3 f" ~3 Z* d
PRT proc near x) m$ u/ r( b
mov ah,02h
) T- K1 Y" j$ S int 21h9 {/ Y0 u' q/ X1 p) H8 G% f
ret
6 v% U# A6 m- m8 u! n. ~ @! ^# IPRT endp
: m2 y! p! P$ J2 R( h;------------------------------------------------------------------------------------------------% }4 R6 G9 Y1 X$ y8 b, ]
crlf proc near
' L4 N' f; r- c% e mov ah,02h$ L. m2 n4 Z4 A' k
mov dl,0dh
! ?9 | B' c! D" `! @6 _) ^ int 21h: j" v3 D' P- y4 f u& q# o
mov ah,02h
% {% S7 F. U. Q* @' j6 q mov dl,0ah
8 T- e; {6 ?; @, c" w int 21h
) F' L: M. R8 ] ret
4 u r2 z2 m% a# K7 \7 Ocrlf endp
% @. u2 N% d! G6 u c;------------------------------------------------------------------------------------------------9 j/ U; x3 i) d8 M- \
_32bits proc near
) _2 C- N: E: |4 `. `- s, N pushad
, x- Z; u( L& v) Q- j4 i mov cl,4
7 P: L# I- H% j7 l6 R( @8 I: m rol ebx,cl
/ }. E- { N2 t& l; y- ] call print_4_bits
2 t" Z* Z! H6 B$ g rol ebx,cl
2 z6 ^6 C, z3 F4 P6 J call print_4_bits
$ b# Z* o4 j9 \4 w8 D rol ebx,cl; U1 M' {1 q3 X O! k1 Q5 Q' D
call print_4_bits5 c' y: Z: Z3 Y; z
rol ebx,cl. G1 B9 ?* w8 G9 h W
call print_4_bits
% l" V Z" J8 r7 M% H rol ebx,cl
$ J2 I$ x7 E" r; ]; o" h# J call print_4_bits! y7 w+ {9 T7 `( G7 s
rol ebx,cl7 e, V( T' K; j/ r; S
call print_4_bits
. A9 g/ e- N8 q4 u/ I rol ebx,cl. `, y8 s6 c3 E7 a2 B, s' B
call print_4_bits
( _8 v! ?' C, k" q1 L1 y7 m! Q rol ebx,cl) g4 H1 x8 z; ~( j$ v
call print_4_bits
2 \) ]1 U" u) Y* Q7 }- b4 U. e rol ebx,cl
! Q; Z& n. T- p7 N% C8 y" t" K8 V popad: D, e0 L( }" `1 g) O
ret1 Y& p5 C% s4 r3 l
_32bits endp
; M( v* T4 J! H" e3 k: F1 f, ^;------------------------------------------------------------------------------------------------
+ ? x1 G# U9 G3 i5 K) N3 e; x( j_16bits proc near
: M7 g9 N! ^, [/ {, S7 D pusha - a$ \# y% b, s J* a, v
rol bx,cl. t, n: P# Y! t' J! {7 v
call print_4_bits
) R6 z( g4 [# B# I: B6 F rol bx,cl
2 Z, d, q& R& n! P call print_4_bits9 Y/ @5 W, a1 @- P
rol bx,cl* s; y- y2 m8 h9 k; o; \
call print_4_bits% D! N/ W- H; R0 Z: g) v3 G' _
rol bx,cl q; F5 h7 W+ G1 r3 J. I
call print_4_bits: a! }" H9 x; j2 }9 a/ Z+ @- F7 g
popa
3 e1 y' |" E2 \ ret
7 ]( L# T$ ~# o7 k_16bits endp
8 A k; j# Z& F% u2 @& i5 j' H;------------------------------------------------------------------------------------------------
$ R- B4 { {. u# R k- T- P_8bits proc near
4 S8 f' h& J; m3 R0 P T9 ] pusha # U0 E7 p+ ^& j( S0 v M9 I( d1 X5 h4 T; [
rol bx,cl
2 N$ h! z7 D# H4 g7 U$ J call print_4_bits
& t' g) \& G0 @0 W8 E6 a9 j rol bx,cl; \+ S! a3 J& k! X
call print_4_bits
# r5 N* _5 H! B$ t1 C popa
$ l/ b' H, _# N7 `& J% @6 g( t ret% h# _- B7 V! F' ^* x- P& P
_8bits endp& Q! r3 {/ {9 t# {: T2 k
;------------------------------------------------------------------------------------------------
) d T5 z7 Z8 T. k; ~1 P5 Tprint_4_bits proc near/ `1 e$ {# s% y- F7 [
mov dx,bx' e3 r. m# d5 e' U
and dl,0fh
1 a& x1 x; d2 V \: D add dl,30h) j. }6 o5 b9 T% U# x0 q
cmp dl,3ah
6 T, ^* X$ T+ I% Y jb print
1 C( Q5 b. k7 I/ n* l) _; R' ` add dl,7
: d) \% U% C. T1 t: Cprint: " f: f' _3 S- q8 c0 e7 e
mov ah,2+ k4 W1 |: R& c) G3 n l
int 21h& {3 R3 M; q+ e' C5 F% Q; {
ret
6 A2 }4 g: |7 c" D# o# L3 E$ T) F/ Wprint_4_bits endp / s% @8 O7 X4 R, g1 ]
;------------------------------------------------------------------------------------------------
% T( F# n8 i, F$ [+ J* H/ [CSEG ends; k. q# b2 F" H! U
END |
|