hi,


cmp , '1000'
jb somewhere


what condition must be met for the "jb" instruction to take place after the string comparison?
Posted on 2011-08-17 09:47:52 by hakand
Smells like homework.
The point of questions like these is not the answer itself, but how to deduce the answer.
So, figure out how conditional jumps work.
jb -> jump if below. Figure out what 'below' means. You'll find it in any x86 instructionset reference (such as here: http://siyobik.info/main/reference/instruction/Jcc)
Posted on 2011-08-17 10:59:18 by Scali
If it's homework, it's a terrible question! (the instructor flunks :) ) In view of previous questions from Hakand, I'd guess "not homework". But... will that even assemble? I'm used to Nasm, and this may be Masm(?), but... don't we need to know the size of the comparison? Is the byte at being compared? The word? The dword? Nasm would definitely need to know. Masm "remembers" more about sizes of variables, but I don't see that this applies in this case. Do we really want quotes around 1000? Looks like "questionable" code to me! What's the context, Hakand? Does this follow the "recv" in the other question, or what?

Best,
Frank

Posted on 2011-08-17 11:22:44 by fbkotler
no, it is not homework. i happened to see those lines in some source code. there are quotes around 1000. because it is a string with 4 characters. and cmp instruction compares the dword pointed by esi with this string.

if is '2000' (that is, the value pointed by esi) , will the program take the jump or not? when will it jump?
Posted on 2011-08-17 12:53:30 by hakand
If were '2000', the jmp would not be taken. I think there's a "syntax issue" here. Nasm treats a "character constant" without swapping bytes. That is, '1000' would be represented as 0x31303030. I think, not sure, that Masm would represent it as 0x30303031. So suppose were '0999' - 0x30393939... "below" 0x31303030 but "above" 0x30303031. Dunno. Run it through a debugger and see what the CPU's opinion is!

Best,
Frank

Posted on 2011-08-17 13:45:26 by fbkotler
Beacuse of this 'byte swapping' you can somewhat more intuitively compare string literals. TASM would assemble '1000' to 0x30 (LSB), 0x30, 0x30, 0x31 (MSB) (or 0x31303030 in hex, 825'241'648 in dec).
Posted on 2011-08-17 14:03:06 by ti_mo_n
Okay. Will Tasm assemble it without a size specified? (Nasm will not)

To put it terms of something I've actually done... searching environment variables for "HOME="... (Nasm syntax)


cmp dword , 'HOME'
jnz do_next
cmp byte , '='
jnz do_next
; got it


Am I wrong that Masm/Tasm would have to do 'EMOH"? Some controversy (obviously) as to which is "right". I find Nasm's way "convenient"...

Not as simple a question as it first appears!

Best,
Frank

Posted on 2011-08-17 14:32:05 by fbkotler