找回密码
 加入计匠网
搜索
热搜: BIOS ACPI CPU Windows
查看: 8757|回复: 0

顯示string會出現亂碼

[复制链接]
发表于 2010-10-19 16:41:51 | 显示全部楼层 |阅读模式
各位前輩好,以下的程式為在 big_real_mode 讀取記憶體的值
, Q: A; {4 P$ n6 I' T( {5 ?) u3 V  g) [, h
例如: C:\memory.exe(程式檔名) 01000100(Address)
9 y6 V# [. i/ ]' y$ ~1 O
  \7 Z; G; d) j9 o! J0 _則會顯示01000100位置的值8 p0 G9 z7 q. S5 E

7 L6 o$ ^# p' l. C但是我另外還有要顯示出字串,但是顯示出來都是亂碼
2 n9 C5 H: I! }! g# H' _8 Z* M/ m7 [- P  X: w
麻煩前輩給我一些指導,謝謝  8 n! m* u: G" U1 ~

! I! c; A: s% z, u- B. J
  ?4 E& c5 v  ?" s9 K) L3 M5 M.model small- C: b! ?( R* |/ d7 _' ~' l
.386p
! \" b4 t$ e* g5 O3 k! ~. O;------------------------------------------------------------------------------------------------$ o6 R! [7 F5 x3 M2 K
DSEG SEGMENT USE16'data'  ' Y4 u, x! b. f7 W0 z
% L/ j! t( C4 m7 ^" M( V
DESC STRUC. L3 r5 g" p1 ^) k  m
  LimitL DW 0  4 i# d1 }1 E. i! }1 Z" X
  BaseL DW 0  5 b4 u+ N6 d3 _7 r
  BaseM DB 0  
9 o" l6 |: m8 ^1 {/ n  s/ h" w, o  Attributes DB 0  & j' A( m$ ?0 O& V" A  M# ]) U, F
  LimitH DB 0  
9 `% f( s9 t  S  BaseH DB 0  / D! P9 _8 O7 b% Z
DESC ENDS
4 E+ R+ ^$ d1 b) V( N" P# M
" ^6 o9 B$ K& S! v6 bPDesc STRUC! a7 N6 b- y0 S
  Limit DW 0  
+ ?/ }$ ~$ P9 v  `  T. L  Base DD 0  % u. I) j4 U' |; U" [6 p1 o
PDesc ENDS
0 U( I+ |4 }) {6 x7 i" |- W
0 w+ V, d/ u5 |" D! X7 hGDT_def Label Fword
: _. b" O) G9 m4 z0 Y3 H* s2 Q: t! yNull_Desc DESC < 0h, 0h, 00h, 00h, 000h, 0>
1 I7 S" ^$ J! h0 L4 e$ H8 aData_Desc DESC < 0FFFFh, 0h, 00h, 92h, 0CFh, 0>3 }( {6 R; l6 E( f- P3 D
GDT_Addr PDesc <$-GDT_def-1, >2 n1 a$ G( P/ Z/ d$ s$ \6 Y
6 {4 N9 x% M3 m" |/ V3 i
msg1 BYTE 'The Input Address is'4 ]$ ^/ i! ~' ^4 X- t( f
msg2 BYTE 'The Data is:','$'
2 a0 K9 {8 u5 z8 `; |5 a
" u7 f" E$ S) rDSEG ENDS
9 j1 l- u) Q* N  }
0 h) p6 p' F8 q1 A9 L5 S
3 B' \. _3 s  I* V# J0 W6 B;------------------------------------------------------------------------------------------------  
& p6 g  s7 }2 i$ ^
! I# z6 z! W& A& h+ |ASSUME CS:CSEG,DSSEG0 U- B% I. I4 r" L. e8 P0 T' w
) y+ y& z9 W; ]% G
CSEG SEGMENT USE16'code'4 i: d9 O" b: K& R5 f8 z
  
+ {1 Z0 z- E4 v3 M7 j  push ds
- t# v) @& F  v9 @, P7 U. @  push es
% O. l8 A- V7 l% T  push fs- G$ M3 L. l7 \( ^9 K
  push gs" @! D5 F. f# x$ Q
  ; }9 {+ I: K$ U, L
  call big_real_mode
- z" n/ _+ p7 B, C1 F3 E  z
( ?5 j% R* J. N- h' f0 X   
( M) s% V; g* d+ d  q, z  mov edx,OFFSET msg1;
% b1 `" E  [: K! i1 T  mov ah,09h;   5 i% R+ f' r- B; K+ \& K  Z9 V, w
  int 21h;- L& j+ k. Q/ ?7 n) [
  mov edx,OFFSET msg2;
. X0 n, _/ M- j3 ?3 i3 m5 j' w* R; X) i  mov ah,09h;
* V5 j! ?8 v  R% f% X8 ~: B  int 21h;
5 K% R8 X) [; H- l1 o% S7 J    . {" K7 E8 X4 N) n9 X( s# I
  call PSP   & i5 r: s+ g: J- h- J
   
; q7 h  M8 ~2 h+ \2 [8 l) d1 I  call crlf   % G! ^! Q8 |/ B$ E" l+ o+ |
   
& D: C( b. T4 ~6 c8 |, F  mov esi,ebx
+ m' B3 t$ X, \0 }$ Y  mov eax,fs:[esi]
6 W2 H3 y9 c- l( f' f% I; |$ n  out 80h,eax" c+ B6 k) }; l; }4 G1 x
  mov ebx,eax% f! h) c9 |8 c7 g, i8 g
  call _8bits5 a! Z7 s! ]& @; n+ N
   
5 ]8 f7 h% Z' k# d( f% o1 @( D5 l  call real_mode
6 H) i, u8 ~( }6 d. O    : q2 H, n5 s: c% M9 T
  pop gs
) `9 U9 a4 P% h5 j0 K1 t  ~  pop fs7 H" l  F- z% B) H. M
  pop es5 l! Q& P% t4 a, ?5 D
  pop ds
' W; U5 ^& `/ g$ L/ U% ~& m9 k   
8 f% G: e4 E8 E  .exit
5 `) C  c0 `& R8 ^$ U  W, Q6 `;------------------------------------------------------------------------------------------------" k  `0 k  I4 U1 b
big_real_mode proc near; o5 a$ q' d! }: H# Q
  in al, 92h
  d+ Y# W) P/ N  or al, 002( n0 K8 f3 o/ K8 V2 `2 m
  out 092h, al3 T8 N( v, j+ ?6 o  o3 i
  out 0edh, al
0 L2 m: d( p' N  cli# I% Y3 E+ h1 j8 @2 t! K
  mov eax,DSEG
" h# W; _& M" |* J& Y% j0 T  shl eax, 4: O. M5 {# V/ |0 f
  xor ebx, ebx
4 M4 l  i) j7 f+ X" E+ J' L; T  mov ebx, offset GDT_def; B% _; u1 M/ i8 N
  add eax, ebx- u% n6 y" v4 @2 P; B
  mov dword ptr GDT_Addr.Base, eax$ x1 w; ?2 C  J* y  O
  lgdt fword ptr GDT_Addr! R) b% R- d& A* D3 q
  mov bx, 8/ a5 U' i) ~- a+ Y8 n, z
  mov eax, cr0* e" M: D+ p/ c9 Z
  or al, 12 J& d& i0 b1 Q8 w  o
  mov cr0, eax
5 P- k- N; V# k- e1 _- e( v. U  `  jmp PMod
" J5 J0 D1 d, O8 P% z" r6 MPMod:! n+ [3 C9 [# e' ~) o
  mov fs, bx
% x$ E  @) W" F  mov gs, bx' s/ x2 V' M: ?4 B& R7 X
  mov eax,cr0
2 W- V% `7 ?/ H5 ]1 O, q  and al, 0FEh
. ?' T$ d+ i! U* W0 U' _# I& D0 G  mov cr0, eax  
/ c1 V5 q& t! A6 O$ V  jmp RMod, Y; N  g* Z7 T$ o/ V0 V6 {
RMod:
- n  Y2 E' ?! o; H7 }; {2 v  xor ax, ax: ?; `+ }- f0 ?; s+ J# R5 o
  mov fs, ax
( y2 L4 T; h# S  mov gs, ax
, z2 W* z# ?' |% Y  b# e( Q   
5 y2 @6 @- f! r  sti
/ K3 D. a) ]8 U; B   
* X; w/ q5 i7 s/ _  ret3 L6 ]' X$ U+ |  f
big_real_mode ENDP
' a, Q7 Y. d: v) Y0 G;------------------------------------------------------------------------------------------------
' g! B1 T3 a, z( Rreal_mode proc near
! W- Y5 c" X- ^2 P6 }* l  in al, 92h
% U0 B+ _& s) W6 M# o  and al, 02# n! e' O0 R8 I2 a8 _
  out 92h, al   / {) ]+ D) j) m1 r# [5 J4 `
  ret- \8 A" x. G; ^/ N6 P9 Q
real_mode ENDP- b( k+ s5 R* V
;------------------------------------------------------------------------------------------------  n* P8 [) N  a! Y1 c7 l' d8 b$ X
Get_Commandtail PROC near6 ]2 ]# @/ `( t0 e  `8 J& P. G
  push es  + Q1 E" x& w+ E) E9 X$ P8 M5 Q
  pusha* I# l8 M4 ?8 ]: r
  mov ah,62h  5 u) x# ?& A; {) ^* u! X, i5 x5 h
  int 21h2 P2 ]4 b3 \6 I' E9 g- [0 x
  mov es,bx
+ F- m6 @/ ]% g7 a- Y5 o' _) |, m  popa  
: l3 l+ L' \! s7 z  pop es
* V1 p7 `) b# C- b3 A* e( H7 N7 _  ret
3 |9 S) E- V4 X) H# vGet_Commandtail ENDP
* B2 d3 q5 l3 L! N2 n6 Q" h7 };------------------------------------------------------------------------------------------------
0 ^6 Z$ H* x5 o. U4 ~( N* a  UPSP proc near
/ S7 N) ^/ m: c3 Z: Y" S  mov ah,62h
- u  T2 j# W! z! W2 u' V  int 21h
* V9 L- p- _, D$ q7 f  mov es,bx   ( z  X# {2 a8 a& H' e
  xor ebx,ebx
, s+ C, [# i- D7 y) Z  U. E8 x  mov si,82h! ^- H8 z5 r: G; L; ^
  mov al,es:[si]
2 X3 q0 p9 d0 S( l  call Change
2 e2 L- G  o: o! ]% I0 @/ O" P  mov cl,4- G* f- c5 o2 u$ [; p5 p$ A
  shl ebx,cl
" }# B1 G" Q2 H  add ebx,eax
/ v4 b! Q3 r2 y8 y) ]/ V( t, }( ?: r  mov al,es:[si+1]% M* r& }6 b% F2 n0 v  P
  call Change
6 O) M* ?1 T' F. Z  mov cl,4
+ k2 G4 A) [8 D! o4 N; O  shl ebx,cl
: E% t# N% Y4 O+ `0 Y+ e/ F$ e  add ebx,eax2 A" V  q2 Q- Y1 C
  mov al,es:[si+2]
% g6 P% z; Y; |5 L. j) G- f7 y5 I  call Change5 I# M* k* t2 B8 _6 R' q" q$ i
  mov cl,45 w( K4 r8 {- t0 W" p8 W, ^, x& ^# @
  shl ebx,cl  A/ _7 d# X7 i6 P0 S8 {
  add ebx,eax- N- m0 M  }2 q
  mov al,es:[si+3]' M2 ~2 H* l, p( W5 K$ @
  call Change
+ y/ L; O. ]1 _1 x) c& ^$ O  q) `  mov cl,4
1 |/ c8 ]8 ~" {7 [+ t3 q  shl ebx,cl
% g* |! F' C  h9 B  add ebx,eax
3 D3 |, H: J/ }' r# p: H  mov al,es:[si+4]
  {7 ~% i1 [  h5 C) h  call Change
& a. {0 o+ y8 P7 z  mov cl,4
( j' r! T" X- o* L  shl ebx,cl, K! H* g% e' I
  add ebx,eax
* A. E# z; H  y0 Q- c4 y# N, |  mov al,es:[si+5]5 x! c8 H- t+ k* i' V, ^
  call Change
. m# w9 V) a4 `  mov cl,4& h8 ]$ M4 C: `! J
  shl ebx,cl9 P, `: K9 R0 u* W2 s+ t. ^
  add ebx,eax
; U# B6 T) y1 o" ~" w  mov al,es:[si+6]( w( E1 @$ r" S( O
  call Change
# B+ ~! m# w! B3 p  mov cl,4; t" j. u6 ^: @2 j9 Y/ o: f
  shl ebx,cl
. Y6 ]' D. z- U: \  add ebx,eax2 e' \8 x1 p! G0 B3 m& u  i# B
  mov al,es:[si+7]6 G' }2 w' f' f; a$ X6 O1 Y# k
  call Change
. f, \4 A4 O- D8 ]  mov cl,4+ A, _' o- c. U; h9 I% ~
  shl ebx,cl' u* J. ~/ \" t  D. q! a( z; ?
  add ebx,eax
' v  ]: |9 g; b9 F- l  ret' w+ H* c* \" f5 A/ x/ _
PSP endp
+ b% b0 Q( x: @;------------------------------------------------------------------------------------------------0 r0 |+ ^% g1 R
Change proc near
+ m' A! ~2 G8 V3 x6 c  ~( LA:   
- ]  t/ ]# x7 R2 H! C5 ?  movzx eax,al9 K' {3 O0 e/ E7 ?
  mov edx,eax& y0 f. s8 L( l: Y4 b- O' Y
  cmp eax,'0'   + R8 h+ z0 T; F  x) @0 H4 d
  jb A- f3 u. R9 g, g5 F
  cmp eax,'9'   5 X5 J8 f3 d# Y+ A
  ja B9 V& U# O$ e1 ?* Q
  sub eax,'0'
2 g: e+ m4 j% \1 |; k) }8 F: W  jmp short E( l' @( ?- s) m) K* u
B:
( m+ ]4 p* F: ]# Q8 g  and eax,0dfh   7 U/ K& P" ^; ]& L/ S
  mov edx,eax9 x; R+ ~* J& e% }2 v7 l
  sub eax,37h   * m, E6 L/ {% u$ a9 R9 c5 m, D
  cmp eax,0ah& a+ _# }3 _7 J$ S7 q1 A) R
  jb A   . L- l" D0 X7 k2 I# s
  cmp eax,0fh
& G* k0 o# q  M% b0 A+ Z% d  ja A   
& l1 |6 |" ~) [& i9 pE:
8 E5 T, i/ k; \& G1 ~+ ^2 k  push eax     I) O: G8 ]/ i/ u
  call PRT   
7 r. x/ X8 ?3 [/ ^9 T8 {: g  pop eax$ v; a  u8 j, _+ U" c# w6 W6 B
CExit:
, i, X5 Y" ?% O& n  V8 Z9 b( B  ret
: |* K) ]$ D: T8 o  j) BChange endp
1 j. O. w! K& h! q+ S4 g, x;------------------------------------------------------------------------------------------------( }4 o3 {; Z, Z+ Y( R2 Q
PRT proc near  I9 ]6 Y5 ~9 @1 k5 v6 z
  mov ah,02h
/ ^, p! |/ a/ \$ m: j1 W' j  int 21h
2 G/ f8 J, c' X& t1 |  ret7 n0 ?, R# L( _
PRT endp
2 W& t" }( Q* N6 a/ Y; I2 r* _' H;------------------------------------------------------------------------------------------------9 E' y. a0 Z  T! X9 q! @
crlf proc near7 i5 Q' l. r4 ?& a1 [+ n  f
  mov ah,02h
" @4 M. C8 L- J7 J2 s% |  mov dl,0dh
$ Y) N# r" F0 U% O  int 21h# v7 g$ w( T* I% l) v: _  `
  mov ah,02h
9 v& {. G( p$ s( h$ H% O+ _  mov dl,0ah: Z( p- ^6 ~$ N1 E
  int 21h& H6 x' U: @7 y7 T" u
  ret
& x! z- T, g( I- q! ~4 Acrlf endp
& o' S/ }- w0 f  a9 h;------------------------------------------------------------------------------------------------
! J5 r! b# ]7 i/ H: g) r% w_32bits proc near
+ q) V7 A: `6 p" p% M* F  pushad
; H% i  H2 r7 \  mov cl,4
: r  u( _5 f" P( G, ]1 `  rol ebx,cl
* I5 Q+ z' Z0 z0 \! ?  call print_4_bits
6 Z) T: C5 \/ E0 l0 R  rol ebx,cl9 S0 _6 _* F+ L/ c; u
  call print_4_bits0 j- P: B$ M+ T% m; e. I& k
  rol ebx,cl
9 Q4 }( y4 y2 b0 d8 w1 P) J! p  call print_4_bits9 ?4 e, a- K: d$ x9 k- E4 }- D
  rol ebx,cl
2 J3 n; G$ u2 N7 N) t/ V  call print_4_bits$ l% X- p0 @8 A- i
  rol ebx,cl
5 T/ W, `  L& K  call print_4_bits/ ^# m5 n8 h( Y; K  c
  rol ebx,cl
6 c. E$ {; z7 i7 j; T% \; J  call print_4_bits
' e' S) m/ ^2 x9 Y$ k! q  rol ebx,cl! S( o. s3 u2 `0 ~# C1 A0 l
  call print_4_bits( {$ S+ D% C+ P- c* I; P
  rol ebx,cl4 L2 o& w( y. |( v# ^" h5 f- Y* c! K
  call print_4_bits6 r( {/ {3 K* T/ ]0 p
  rol ebx,cl
- }+ {+ Z5 d$ c9 [5 |  popad
2 Q  O% g; [. d  ret
$ F) E* h: A8 {' v' R# E_32bits endp& a( P' h# K% [7 @  M2 R# }9 S6 T& [
;------------------------------------------------------------------------------------------------
7 v, `4 n: L9 z, Z0 U* n: d0 l' O_16bits proc near
9 t) m# M( t! {7 y  pusha   
; k- R% t! y1 j4 d, _  ]/ x; G# z/ V  rol bx,cl' E+ b' B( f! U1 @$ |
  call print_4_bits5 B  p% d2 P1 k( G
  rol bx,cl! p, u- L, g0 y$ z! D
  call print_4_bits
" I" Q! ]0 y' h; f# }  rol bx,cl
3 h9 ]1 ^) O) G  z' f6 u+ b  call print_4_bits  D* M) ~' z4 B$ {$ V- R
  rol bx,cl6 n4 |6 _# M, i3 q3 o$ m
  call print_4_bits
9 f; D/ I3 m8 S+ Y  popa# |' n, r4 N  q' \% D" m+ U- p' v
  ret  N" O5 a! [; P& L. O
_16bits endp
8 a( e& o- [" I" R! V; {, ^;------------------------------------------------------------------------------------------------9 A4 V/ _6 N  B4 P3 X1 O+ R# Z
_8bits proc near: b1 l1 ~0 R6 v9 }" f
  pusha   
* _( {, N3 i" `  l' W1 Q; @+ l  rol bx,cl* E+ Y+ F1 z7 g# j) B) m& ^
  call print_4_bits
1 v2 M3 i# L1 H" y  rol bx,cl9 W5 \) C+ R3 N$ {9 @& n9 h* c! W2 {
  call print_4_bits7 a; B8 K6 [; ^$ D6 N
  popa
& r- L% a( h# @9 X3 V, b) S  ret& c0 m; m" c) p8 ~. C- S4 k0 g' A
_8bits endp4 \# ?) E$ n- m2 H; i* k3 l( u
;------------------------------------------------------------------------------------------------
: @! B& k+ U7 u. zprint_4_bits proc near
8 u) M9 A, {2 N/ F! Y$ p  mov dx,bx0 d* {2 v, U0 Y7 |% f
  and dl,0fh7 @0 y+ W0 D; a4 F% Q( s/ k% n9 h
  add dl,30h
. U# ?/ C& q6 \) b  cmp dl,3ah
) I1 j5 ~* g. \+ r4 n  jb print
; g1 Z$ B) {0 x! v) V8 W* ]; Q  add dl,7  [; Q, u% R% _5 h& ]
print:   
+ Z1 }3 F& y) r8 O3 [2 ~3 W  mov ah,2
1 m' K; t0 w, L* ?: |  int 21h' z3 h/ p  M3 s
  ret
5 J- P  [& m4 \! D" i% Sprint_4_bits endp   
/ M( k  \. @2 b" E* d, Y;------------------------------------------------------------------------------------------------
2 y# G9 }( `: j" T& h/ ICSEG ends1 x1 ?: V4 ]2 u2 p+ _9 e' z' A9 n  V4 A
END
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

Archiver|手机版|小黑屋|计匠网

GMT+8, 2026-9-18 20:09 , Processed in 0.061713 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表