tags:

views:

271

answers:

2

Hi, once again I'm doing MASM programming. I'm trying to write a procedure using the Irvine32 library where the user enters a string which is put into an array of BYTEs with ReadString. Then it loops over that arrray and determines if each character is a number. However, when I try

cmp [buffer + ecx], 30h

MASM complains about comparing two things that are not the same size. Is there anyway I could read the ASCII code in each BYTE in the array as a DWORD (or otherwise extract the ASCII value in each BYTE)?

+1  A: 

Does this work?

cmp BYTE PTR [buffer + ecx], 30h

To extract a BYTE as a DWORD you can do something like this:

mov EAX, 0
mov AL, [pointer]

or even better (thanks Martin):

movzx EAX, [pointer]
Nick D
@Martin, yes, better choice :)
Nick D
movzx eax, [pointer] is working but whenever I do movzx eax, [pointer + ecx] (since I'm getting more than one character inputs) it always puts just a zero into eax.
Help I'm in college
BYTE PTR [buffer + ecx] always evaluates to zero (where ecx is the number of items put into the buffer)For the record I'm beginning to suspect my professor isn't even trying to implement his ideas for programming assignments in MASM before he assigns them. We have done nothing with type conversions in MASM. I've learned more about assembly so far trying to figure out his assignments using the internet and stack overflow than I've learned in class.
Help I'm in college
@Help I'm in college, if buffer contains a null terminated string and ecx has string's length, then [buffer + ecx] will be zero.
Nick D
A: 
getData PROC
    push ebp
    mov ebp, esp
    mov esi, [ebp + 12] ; offset of buffer
    mov ebx, [ebp + 8] ; where to write answer

    GETNUMBERSTRING:
    mov edx, esi
    mov ecx, BufferSize
    mov eax, 0
    call ReadString

    mov ecx, eax ; set size to loop counter
    cld

    mov edx, 0
    PROCESSSTRING:
    lodsb

    cmp al, 30h
    jl WRONG
    cmp al, 39h
    jg WRONG

    ; add digit into total edx
    sub al, 30h
    push eax ; multiply edx by 10
    push ecx
    mov eax, edx
    mov ecx, 10
    mul ecx
    mov edx, eax
    pop ecx
    pop eax

    push ebx ; add to the total
    movsx ebx, al
    add edx, ebx
    pop ebx

    loop PROCESSSTRING
    jmp DONE

    WRONG:
    call Crlf
    stringWriterEndl invalid
    jmp GETNUMBERSTRING

    DONE:
    mov [ebx], edx
    pop ebp
    ret 8
getData ENDP

That's what I needed to do.

Help I'm in college