0

So, I'm fairly new to assemlby. My task is to check for a substring in a string and print out yes/no answer. Both strings are put in by the user.

I have put offset of the string into bx register, offset of the substring into bp register. Using index numbers in di and si registers, I want to compare characters of my strings. Both of my index registers are set to 2, which should be the first character of the string.

mov dl,[bx+di]
mov al,[bp+si]
cmp dl,al
jz AnswerYes
jmp AnswerNo

I used this to compare first characters in each string.

When I put 'a' in both string, the program should jump to AnswerYes and print out 'yes'. When I print [bx+di] and [bp+si], it prints out 'a' for both of them, which means they are the same, but the program always jumps to AnswerNo.

If I do this:

cmp dl,'a'

it prints our yes, meaning they are the same.

When I do this:

cmp al,'a'

it prints out no, even though they are the same.

I suspect the problem is with me using bp register, since I've never used it before. I always used only one string in my program, for which I always used bx register.

Thanks for help in advance.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
user3249071
  • 1
  • 1
  • 1
  • 1
    I believe your assumption is correct. The use of BP implies a stack-based buffer. You could test this yourself by using e.g. CX instead of BP. – 500 - Internal Server Error Jan 29 '14 at 14:05
  • Using CX instead of BP gives me 'Illegal indexing node' error, so I can't use [cx+si]. Is there any other combination of registers (like [bx+di]) which I could use for offset of the string and index number? – user3249071 Jan 29 '14 at 14:12
  • `Illegal indexing node` - is that the precise error? Hmm. It's been decades since I coded 16-bit assembler so the precise constraints on that platform are but a faint memory. I guess that's going to be the case for a lot of people. That's why you need the book - or you may want to try and google for some x86 samples. – 500 - Internal Server Error Jan 29 '14 at 14:16
  • Ehm, I just realized, why bother using registers to store offsets my string? I can just use [offset Substring + si].. I'm going to try that out. – user3249071 Jan 29 '14 at 14:42
  • You can find a list of the valid register/offset combinations for effective addresses in section 2.1.5 of Intel's Software Developer's Manual Vol 2. – Michael Jan 29 '14 at 15:02

0 Answers0