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

顯示string會出現亂碼

[复制链接]
发表于 2010-10-19 16:41:51 | 显示全部楼层 |阅读模式
各位前輩好,以下的程式為在 big_real_mode 讀取記憶體的值
) z7 f, m* U" y" a" U+ l  D  h. G# T" P% j% w! r6 x
例如: C:\memory.exe(程式檔名) 01000100(Address): H' x% ~9 G# e7 e+ Q

! x( z" Z% S1 x則會顯示01000100位置的值# Z5 Z+ _" c- V& |& B
+ G2 Z( r9 R* p
但是我另外還有要顯示出字串,但是顯示出來都是亂碼! d0 k* b6 D6 ~
. h+ Q9 ]" A7 M) C1 g* `0 `
麻煩前輩給我一些指導,謝謝  
. z4 @! m- y4 a( G1 k) K( T: N4 @

5 P  S* v7 ], @+ Y# ^7 Q! u.model small
6 H- y* |  n" O) [3 |: ^4 }4 j.386p
: x% P5 ^& ^, ~;------------------------------------------------------------------------------------------------
0 Z$ q% s' s8 K6 o6 E- D4 aDSEG SEGMENT USE16'data'  & {) [8 q+ C; _, W6 [: F
9 T% W; N: B2 g9 u8 h: w/ U
DESC STRUC
! v  t4 T% y  M4 M  LimitL DW 0  1 I  i3 `: ^4 N9 q# `) I6 E
  BaseL DW 0  " x3 W0 A; `/ c4 g. U8 P
  BaseM DB 0  
, |- q  x( P( @* U9 W  Attributes DB 0  1 U- w; r2 u) ~; R
  LimitH DB 0  2 e% ?! {. r! D0 K! h. U
  BaseH DB 0  
+ d/ G8 A/ ?1 F2 m8 B  ]9 tDESC ENDS
/ T3 {: j* ]( h! h' h* T* o7 }5 d8 E" Z, D2 u& ~2 B8 f
PDesc STRUC
* ^" }. F1 Q% g8 O: w/ E0 z5 E' w  Limit DW 0  2 s' S  s  ^3 o- ~
  Base DD 0  ( }/ H, x5 R4 D$ G: K, w/ S. M2 {
PDesc ENDS
! `1 u% _7 T( w) f& F( H/ T: L; R0 h4 B; r: ]7 T
GDT_def Label Fword
3 n9 C# i- \- A+ e; k: e( fNull_Desc DESC < 0h, 0h, 00h, 00h, 000h, 0>+ F; M4 d4 P: f: X( L
Data_Desc DESC < 0FFFFh, 0h, 00h, 92h, 0CFh, 0>
* Z' g' r' p+ F* H3 [; wGDT_Addr PDesc <$-GDT_def-1, >
" I' Q- C6 L& c& _8 q4 K5 g$ W* F& J
$ R6 j9 Y, @/ q$ F. e; r1 z: Mmsg1 BYTE 'The Input Address is'
0 @" a9 B  [4 `9 {& V" Q2 P. Lmsg2 BYTE 'The Data is:','$'# ~2 h) n6 |& {/ c
6 P) z4 \, i( G' B8 E1 ~5 R
DSEG ENDS$ o3 y5 f' `: P1 B/ w' U
/ P$ O% @! ]. Z) E$ G% h

6 g! f/ d2 f1 r;------------------------------------------------------------------------------------------------  2 N0 c$ t2 L: r/ D
4 X( s1 h$ }( k1 h+ @5 S
ASSUME CS:CSEG,DSSEG% n. j( G& v3 Y, X# [
% H: p4 e3 {* d5 p  E  m2 I, S
CSEG SEGMENT USE16'code'
$ U& T6 G9 W- l( k$ M  ; R% w4 U2 t- C" m* x
  push ds
2 M$ V3 |, w7 D  push es9 {7 l/ z" R! j$ j- f- A2 F. w" D
  push fs
8 v4 r; c8 w& }  push gs
: _7 V* V; p. x  Y- R( Z' R  # N: s4 {+ d- R4 ~, ?" {
  call big_real_mode3 G& C+ d* D5 J/ x# y  F
* t! L' o6 h3 p6 Y6 T
    : X7 w2 d/ R( o6 `; ?
  mov edx,OFFSET msg1;
1 l% j# W7 t# c( k' Q# [& {  mov ah,09h;   
3 w- B3 d# ?; S8 _: d6 q* m, V  int 21h;
! x- j; \9 a7 ?  mov edx,OFFSET msg2;
0 f; D% P! Y+ _& ?; k8 Z: u; L  mov ah,09h;# `8 G9 O( A/ M: c) c/ \! \$ T
  int 21h;
! ]  `  N& i8 G/ b$ \    ; v2 _$ y! B) q& A4 x" Y6 ^2 h7 Q( N
  call PSP   
! C; k4 z; `# Y, C' |   
" y6 C' K: ^; g  call crlf   4 Z5 u; ^+ G% F5 M" H8 A
   
& k9 D" ?4 _; w" |  mov esi,ebx# t1 l. C6 V$ p9 O8 C4 p4 e
  mov eax,fs:[esi]
* W5 s, p" m  B) x$ q  l  out 80h,eax" l$ ?( ~! a1 B/ u* }$ G8 T
  mov ebx,eax
4 e, {4 t! x6 \4 m0 K8 l- M  call _8bits# X$ ]. H" _( t' Y. w2 \
   
* d2 w- x6 b* f' H% i& z9 X  call real_mode; Z, w8 P& O; w6 l8 y& o& N5 x
   
. C, a4 v; K. X+ `, b  pop gs
2 g' S0 I8 I5 v( h+ K8 H  pop fs
0 X9 y& s, P. j4 v! J, O  pop es
& e% h% V! M: i5 b8 B8 I( L  pop ds. O" Y& |( r1 a6 g6 m. u
    + h, C/ M: y: {9 {  {6 g
  .exit
, l# w# [0 z/ ]! s& L- e;------------------------------------------------------------------------------------------------3 H% w/ S% K" r
big_real_mode proc near
" V" @7 B0 s5 @+ v7 N  c  in al, 92h, }1 e( Q1 R+ z$ t" ~3 T2 P% {
  or al, 002
% z5 [, v8 T- a/ M' w$ I% o  out 092h, al
) }/ P- n) E- h) @+ Y2 [) S* m1 a  out 0edh, al
8 S0 Y6 v+ D9 ]2 j/ X5 x  cli- l+ O9 Q$ x! R/ l$ h8 o6 s
  mov eax,DSEG2 P) U0 R+ R1 m- o0 a1 m' k; _
  shl eax, 4  b6 \) ?" ^" T' X0 K7 n
  xor ebx, ebx
% g2 E. x+ `% L) h* \  mov ebx, offset GDT_def- ]6 I" f0 S5 L/ R. M- Q( A7 B- C
  add eax, ebx5 d* y) d0 y# n6 h- ~9 |* @
  mov dword ptr GDT_Addr.Base, eax) J$ W! O& H; a. U7 {: d9 G
  lgdt fword ptr GDT_Addr
! P# c8 ~$ b! h2 Z. ]2 M6 A5 @% F1 W$ _  mov bx, 8
3 ?, g4 t5 @- k+ f4 F( d& s. l  mov eax, cr0
/ y' F) d9 Z% b# j' H  or al, 1
' _; r& U8 F2 k+ _' B+ }; n( N  mov cr0, eax  z- r% l/ I% p: [) A5 K
  jmp PMod
9 v; U$ Z# p! T. E8 @) V7 GPMod:
' Z( z( z2 m/ M) B  mov fs, bx
) |: V2 m# d. [' p$ @3 }* K) m  mov gs, bx7 t. {, L, ^% i, v- X2 N
  mov eax,cr0
9 E, P/ ]8 t- t4 Y6 O8 a  and al, 0FEh+ d( v8 [. e. ?7 k- O; u6 s, A! I
  mov cr0, eax  8 ?4 \* B3 O0 {' a  B6 X, w+ i
  jmp RMod
- `! g& u3 {0 _RMod:
9 Y' Q/ u. I5 Y! Z8 k. v  xor ax, ax
$ @9 D! A" H7 w  c$ L' V+ M  mov fs, ax
% x, [3 M8 o- Z- b8 Y: D1 P1 P. K: X7 F  mov gs, ax; N, P- J1 j/ U/ `
    % n9 c. a0 [. ]: F( L$ X! F- _0 _" N. w
  sti
! v1 f" j8 r2 B- H- p3 m   
! c; e5 c% ]7 H6 f3 ?  ret; K) c0 D+ }3 A9 ]; M5 [8 L; |2 r
big_real_mode ENDP) F. n+ z* Y$ w: n) w# `! [
;------------------------------------------------------------------------------------------------
. k# p5 H6 ]  j5 C6 Oreal_mode proc near
8 _2 D* l4 e4 W" M/ B+ v  in al, 92h5 k. }8 P3 J/ Z) Y4 q
  and al, 02: h& B" b4 o, G
  out 92h, al   ) q* y+ V% H% c4 T
  ret
2 S; J3 A+ z7 u+ ]real_mode ENDP8 T; t/ b) c( y6 X' c: b
;------------------------------------------------------------------------------------------------7 o# Q+ C+ g. F4 _( U% h
Get_Commandtail PROC near
; V/ }9 Q, \0 ^1 f, N  push es  4 r+ l+ Y" k5 ]5 [' M
  pusha$ H, y' \; }# T
  mov ah,62h  
; J' D. C9 z% @4 G- t5 r  int 21h8 \' ?) P# b& _( z
  mov es,bx9 |" s. N$ ^: `4 W% a2 \' a
  popa  
( v1 `, f) l# c( o  pop es# o7 n, [1 L/ Z
  ret
0 Q: [0 J4 D: j# q! v- b5 ^Get_Commandtail ENDP7 M3 u& G8 x1 y& Y
;------------------------------------------------------------------------------------------------8 [1 F7 j% g) @# G: ^& f
PSP proc near
  j& G$ Q; e% k  mov ah,62h
: N5 C- _6 L. U* Q  int 21h' J5 N0 T( [& b6 }" }  z
  mov es,bx   
- X) F7 h; i  b# `* ~' P  xor ebx,ebx
2 O: I2 Q1 g& Y, i, T3 }  mov si,82h; |1 k( r- f; N0 Q0 h0 }
  mov al,es:[si]( r: q/ ^6 H& u5 r! j' Q+ P
  call Change" S1 y" p  q; r- U, ~+ H
  mov cl,4
$ i" j6 Y3 V; s7 t" Z% \2 A2 {8 C  shl ebx,cl% _# m: g5 g4 x; J5 o- e8 x
  add ebx,eax3 e6 A* c1 h# A9 y( \% s
  mov al,es:[si+1]
& u& K# t* R; g% y  call Change7 X8 E* s# J/ U: X" Y
  mov cl,46 i+ |% ^! x( l# B! s+ I
  shl ebx,cl/ L* b# u  o9 B3 c, `' m# Q
  add ebx,eax2 T0 C6 K) s* y* U( ?* Y% b
  mov al,es:[si+2]* i7 S7 Z7 @5 x5 Q9 `5 q
  call Change
! Y$ k; d8 o3 T1 q  mov cl,4: [# C5 i4 ]" B0 a, }) }! e0 ~0 u$ l
  shl ebx,cl' Z: X) s7 c1 j
  add ebx,eax
) [" ~/ P( F& `( o  mov al,es:[si+3]
1 D5 k7 L4 M. j/ C+ Y  call Change
$ c$ p% x2 E4 E- {7 M  mov cl,43 @; N+ s- R6 Q8 L1 M2 r
  shl ebx,cl9 @' a/ M$ q0 l" \4 Q! w3 R
  add ebx,eax6 {( t2 ?- q7 u3 K: y
  mov al,es:[si+4]
! e9 O  h' ?& E: l+ t  call Change5 h- g/ H. P8 T  U) ]( u
  mov cl,4+ s5 w4 I0 Y/ L5 s2 }/ `) b7 u
  shl ebx,cl6 l+ ]6 K" Q' Q6 f( T
  add ebx,eax+ d& l& B/ w/ g+ @: _/ P
  mov al,es:[si+5]
1 T1 U  x8 C$ A8 [; y- P9 Q! W  call Change
8 z9 T* S! k+ g3 `* a3 @  mov cl,4
/ |; j! L/ _' A6 h- g$ |# U  shl ebx,cl
5 P6 `) r, U! C/ E9 l8 u' [  add ebx,eax, Q/ _" }' ^4 s5 h
  mov al,es:[si+6]3 [- t# P1 X8 G) B! m4 Z( D. B* H
  call Change$ O/ g# Z# `5 V
  mov cl,4
( V' [' i& B! g, o( H( C  shl ebx,cl
4 A8 v# C" _' Q0 o* B: @' l  add ebx,eax" T+ A' _, p6 _( R; g+ z
  mov al,es:[si+7]; V- f/ g- C8 a! @
  call Change
' D% s0 R( K8 g7 J% J* e  mov cl,4
7 Q& r6 r9 x2 g8 `  shl ebx,cl
' S* j0 `/ {0 R- H( t  add ebx,eax
2 n! _  ^- z8 _4 K( k  ret
( r; ?! r+ \% C1 k7 R: S3 kPSP endp
* ?/ b* @8 H' I# N% n1 H;------------------------------------------------------------------------------------------------
3 ^* C0 A3 [1 ?$ R- X7 gChange proc near
  t, ]- X" a% F0 U5 I/ RA:   8 J( S2 ?1 Z8 `+ }
  movzx eax,al
% t" |) k! p1 A7 y" Q& U! |  mov edx,eax
1 F8 T( N0 K7 C0 J4 `  cmp eax,'0'   
5 D1 ~( g( y: \: r- w9 t# m# z  jb A, ?/ W- R5 @* ~' v; f8 {2 Y
  cmp eax,'9'   
( X; j0 E. M1 f5 s  ja B- J7 M! h5 P, A  h& B
  sub eax,'0'
- c1 K0 k" O! @, `  jmp short E7 Z5 i, ^, y$ U/ C! f  a
B:
  L, H5 Y5 W0 O! v+ Y" K! h  and eax,0dfh   
0 [2 b' G! ]. K1 f+ N, h  mov edx,eax
3 ]* o  k. f3 @; Y* M) a( v  sub eax,37h   - _' g8 [4 r: ?; Z4 Q; V
  cmp eax,0ah
9 m) _2 W0 x( e; e! q1 E6 Q  jb A   
" V2 d& V; k# @$ P: O1 U: P  cmp eax,0fh' @/ j% `7 v- l4 Z* k
  ja A   ' D! n5 z) B" h0 K# {
E:
+ c& _4 X- Z" N4 c3 P. `. g+ k  push eax   
( D! O' i' Q0 \  t9 C1 w  call PRT   
& B6 Q  x4 g1 f1 u8 Q/ a% @4 ?  pop eax" |. j6 o- e+ T$ Q$ |0 Q5 g6 |
CExit:
) D2 K& N7 r' R5 C4 y: J  ret- e5 @" T9 m# f3 K* `
Change endp! P  O2 N4 s0 i+ z4 B+ D
;------------------------------------------------------------------------------------------------
! i& r* Z9 y, ^# s7 EPRT proc near2 r3 r& E  _0 h& t3 q
  mov ah,02h. l6 b( C/ y9 Q
  int 21h8 F0 L; z# Q0 r$ V
  ret
6 S; s6 b' B/ FPRT endp
) ~5 U2 b# a: P;------------------------------------------------------------------------------------------------
0 i6 a5 D, ?3 l, c) @0 pcrlf proc near" Q3 S9 T' S3 l0 q1 t
  mov ah,02h
2 t/ s/ _) v2 a+ b  mov dl,0dh8 \( }9 i/ J2 X( z( m: P. r
  int 21h% p# Z. _& k+ C, L- y* G
  mov ah,02h' v0 h: |( q# Y! O; Q
  mov dl,0ah
  R- D) d6 q# N/ [. S  int 21h
$ k0 s$ @( `# N9 ^  ret
  e  M! j- T) J) l  U* R" t' P& Icrlf endp0 a5 d- p  x& ]3 H# h
;------------------------------------------------------------------------------------------------
. F' }6 o/ B7 C5 p) ?+ j' G_32bits proc near. c; L! N0 g" k) ]) b- r
  pushad
+ k/ e4 \; V3 g# J  M  mov cl,4
% \1 q! R7 e0 n0 a( N" @  rol ebx,cl
% J8 G" a5 k$ c- E' I0 O/ O* a, M  call print_4_bits% g- ^  k' v  t/ }) L8 G+ h
  rol ebx,cl# u+ L6 P0 n8 Z' m3 W7 E
  call print_4_bits1 q; A0 |* y* _% h9 ]
  rol ebx,cl6 V  |) d/ ?8 I0 q0 V
  call print_4_bits
! J) n$ {- k* l1 u& _0 }  rol ebx,cl, Q5 ~- ]" J, R6 [( ~9 `
  call print_4_bits! |# h" \" t' l6 x" j! L
  rol ebx,cl
0 b1 e/ |! l4 ^, J; Q& M: _  call print_4_bits
6 v" u1 t" G: J7 Q  f! x+ E4 f  rol ebx,cl$ m3 B9 M: j9 G! q2 Z4 K
  call print_4_bits; g  h! o7 G7 i$ O" `* ~
  rol ebx,cl
7 z( p' `* U" C  call print_4_bits
$ N2 }0 \  O; }1 W. u1 d  rol ebx,cl
0 g: k- G$ P- o! A( Y+ n% _+ F  call print_4_bits
- ~2 v4 |, m' j' M  rol ebx,cl
: U% t  ~( O( |+ n( T8 c) E+ w  popad
# }5 E( C6 G* B8 D% }3 ?2 t  ret
" S& n6 _6 v# o1 j/ Z1 a_32bits endp' |4 w) t  U. _
;------------------------------------------------------------------------------------------------
( p) o; j1 }" l. ^_16bits proc near
8 E, z$ o2 S" @; q' j, r  pusha   8 J  i2 A+ Z" m- x% @* ^- Q
  rol bx,cl
5 V% W% i/ a, L5 \) |, A  }' T: }  call print_4_bits
$ u) ~5 v$ |+ b' y  rol bx,cl
% U4 O9 C7 P0 Z) `+ n! F, p  call print_4_bits
* S0 {- J" T( m  rol bx,cl
# f" s1 A3 w* Q6 m4 u0 V6 C* p  call print_4_bits
1 J. x& W% \/ y  rol bx,cl
- h; Q6 F- l% Y  call print_4_bits
- w, u4 e+ I& Q+ r+ T3 V  popa
8 s3 w$ ^1 G9 f* D* N* y  ret% t' k3 Q  T7 p8 w7 Z
_16bits endp( _' B4 f0 V5 t5 P
;------------------------------------------------------------------------------------------------
0 j6 k9 Q( q8 R0 E_8bits proc near8 s  V+ D+ i2 {" P' i" G
  pusha   , G# {" M. ^4 _
  rol bx,cl6 V: y/ c/ B# h7 W! r- a' Y7 X
  call print_4_bits
4 }3 d$ s% p  s  Q# W* h( w0 K  rol bx,cl. A% i) |8 k6 t, F& v, w6 q/ S0 W/ S. T
  call print_4_bits
/ D- u) H1 ?: B4 b- {  popa6 n5 q( ]$ l+ p; n+ c, @* H
  ret' w! P, w: k3 }$ ~; y& k
_8bits endp4 z  F* P! S) ?- p4 B' X
;------------------------------------------------------------------------------------------------. c& r# a- v0 i9 ~
print_4_bits proc near
9 A, Y' y7 Z) t6 U  mov dx,bx
2 A2 I4 Z$ ]1 m' x  and dl,0fh8 C& T( ~8 \) o9 X2 t; E- ~
  add dl,30h
  R  O, N& d4 B4 N% B  cmp dl,3ah
5 e" A- g" e. m) l' p! s. t+ g! c  jb print$ \9 ^- W* ^: F: I7 |
  add dl,77 x/ p; _. |, Q% U+ z* b2 {( x( `
print:   
0 u% X% E( b4 m1 [  L& P  mov ah,2
0 b- V& ^8 J: @% ]- x  int 21h
3 w* p- \+ d9 o: J; O; F7 P  ret8 H5 L, E* d7 n- X4 }: C. V
print_4_bits endp   , [2 Y" @+ t, z
;------------------------------------------------------------------------------------------------, Z( a4 S3 n! A9 W) n# q+ G/ r6 u
CSEG ends
& |3 P! T( }3 ]' IEND
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2026-3-5 15:55 , Processed in 0.053068 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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