News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

byte ptr comparison

Started by Ryan, June 08, 2012, 10:43:10 PM

Previous topic - Next topic

Ryan

Um... the thread was an inquiry about how cmpsb compares two byte pointers.  I wanted to know if I could use similar logic to keep a register open for other use.

hutch--

Ryan,

If you use CMPS you must use the registers it requires, if you perform the comparison using lower level mnemonics you have more freedom to choose the registers you have available. If you look up the Intel manual you will see that you must use the source index ESI and the destination index EDI to perform the comparison and used in conjunction with the REP prefix. Byte counts MUST be done in ECX.

From the manual,

Quote
The CF, OF, SF, ZF, AF, and PF flags are set according to the temporary result of the comparison.

I have tried to warn you that using CMPS is buying into old DOS junk and an antique architecture. In the 8088 - 8086 days you had no choice, with the advent of 32 bit on 486 and later you are free of these restrictions.

What you write has some to do with what you are after, if you are performing a normal scan for text, you normally load the 1st character of the text into a register then scan through the text data you are searching to find a single character match. When you find a character match you branch to another loop to compare the rest of the characters in the text being searched for. If it matches the search text you exit with the start offset of the result, else you return to the main loop and keep scanning the text being searched.

If you are performing a text comparison, you load both addresses and compare them byte by byte.