1

This time I have a simple question, how do I access a specific byte in memory?

I've tried:

mov cx, addr_seg

mov es, cx

mov cx, addr_off

mov bx, [es:cx]

But this simply gives me "invalid effective address", so I assume I've done something wrong.

Can somebody please tell me how to do this? Thanks in advance.

Alexey Frunze
  • 61,140
  • 12
  • 83
  • 180
codesmith
  • 561
  • 1
  • 3
  • 17
  • possible duplicate of [invalid effective address calculation!](http://stackoverflow.com/questions/2809141/invalid-effective-address-calculation) – Jens Björnhager Jan 29 '13 at 03:16
  • Vol. 2A of the same manual lists possible ways for addressing a memory operand in 16-bit mode in Table 2-1. 16-Bit Addressing Forms with the ModR/M Byte. – Alexey Frunze Jan 29 '13 at 03:30
  • Thanks for pointing me to this, I will definitely use it in the future. I am wondering though, does table 2-1 _not_ show [es:si] as a valid way to address memory? – codesmith Jan 29 '13 at 12:00

1 Answers1

1

After some messing around with the code after google, my textbook, etc. I've come up with a fairly surprising solution...

Apparently, the only problem is that I'm referencing the address through [es:cx]. It works through [es:si], so I guess that there is a difference in cx and si in the actual addressing scheme.

Huh, learn something new every day.

codesmith
  • 561
  • 1
  • 3
  • 17
  • 1
    `mov bx, [es:si]` fetches a word (16 bits). If you really want to access a single byte, `mov bl, [es:si}` (or any 8-bit register for destination). Note that 32-bit addressing modes are MUCH more flexible: `mov bl, [es:ecx]` works fine. – Frank Kotler Jan 29 '13 at 12:55
  • Thanks for the explanation, the solution definitely left me confused as to the answer. – codesmith Jan 29 '13 at 21:52
  • If you answered your own question, please select your answer as the accepted solution – Philipp Nov 30 '16 at 15:03