Author Topic: byte ptr comparison  (Read 19644 times)

Ryan

  • Guest
Re: byte ptr comparison
« Reply #30 on: June 10, 2012, 09:58:35 AM »
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--

  • Administrator
  • Member
  • ******
  • Posts: 7307
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: byte ptr comparison
« Reply #31 on: June 10, 2012, 12:56:26 PM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy: