0

So, from my understanding DB can be used to create a string in x86 Assembly. I am trying to move my index pointer to be at the beginning of the string so I can iterate through it. I am getting this error,

"instruction operands must be the same size"

So far I have tried using a doubleword which is the correct 32-bit size, but the issue with this is it says my string is too large for that definition. I'm confused as to how I can solve this.

.DATA
excerpt  db  "Follow. But! Follow only if ye be men of valour, for the entrance to this cave is guarded by a creature so foul, so cruel that no man yet has fought with it and lived! Bones of full fifty men lie strewn about its lair."
         db  "So, brave knights, if you do doubt your courage or your strength, come no further, for death awaits you all with nasty, big, pointy teeth. – Tim"     ; string
lenExcerpt  equ  $ - excerpt    ; length of string
compvar db "t"
compvar2 db "T"


.CODE

main PROC

mov ecx, 0
mov esi, excerpt
xor ebx, ebx
Suezzeus
  • 31
  • 4
  • 2
    `mov esi, offset excerpt` – Nate Eldredge Apr 23 '21 at 20:49
  • Oh okay, so this is just MASM specific issue. So by using offset var, it is now pointing to the address rather than the value? – Suezzeus Apr 23 '21 at 20:54
  • 3
    Phrases like "pointing to the address" are confusing. `mov esi, offset excerpt` will cause `esi` to contain the address of `excerpt`. When you write `mov esi, excerpt`, you are asking for `esi` to be loaded with the value of the dword that is in memory at address `excerpt`. In principle that would be a legal instruction, though not the one you want, but MASM rejects it because `excerpt` was declared as `db`, i.e. bytes. So it thinks that trying to load a dword from that address is probably not what you want (you'd have to say `DWORD PTR` to override it). – Nate Eldredge Apr 23 '21 at 20:57
  • Oh okay, I understand now. Thank you. – Suezzeus Apr 23 '21 at 20:59

0 Answers0