If statement 关于ValidatePIN的一个错误输出的请求

If statement 关于ValidatePIN的一个错误输出的请求,if-statement,assembly,x86,irvine32,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

程序工作正常,除了
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
;32位汇编语言模板
; 包括Irvine32.inc
INCLUDELIB C:\Irvine\Kernel32.lib
INCLUDELIB C:\Irvine\Irvine32.lib
包括C:\Irvine\Irvine 32.inc
pbyte typedef ptr字节;指向字节的指针
.数据
有效_PIN=0
引脚尺寸=5
最小字节5,2,4,1,3;全球可见
最大字节9,5,8,4,6;全球可见
样本1字节6,3,4,4,3;有效PIN码
样本引脚_2字节5,2,3,2,4;数字3无效
samplePin_3字节5,2,4,5,3;数字5无效
样本引脚_4字节1,3,4,4,3;数字1无效
ptr1 pbyte样本1;指向阵列样本针1的点
ptr2 pbyte样本2;指向阵列样本针2的点
ptr3-多核细胞样本3;指向阵列样本针3的点
ptr4单核细胞样本4;指向阵列样本引脚4的点
ptr5微字节;指向数组最小值的点
ptr6字节最大值;指向数组最大值的点
ValidPINMsg字节“引脚有效”,0;
InvalidBinMsg字节“PIN无效。无效数字为”,0;
.代码
主进程
mov eax,有效的_引脚;
mov edi,ptr5
mov ebp,ptr6
movesi,ptr1
调用ValidatePIN;确定PIN码是否有效
。如果eax==0
mov edx,偏移量ValidPINMsg
通话记录
打电话给WaitMsg
呼叫Crlf
其他的
mov edx,偏移量无效
通话记录
通话记录
打电话给WaitMsg
呼叫Crlf
.ENDIF
movesi,ptr2
mov edi,ptr5
mov ebp,ptr6
调用ValidatePIN;确定PIN码是否有效
。如果eax==0
mov edx,偏移量ValidPINMsg
通话记录
打电话给WaitMsg
呼叫Crlf
其他的
mov edx,偏移量无效
通话记录
通话记录
打电话给WaitMsg
呼叫Crlf
.ENDIF
mov esi,ptr3
mov edi,ptr5
mov ebp,ptr6
调用ValidatePIN;确定PIN码是否有效
。如果eax==0
mov edx,偏移量ValidPINMsg
打电话给WaitMsg
呼叫Crlf
其他的
mov edx,偏移量无效
通话记录
通话记录
打电话给WaitMsg
呼叫Crlf
.ENDIF
mov esi,ptr4
mov edi,ptr5
mov ebp,ptr6
调用ValidatePIN;确定pin码是否有效
。如果eax==0
mov edx,偏移量ValidPINMsg
通话记录
打电话给WaitMsg
呼叫Crlf
其他的
mov edx,偏移量无效
通话记录
通话记录
打电话给WaitMsg
呼叫Crlf
.ENDIF
主端
验证程序
mov ecx,引脚尺寸
.重复
mov al,字节ptr[esi]
.IF(al<[edi])| |(al>[ebp])
负ecx
添加ecx,6
jmp-L1
其他的
添加esi,1
添加edi,1
添加ebp,1
.ENDIF
12月ecx
.直到ecx==0
L1:
mov-eax,ecx
ret
ret
血管内皮素
端干管

那是因为计算机可以计数。数字#4无效,它恰好是一个
5
,但您打印了基于1的索引,因此
4
是完全正确的。是的,但我不知道如何将
samplePin_3
的无效输出变成
5
。让我再说一遍,
4
是正确的答案。。。使其成为
5
的唯一方法是将
samplePin_3
中的数据更改为
samplePin_3字节5,2,4,3,5
对不起,我不明白。如果比较
minVals
maxVals
之间的
samplePin_3
值,则只有
5
无效。它不应该是
5
而不是
4
?您的代码打印的是错误值的索引(位置),而不是值本身(与消息相反)
5
是错误的值,但它位于位置
4
,因此打印
4
。您很幸运,对于
samplePin_2
samplePin_4
而言,索引和值匹配(数字
3
是第三位,数字
1
是第一位)。