出于某种原因,WriteInt PROC
在我调用 my 之后它不起作用fibo PROC
,但如果我注释掉它可以打印数组fibo PROC
。整个程序运行,但从不打印值。以下是我正在使用的链接库:http: //kipirvine.com/asm/examples/IrvineExamplesVS2012.zip
我想知道为什么它不打印到控制台?这是我写的程序:
INCLUDE Irvine32.inc
printArray PROTO pArray:PTR DWORD, count:DWORD
.data
fiboNum DWORD 1,2,3,4,5,6,7,8,9,10
.code
main PROC
push LENGTHOF fiboNum
push 0
push OFFSET fiboNum
call fibo
Invoke printArray, ADDR fiboNum, LENGTHOF fiboNum
exit
main ENDP
fibo PROC
push ebp
mov ebp, esp
pushad
mov eax, [ebp + 12]
mov ecx, [ebp + 16]
cmp ecx, eax
je leaveNOW
cmp eax, 0 ; Does array need to be setup?
jne calc
push eax
mov eax, [ebp + 8] ; Setup array
mov DWORD PTR [eax], 1
mov DWORD PTR [eax + 4], 1
add ecx, 2
pop eax
calc:
mov ebx, [ebp + 8]
mov edx, [ebx]
add edx, [ebx + 4]
mov [ebx + 8], edx
lea ebx, [ebx + 4]
inc eax
push ecx
push eax
push ebx
call fibo
leaveNow:
popad
pop ebp
ret 12
fibo ENDP
printArray PROC USES ecx edx eax,
pArray:PTR DWORD,
count:DWORD
mov ecx, count
mov edx, pArray
L1:
mov eax, [edx]
call WriteInt
call CrLf
add edx, 4
loop L1
ret
printArray ENDP
END main
WriteInt PROC
在欧文链接库中:
;-----------------------------------------------------
WriteInt PROC
;
; Writes a 32-bit signed binary integer to the console window
; in ASCII decimal.
; Receives: EAX = the integer
; Returns: nothing
; Comments: Displays a leading sign, no leading zeros.
; Last update: 7/11/01
;-----------------------------------------------------
WI_Bufsize = 12
true = 1
false = 0
.data
buffer_B BYTE WI_Bufsize DUP(0),0 ; buffer to hold digits
neg_flag BYTE ?
.code
pushad
CheckInit
mov neg_flag,false ; assume neg_flag is false
or eax,eax ; is AX positive?
jns WIS1 ; yes: jump to B1
neg eax ; no: make it positive
mov neg_flag,true ; set neg_flag to true
WIS1:
mov ecx,0 ; digit count = 0
mov edi,OFFSET buffer_B
add edi,(WI_Bufsize-1)
mov ebx,10 ; will divide by 10
WIS2:
mov edx,0 ; set dividend to 0
div ebx ; divide AX by 10
or dl,30h ; convert remainder to ASCII
dec edi ; reverse through the buffer
mov [edi],dl ; store ASCII digit
inc ecx ; increment digit count
or eax,eax ; quotient > 0?
jnz WIS2 ; yes: divide again
; Insert the sign.
dec edi ; back up in the buffer
inc ecx ; increment counter
mov BYTE PTR [edi],'+' ; insert plus sign
cmp neg_flag,false ; was the number positive?
jz WIS3 ; yes
mov BYTE PTR [edi],'-' ; no: insert negative sign
WIS3: ; Display the number
mov edx,edi
call WriteString
popad
ret
WriteInt ENDP
编辑:
好的,所以我有点修复它,但我不知道为什么(特别是)。显然,当我从程序的一个过程中调用 WriteInt Proc 时,CheckInit 宏没有初始化控制台句柄。因此,我只是将 WriteInt 称为程序中的第一条指令,它正确设置了控制台句柄。不知道为什么它在我的过程中没有初始化控制台句柄。有人对它为什么会这样做有任何想法吗?
这是 CheckInIt 宏:
;-------------------------------------------------------------
CheckInit MACRO
;
; Helper macro
; Check to see if the console handles have been initialized
; If not, initialize them now.
;-------------------------------------------------------------
LOCAL exit
cmp InitFlag,0
jne exit
call Initialize
exit:
ENDM