分析/过滤masm32中按字符输入的字符串

时间:2017-10-18 00:22:32

标签: assembly masm32

我试图从一个用户获取一个单词(大小)数组的值,但只接受不会太大而且是数字的值(0-9,-32768到32767)。我对masm很新,所以我用Google搜索了一下,以为我理解了一种检查每个字符的方法,但它没有用完。到目前为止我所拥有的是:

.data
...
strInput    byte    7 dup(?)            ;used to store user input
                                        ;6 available chars + null
.code
...
userInput:
    ...code that converts strInput ascii to int and puts it in eax...
    cmp eax, 32767       ;compare input to max positive word size
    jg exceedsBounds     ;jump to error message
    cmp eax, -32768      ;compare input to max negative word size
    jl exceedsBounds     ;jump to error message 
    mov iVal, eax        ;store value in signed placeholder
    mov esi, 0           ;use esi as a counter, set it to 0
    jmp checkChars       ;go to inspect chars

checkChars:
     mov al, strInput[esi]  ;grab the byte at esi
                   ;input method stores each char as a byte capped by null
     inc esi                ;move to next byte
     cmp al, 0              ;check if at the end (null cap)
     jmp goodEntry          ;if at end, it's good
     cmp al, 45             ;compare to minus sign
     je minus               ;jump to minus handler (checks for multiples)
     cmp al, 57             ;compare to "9"
     jg invalidChar         ;if al is greater than ascii 57, invalid
     cmp al, 49             ;compare to "0"
     jl invalidChar         ;if al is less than ascii 49, invalid
     jmp checkChars         ;loop back to check next char

在我的脑海中,strInput是ascii,所以如果我比较表值它应该工作,但是没有checkChars跳转正在工作。关于我在这里误解的任何线索?

0 个答案:

没有答案