|
各位前輩好,以下的程式為在 big_real_mode 讀取記憶體的值
4 `, |' T5 p$ J0 E x+ A4 X( @& B" x8 j5 b
例如: C:\memory.exe(程式檔名) 01000100(Address)
' S4 M. z; u: [& [; H
+ K: ]% c- Q$ A5 a5 `) k! ^則會顯示01000100位置的值
# I/ i7 _+ J) i7 W4 h1 ~8 d0 {' k( J; P( [- q
但是我另外還有要顯示出字串,但是顯示出來都是亂碼6 c3 @7 Z9 d' w7 u/ ]
+ f* n, @/ `8 K- n麻煩前輩給我一些指導,謝謝
' r9 |2 v8 o$ \9 z, R% I) j) B: j m! t9 Y8 Q3 r3 X9 d
) a. [9 X' M5 Q) F4 {8 T7 j' }( @
.model small
3 @, Y* u0 i7 m* ?9 z% d.386p
& X2 l$ f" {4 D$ u9 r;------------------------------------------------------------------------------------------------( s5 u# Y5 W) H6 r
DSEG SEGMENT USE16'data'
1 }% U4 H: ~- U& i, [" m" j
7 V6 ?) j# a7 ~) @; a+ ^DESC STRUC
" d' ~2 }9 f" ] J* i! f( S LimitL DW 0
" P/ O$ h- D8 `, q- {- l3 z BaseL DW 0
1 K) J2 t2 {2 O. r6 \1 g( T# [0 u BaseM DB 0 0 g3 r* w% u5 w/ G8 B& [: b s& u
Attributes DB 0
6 B' w/ P% K% @% ^2 W LimitH DB 0 $ k/ ~/ E8 B7 H% \$ }
BaseH DB 0
. }7 A* z' E4 G1 RDESC ENDS
/ e+ K* \: J: O9 j1 A# C ~+ l/ N9 F
PDesc STRUC
, v$ {" \( c9 F Limit DW 0
+ ~6 r2 W9 f+ G6 ^% I Base DD 0
# l/ E9 X7 d7 B7 Y' D5 KPDesc ENDS9 @% v: L& G4 N6 }" s$ X
- d) o' c: D7 F' c1 U) SGDT_def Label Fword" X0 U- E: h; j: G
Null_Desc DESC < 0h, 0h, 00h, 00h, 000h, 0>
% T K( h/ P( UData_Desc DESC < 0FFFFh, 0h, 00h, 92h, 0CFh, 0>" ~8 g+ d! o2 q0 V
GDT_Addr PDesc <$-GDT_def-1, >) B, P6 y5 x# O" t1 R! \3 a
( g* a, q, k1 ?3 I+ G5 Z
msg1 BYTE 'The Input Address is', p2 V+ P6 U1 N$ |' Y1 l- n! a
msg2 BYTE 'The Data is:','$': _+ e4 w8 _) f; ]' z0 u' n8 u- o
- {* ^1 ^2 U/ U2 B3 R* `, e4 C1 l
DSEG ENDS
# m- Q) m, X# Q; S: f; c& @. W. y" L0 }7 V/ Z( l4 J
1 M: m. j, [0 f" m' I* w- O
;------------------------------------------------------------------------------------------------
7 S4 {( i4 z8 B# w- E ~
+ x0 ^2 g# a$ l5 h9 _; tASSUME CS:CSEG,DSSEG
2 r0 Y( z7 s3 S1 u' ?& L1 v
1 c' T+ x; \/ c$ P' {+ J( a& u) cCSEG SEGMENT USE16'code'
. X. F- w( R, Y5 t R, f8 d
' _; y$ e x8 U/ A6 Y& g push ds0 _9 {$ n( H" H4 `7 z! `
push es/ l1 X! g' L! X6 e
push fs+ E3 Q N" f, q7 u9 v7 v' v
push gs5 `; r2 k3 ^7 R8 _/ X r, I
\* v: z/ _. V. F" |& k call big_real_mode2 b7 Y: p% l2 O( `
1 A8 d$ \+ B$ \! K2 U0 ?- b, S
3 w1 p- o% t% P! T; \ mov edx,OFFSET msg1;
# X U3 z. D3 O2 T mov ah,09h;
: N$ q6 K* b2 W8 t; J6 m int 21h;' k+ u3 m3 |6 H' T- ]8 M
mov edx,OFFSET msg2;( u5 L7 |( E3 F4 ?. h- ]9 C
mov ah,09h;
6 [: }& c- {3 m" ^ int 21h;
. T9 r" B) t$ N# x+ ?' N
# a$ N' g& S" @9 \- q* U2 X call PSP
. Z o- M! A4 `* q5 \7 r! g * j8 B* [* ^; y" H
call crlf % _9 J8 _# z6 j: v5 ^
3 K# F6 x, W% w! j mov esi,ebx
/ O8 T0 I) V+ J# I9 W$ P mov eax,fs:[esi]7 }' `, s) D- b0 r" n
out 80h,eax* s7 V" R$ a/ r& ?: n0 a0 e
mov ebx,eax
8 W/ d9 ^- f- [* D3 E6 W call _8bits
- z) {6 }, o9 s4 L8 h0 F : N# F1 \! g( P' D, u5 f9 E
call real_mode
5 e. T+ J" ]5 `3 |2 X: D, J
J* ?% l2 e5 j5 n pop gs
' A1 f2 N0 u5 @$ O4 o pop fs) p* b: P5 S+ T) w: Q1 K7 Q
pop es
. L7 G; q" F( x6 U pop ds! W2 c( I# k" |9 ?7 ]7 S E
5 C" Z. j, V/ P6 i- z3 w) I .exit
" l4 V- Q1 @4 a8 b2 o;------------------------------------------------------------------------------------------------( Z: Q6 C3 E5 B/ ^+ E
big_real_mode proc near
5 n6 H2 g+ [% `0 C- S in al, 92h1 R; |4 }! Q* W; I Y! [# T
or al, 002
, F$ i3 m& z; X out 092h, al
5 Z L, a& U& _, L* M( f# l out 0edh, al4 X5 Z8 O7 V2 I2 F
cli# J( K/ [! g- N3 ~: t o
mov eax,DSEG
8 M' h6 O7 m8 ]0 F5 y4 D* t shl eax, 4' T ?, r7 }% S# s' A P
xor ebx, ebx+ ^1 q5 C: B# F2 X7 K* x: ~
mov ebx, offset GDT_def: K8 _% x9 U5 V. J
add eax, ebx
{& s# z8 {. L5 U V mov dword ptr GDT_Addr.Base, eax! w( A0 X( |$ g+ j. h( g
lgdt fword ptr GDT_Addr
1 e+ @+ k: {. M& U mov bx, 8
1 }% W' `1 R& `- M! J+ N6 v mov eax, cr0
8 Y& s, ^, A: R! t4 p) t/ W or al, 1
0 }1 }4 c: i4 }7 C2 h mov cr0, eax) T5 l, m6 J) V, ]: R- A, l
jmp PMod
% p# @& {% {( _6 rPMod:
( Y0 @% K Q j7 I: i: b3 x mov fs, bx
9 Y, V/ T9 Q. s# M/ O+ z: }3 | mov gs, bx
7 `7 }8 e/ h" L9 ?0 j mov eax,cr0! m, e! T' r( F9 N/ k
and al, 0FEh
( S# O; U( `$ q8 i8 w mov cr0, eax 7 q% y+ [7 a/ C m7 `+ c- V/ T6 O
jmp RMod
/ W. t- i6 z, A* k, mRMod:
1 S5 g9 D8 a& E C( `! W6 ~# N( Q: P xor ax, ax
' L/ ^1 \0 {( K mov fs, ax( i- j0 D' v( X( T/ c- e: b
mov gs, ax- Z6 @% C+ f% x+ J
, F: L9 I, D" C+ ^+ L" U( d$ H sti
9 w4 I: S/ |. O+ Y" z3 Q 4 K5 ^' {, O# l8 U
ret; \ P) K6 \6 b" K' n" W$ W1 k
big_real_mode ENDP% c" J2 y. L$ d1 |2 b' P4 |9 K5 _- }
;------------------------------------------------------------------------------------------------
) |. n- o0 y2 O$ Kreal_mode proc near
0 V9 T" k+ ]& E! H! m in al, 92h
5 Y- ]5 H+ v0 ?, D+ z and al, 02
4 ?3 G, S! Q" n5 p2 L( K out 92h, al
) H! D$ g, W2 q4 g: O ret- O8 c$ o S$ ~$ C( ?- `$ M$ e- H
real_mode ENDP4 p8 y \0 z9 n2 E2 e
;------------------------------------------------------------------------------------------------: w: K/ Y, L. i1 @
Get_Commandtail PROC near }5 y+ [$ {$ {! d, W
push es
7 G ?8 t/ b7 |6 }0 R pusha# A! U% |) E1 ?; I0 m; C7 H7 H
mov ah,62h
) ]. F4 E+ k: o! V" ^+ F6 Z int 21h/ [; a" Y2 P0 [" y6 w& A
mov es,bx
" Z( l# G& j# Z* }5 m$ e popa
1 n0 G0 }9 m% \# m pop es
& i2 |; J2 p8 J ret1 S2 Z3 D7 V5 l& H3 H2 v8 n- Y
Get_Commandtail ENDP
1 H) V- `5 k: a7 e( m;------------------------------------------------------------------------------------------------
8 N) d, p) y: oPSP proc near: n+ [; E0 D; ^4 M9 z
mov ah,62h
1 \: E X' }( ]$ b1 H- ^ int 21h! I7 E- x# r5 |3 m9 D: r8 v+ m/ k
mov es,bx 6 c" S3 h& U) Z/ B
xor ebx,ebx
3 ~/ N: m2 a+ A& @* d$ e j mov si,82h
`$ a, T5 ?& b$ D E mov al,es:[si]
) U L. _' c3 e: q1 n call Change
7 Q T& n. a$ U# K mov cl,4
# C, I9 L5 J$ z3 R9 {, k b! f shl ebx,cl
3 [% e' L; E' t! Z' Z: v: P' H add ebx,eax, j& H9 C0 `1 B! k$ A0 y
mov al,es:[si+1]7 `) a# A5 n/ k- H" S" T
call Change
Y ~8 D5 `' a. G# a9 E mov cl,4
0 K, H: S( z3 H( F( n% B( \/ h8 n; H shl ebx,cl) x" m: c9 \5 w0 S: G" }+ V/ Z
add ebx,eax2 e6 s' M5 P4 O0 E* C) n d4 B. B
mov al,es:[si+2]
a+ _8 I! I) X$ W* W. Y# e. c4 K( m" x call Change; n, N5 a5 l" P
mov cl,46 S1 a% C6 z& o q
shl ebx,cl0 k6 K O! y( e$ I' }
add ebx,eax3 m2 r# n) a0 i
mov al,es:[si+3]! S# f% x. M( ?' h8 m: Z# Y$ g* w
call Change
/ X0 Y$ _" J4 E2 H( @: F9 |2 ? mov cl,4
7 S/ e, ]: Q7 I- C shl ebx,cl
; T" q/ ]" \ F9 U2 l+ U6 y add ebx,eax
0 Z7 |% u9 ]/ H& Y( P mov al,es:[si+4]
% O! Q9 Q9 R' M call Change8 O; E& Q% @5 k) {0 K
mov cl,4
/ u) g; ]# x/ K+ o shl ebx,cl
! a+ d7 [* M0 A* X$ ~! C% U( q, H add ebx,eax
6 H7 l- G, z% j) Z mov al,es:[si+5]2 W/ J/ r Z* p" T% U
call Change$ D) v4 @5 c( u6 n' E n5 |
mov cl,44 \% ], A/ N6 V* m+ n8 ^
shl ebx,cl
7 F1 k( A8 `6 K( a" R$ i add ebx,eax0 L M8 C! z+ C6 R/ ]' u4 P6 v% _
mov al,es:[si+6], K7 T h9 F1 T- [. T
call Change
% Y, o4 x- t5 H mov cl,48 g% k( r6 K7 f" ^9 |& i! j
shl ebx,cl$ K0 N5 h* n4 y9 W! Q, i
add ebx,eax
9 e& U1 q# I# @, J, r mov al,es:[si+7], q4 C3 ^6 C4 N% Y/ ^1 {
call Change5 [# w9 J# }! u
mov cl,4
8 Z! A4 w K" ]& e7 w7 z shl ebx,cl* N7 r. K; I# q, G
add ebx,eax2 c1 w6 ?4 a! A$ j
ret- v0 ^, M: n6 m
PSP endp
( W ^ R3 M: N% c' {8 x;------------------------------------------------------------------------------------------------$ h2 Z9 A4 N" O( Q* g
Change proc near+ b$ e$ s8 T" U
A: ! e4 A' q6 J8 T! ?& U5 n
movzx eax,al
1 N0 o: e' Y3 ? q mov edx,eax: g8 s0 h B9 O' Y
cmp eax,'0' # A9 {+ T- o; `3 {) C: ?0 u3 R* @
jb A M' n* e+ u. G# x0 V3 U
cmp eax,'9'
( W. ^) g5 R2 L X7 t+ E ja B
% f* p J* P8 z0 C5 K) C9 D sub eax,'0'
. q: G+ e7 X: r- u jmp short E
$ ]" i8 `& p) b* bB:! |+ i) h5 \8 @. u0 E) ]
and eax,0dfh
0 Z/ U7 W; @1 T mov edx,eax
$ P# ]0 b. O# c4 y* y1 e sub eax,37h
, _& r6 D" S9 ~" ?7 i cmp eax,0ah% k( W7 T2 |; U+ s4 P
jb A 6 a5 Z! T1 A6 M, I" E( m
cmp eax,0fh
+ j8 R# H: C* z1 G/ F) L$ E" i7 k ja A & D' Y1 F- F2 k. ?; O2 a. p
E:
. q+ X5 `: }+ H. j push eax & k4 A+ m9 ^$ L, A5 \% o' z9 L/ t! L
call PRT
1 f i7 g1 c' r! c2 n; @$ D; `& b' d pop eax+ ?; y6 d6 c3 b$ L
CExit:2 b% e7 U( V" p3 ~8 @& M
ret
% G' E2 p! X, a$ n% ?% j9 _# xChange endp# ~2 `8 D; e2 E7 o
;------------------------------------------------------------------------------------------------
* Z" [: Q0 Z" sPRT proc near) ]" X% c" g$ D2 t5 c0 V
mov ah,02h
2 z* q7 ?3 `4 E# k1 G6 W int 21h2 {2 Q0 T9 f j+ {9 l" y2 |- u
ret+ {3 j, z3 c# k3 Q7 n
PRT endp. d- I* ~ E! ~) c& b, o
;------------------------------------------------------------------------------------------------
N2 w! G+ R2 C. t/ ocrlf proc near* c: _7 t# `! A1 B# I7 W. Y
mov ah,02h6 Y/ y I! \$ C2 ?3 ^
mov dl,0dh- V# R1 P& p* y/ z
int 21h( B: K; Q8 H# S/ k0 V3 Z; c
mov ah,02h( X+ C: ^6 I6 z
mov dl,0ah
+ b: i7 f: }6 n4 E! P; c7 T5 r int 21h2 y# [3 J' W* e" K; O- k$ A& d
ret: q: R3 H a1 q) l3 j8 S
crlf endp* `) U. `- k3 j; ]% G5 \
;------------------------------------------------------------------------------------------------
/ t) E6 d6 `7 k/ ~; L7 u0 O$ i; D_32bits proc near
% a8 J! e( m% f2 } G- l pushad* U6 S8 T" B3 w6 A2 |5 o; Y0 L
mov cl,4
& I& N- K7 `5 H3 Y; {% ^ rol ebx,cl
v3 y4 s4 Z& x call print_4_bits: I& b% a5 D; T8 O3 \! N, j9 v
rol ebx,cl0 ~+ y# j& W- E1 |& j( s7 T5 @( ^% J4 s
call print_4_bits7 a5 s$ Q% P4 u2 N+ G( o* ~
rol ebx,cl
* ?! C! w6 G" ]2 _. w call print_4_bits. p6 F/ P. i# ?" u" g
rol ebx,cl
' R( I! `& P# \( | call print_4_bits
t3 z1 T3 g% Z k4 S rol ebx,cl3 w6 N2 D' k% T% ?4 x; w9 [. R y7 ^: E
call print_4_bits1 F* @2 ?8 W+ s. E4 A1 j9 b
rol ebx,cl
( j/ ~7 O. M) z0 w# M& X6 ~4 g) q9 s$ j call print_4_bits
, W, g8 t7 k/ [ rol ebx,cl
8 ?; }# U6 m0 V2 K% ]3 X call print_4_bits
: W0 F2 G" r8 C0 J; S" j! T1 K rol ebx,cl5 n$ @0 O$ r2 ~' a7 {
call print_4_bits
: T" g3 Y! x( `4 K rol ebx,cl
! U8 r5 h3 v& j h7 o2 Z$ h popad- a$ @) e/ B+ v+ u
ret
) h! d* c9 a0 @3 ^( A0 n_32bits endp& a4 S6 @0 i/ Z
;------------------------------------------------------------------------------------------------
% T& V$ W, i& j7 Q- r" ~_16bits proc near
* h/ }1 g0 p9 f$ l& S pusha 7 f* Z& B. f, k D4 i+ ^4 k6 b
rol bx,cl: z, j' X8 g) H; X1 z
call print_4_bits$ H1 k6 S: l$ _1 R8 a3 z5 ~
rol bx,cl+ w5 g+ z& G% W/ V
call print_4_bits+ V4 f+ P* H7 y' v6 R b7 }. `+ ~
rol bx,cl
" G9 G/ G1 g0 T6 Q; y( T& P% f, n call print_4_bits
2 k/ U6 O% B7 c; i% ]/ F) X rol bx,cl5 U; k+ ~6 x1 {& r" ~ B8 t0 X S9 U
call print_4_bits j; q( ?2 y; l1 v! O' n
popa' f3 d7 p; J( l9 T) [+ S5 \, [
ret- Y3 I |2 }. k% ~
_16bits endp
2 s7 o! e9 B0 ^- D( T;------------------------------------------------------------------------------------------------
! g+ `, o1 V* j1 O V E2 Z_8bits proc near7 i- |+ Y# X' R8 F
pusha / n9 Z. q1 l2 x# k) p9 N8 B
rol bx,cl0 g" e6 f+ o8 ~: A( M8 N
call print_4_bits
6 U, W& j/ j8 @ rol bx,cl8 H1 F% d3 g# u3 ~8 b. I! p! \
call print_4_bits, U' W* a7 P" m/ o' c7 O
popa
: K( r/ H8 T: S F5 d3 r6 H1 T5 L ret
# {0 j+ l" ^/ U6 I( R_8bits endp h* s' Y* s) O
;------------------------------------------------------------------------------------------------
3 j" |8 i7 W; J% P7 ^print_4_bits proc near
; r I% n8 B+ l: s' n7 b mov dx,bx% e6 C C5 t) [: \9 T9 a
and dl,0fh
; l3 @/ K% n' R* Z' V! |4 a add dl,30h2 \$ W7 Q! `8 \9 {" u# [
cmp dl,3ah
3 \7 X) y& r+ S/ y3 h( m jb print
1 |& A9 N5 d8 S/ D" y* A add dl,73 o% `0 b+ U3 [; s
print: ! l$ ]0 [( m$ ]9 N* M B
mov ah,2# ]# ^7 W" I, Q8 s0 ?5 I! o* p
int 21h, Z) z+ _6 |) t0 ?
ret
/ c/ W3 X5 W7 z! W$ y; aprint_4_bits endp ' Y' }" I0 j& |$ O- l
;------------------------------------------------------------------------------------------------3 ?6 k, A9 P' ^
CSEG ends8 M! y* b7 G9 F2 x9 f
END |
|