News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

New to MASM. Problem getting CMP to work

Started by SteveB, September 15, 2012, 08:13:34 AM

Previous topic - Next topic

SteveB

Hello,

I'm learning MASM.  I am trying to get a basic CMP instruction to work.  The code currently copies the characters into the registers but the CMP instruction has no effect.  Sorry if it's basic, but I've been banging my head against a brick wall with it.  The code is copied below:-

.386
.model flat, stdcall
option casemap :none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\masm32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\masm32.lib

.data
    TopTitle db "File Reading Project", 0
    TestStr  db "String not found",0
   
.data?
    thandle  dd  ?         ;variable for the filehandle
    ansa     dd  ?
    temp     dd  ?
   
.code

start:

        mov esi, offset TopTitle    ;load address of string
        mov ebx, "i"
       
tloop:

        xor ecx, ecx               
        mov cl, [esi]               
        inc esi     

        invoke dw2hex, ecx, offset ansa
        invoke MessageBox, NULL, addr ansa, addr TopTitle, MB_OK
           
        invoke dw2hex, ebx, offset ansa
        invoke MessageBox, NULL, addr ansa, addr TopTitle, MB_OK
       
        cmp ecx, ebx
        je tstbx
        jne tloop

tstbx:
        invoke MessageBox, NULL, addr TestStr, addr TopTitle, MB_OK                   

        invoke ExitProcess, 0
end start

jj2007

Hi Steve,
Welcome to the Forum :icon14:

ecx is a "trashable" register for Windows APIs, therefore you need to preserve it before an API call:

    TestStr  db "String found",0
...       
tloop:
   xor ecx, ecx               
   mov cl, [esi]               
   inc esi     
   push ecx
   invoke dw2hex, ecx, offset ansa
   invoke MessageBox, NULL, addr ansa, addr TopTitle, MB_OK
   pop ecx
   cmp ecx, ebx
   je tstbx
   jne tloop

Check my signature for more info.

Cheers, JJ

SteveB