幫忙將下面16bit匯編改成32bit匯編。測試成功後再加200分酬謝,絕不食言。謝謝
lypp 2003-08-26 09:35:20 PAGE 66,132
OPTION segment:use16 ; This directive should be placed before .386P so that the default segment size will be 16 bits
OPTION OFFSET:GROUP ; Default
OPTION CASEMAP:NONE
.386P
.MODEL LARGE, C
DGROUP GROUP _DATA,CONST,STACK
PAGE
;+===========================================================================+
;| Structure |
;+===========================================================================+
IMAGE STRUCT
wWidth WORD ?
wHeight WORD ?
wColorBit WORD ?
wWidthPixel WORD ?
wHeightPixel WORD ?
acMap BYTE 0 DUP(?)
IMAGE ENDS
PAGE
;+===========================================================================+
;| Macro |
;+===========================================================================+
PAGE
;+===========================================================================+
;| Constant |
;+===========================================================================+
;***********
;
;***********
BPT TEXTEQU <BYTE PTR>
WPT TEXTEQU <WORD PTR>
DPT TEXTEQU <DWORD PTR>
FALSE EQU 1 eq 0
TRUE EQU 1 eq 1
NO EQU FALSE
YES EQU TRUE
;***********
;
;***********
CONST SEGMENT PUBLIC 'CONST'
g_adwColor LABEL DWORD
DWORD 000000000h
DWORD 000000001h
DWORD 000000100h
DWORD 000000101h
DWORD 000010000h
DWORD 000010001h
DWORD 000010100h
DWORD 000010101h
DWORD 001000000h
DWORD 001000001h
DWORD 001000100h
DWORD 001000101h
DWORD 001010000h
DWORD 001010001h
DWORD 001010100h
DWORD 001010101h
CONST ENDS
PAGE
;+===========================================================================+
;| Global variable |
;+===========================================================================+
_DATA SEGMENT PUBLIC 'DATA'
;uffer DWORD 0CC88CC88h
_DATA ENDS
PAGE
;+===========================================================================+
;| Stack |
;+===========================================================================+
STACK SEGMENT STACK 'STACK'
; BYTE 100h DUP(0)
STACK ENDS
PAGE
;+===========================================================================+
;| Program |
;+===========================================================================+
_TEXT SEGMENT PUBLIC 'CODE'
ASSUME cs:_TEXT
ASSUME ds:DGROUP
Begin:
ConvertColorPlane \
PROC USES eax bx ecx dx si di ds es, \
lpsDst:DWORD, \
lpsSrc:DWORD, \
wWidth:WORD
LOCAL adwColor[16]:DWORD, \
wIndex:WORD, \
wLoopOfLine:WORD, \
wLoopOf8Bit:WORD
;***********
; Move color table to stack for easy process
;***********
mov ax,DGROUP ; Prepare segment register
mov ds,ax
sub si,si
mov cx,16
@@:
mov eax,g_adwColor[si] ; Must use si as index register
mov adwColor[si],eax ; If use bx, it will be "Error A2029: multiple base registers not allowed"
add si,4
loop @B
;***********
;
;***********
lds bx,lpsSrc ; Source bit map
les di,lpsDst ; Destination bit map
mov ax,wWidth ; wIndex = wWidth * 2 / 8
shr ax,2 ; 2 Pixels in 1 byte in original bit map
mov wIndex,ax ; 8 Pixels in 1 byte in converted bit map - Each byte represent a color plane
mov wLoopOfLine,ax ; Loop n of 8-bit per scan line
_CCP_010:
mov wLoopOf8Bit,4 ; Loop 8-bit (4 bytes) in a scan line
sub eax,eax
_CCP_020:
sub dx,dx
mov dl,[bx] ; Fetch 1 byte of bit map
mov si,dx
and si,000F0h ; Fetch 1st pixel in the high 4-bit
shr si,2 ; Adjust for DWORD
mov ecx,adwColor[si]
shl eax,1
or eax,ecx
mov si,dx
and si,0000Fh ; Fetch 2nd pixel in the low 4-bit
shl si,2 ; Adjust for DWORD
mov ecx,adwColor[si]
shl eax,1
or eax,ecx
inc bx ; Point to the next byte of source bit map
dec wLoopOf8Bit
jnz _CCP_020
push bx
mov es:[di],al ; Store color plane 0 to destination bit map
mov bx,wIndex
mov es:[di][bx],ah ; Store color plane 1 to destination bit map
shr eax,16
add bx,wIndex
mov es:[di][bx],al ; Store color plane 2 to destination bit map
add bx,wIndex
mov es:[di][bx],ah ; Store color plane 3 to destination bit map
pop bx
inc di ; Point to the next byte of destination bit map
dec wLoopOfLine
jnz _CCP_010
ret
ConvertColorPlane \
ENDP
END ;egin