请求验证ValidatePIN的错误输出之一

时间:2015-05-08 20:35:56

标签: if-statement assembly x86 irvine32

该程序工作正常,但samplepin_3的无效输出应为5,但显示4。我在这里错过了什么?

 ; 32-bit assembly language template

; INCLUDE Irvine32.inc

INCLUDELIB C:\Irvine\Kernel32.lib
INCLUDELIB C:\Irvine\Irvine32.lib
INCLUDE C:\Irvine\Irvine32.inc

pbyte typedef ptr byte                          ; pointer to bytes

.data
VALID_PIN = 0
PIN_SIZE = 5
minVals byte 5,2,4,1,3                  ; globally visible
maxVals byte 9,5,8,4,6                  ; globally visible
samplePin_1 byte 6,3,4,4,3              ; valid PIN
samplePin_2 byte 5,2,3,2,4              ; digit 3 is invalid
samplePin_3 byte 5,2,4,5,3              ; digit 5 is invalid
samplePin_4 byte 1,3,4,4,3              ; digit 1 is invalid

ptr1 pbyte samplePin_1                          ; points to array samplePin_1
ptr2 pbyte samplePin_2                          ; points to array samplePin_2
ptr3 pbyte samplePin_3                          ; points to array samplePin_3
ptr4 pbyte samplePin_4                          ; points to array samplePin_4
ptr5 pbyte minVals                              ; points to array minVals
ptr6 pbyte maxVals                              ; points to array maxVals

ValidPINMsg byte "The PIN is valid     ", 0    ;
InvalidPINMsg byte "The PIN is invalid.  The invalid digit is     ", 0 ;

.code
main proc

mov eax,VALID_PIN                  ; 

mov edi,ptr5
mov ebp,ptr6

mov esi,ptr1
call ValidatePIN                   ; determine whether or not the PIN is valid
.IF eax == 0
 mov edx,OFFSET ValidPINMsg
 call WriteString
 call WaitMsg
 call Crlf
.ELSE
 mov edx,OFFSET InvalidPINMsg
 call WriteString
 call WriteDec
 call WaitMsg
 call Crlf
.ENDIF

mov esi,ptr2
mov edi,ptr5
mov ebp,ptr6
call ValidatePIN                   ; determine whether or not the PIN is valid                       
.IF eax == 0
 mov edx,OFFSET ValidPINMsg
 call WriteString
 call WaitMsg
 call Crlf
.ELSE
 mov edx,OFFSET InvalidPINMsg
 call WriteString
 call WriteDec
 call WaitMsg
 call Crlf
.ENDIF

mov esi,ptr3
mov edi,ptr5
mov ebp,ptr6
call ValidatePIN                   ; determine whether or not the PIN is valid                       
.IF eax == 0
 mov edx,OFFSET ValidPINMsg
 call WaitMsg
 call Crlf
.ELSE
 mov edx,OFFSET InvalidPINMsg
 call WriteString
 call WriteDec
 call WaitMsg
 call Crlf
.ENDIF

mov esi,ptr4
mov edi,ptr5
mov ebp,ptr6
call ValidatePIN                   ; determine whether or not the pin is valid                       
.IF eax == 0
 mov edx,OFFSET ValidPINMsg
 call WriteString
 call WaitMsg
 call Crlf
.ELSE
 mov edx,OFFSET InvalidPINMsg
 call WriteString
 call WriteDec
 call WaitMsg
 call Crlf
.ENDIF

main endp

ValidatePIN PROC
 mov ecx,PIN_SIZE

 .REPEAT

mov al, byte ptr [esi]
.IF (al < [edi]) || (al > [ebp])
    neg ecx
    add ecx, 6
    jmp L1
.ELSE
 add esi,1
 add edi,1
 add ebp,1
.ENDIF

dec ecx    

.UNTIL ecx == 0

L1: 
 mov eax,ecx
 ret

ret
ValidatePIN ENDP
END main

0 个答案:

没有答案