reading a BYTE as a DWORD in Masm
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. H开发者_开发问答owever, 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)?
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]
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.
精彩评论