flat assembler
Message board for the users of flat assembler.

Index > DOS > what is wrong with using [es:cx] ?

Author
Thread Post new topic Reply to topic
dvlfrnd



Joined: 09 Mar 2007
Posts: 15
dvlfrnd 11 Mar 2007, 14:00
i am sorry if this exists somewhere in the forum,but i couldn't find it.
can anyone point out why this happens,it sure looks like something i should know:

i found this sample of code on a website(extracting the related part):
Code:
  mov al,1
  mov bx,0
  mov cx,64000

startloop:
  mov [es:bx],al
  inc bx 
  loop startloop
    


however,it didn't make sense to me,so i changed it:
Code:
  mov al,1
  mov cx,64000
startloop:  
  mov [es:cx],al
  loop startloop
    


it didn't work,and threw this error :
Code:
reserved word used as symbol.    


so i changed it into:
Code:
  mov al,1
  mov cx,64000
startloop:
  mov bx,cx
  mov [es:bx],al
  loop startloop
    


and it worked,
what is wrong with using [es:cx] ?
Post 11 Mar 2007, 14:00
View user's profile Send private message Reply with quote
tantrikwizard



Joined: 13 Dec 2006
Posts: 142
tantrikwizard 11 Mar 2007, 14:29
You cannot use every register as a displacement in 16 bit code, only in 32 bit code can you do this. Displacement registers in 16 bit code are BX, SI, DI, SP and BP. This is not a DOS limitation, it's by design of the processor when not running in protected mode.
Post 11 Mar 2007, 14:29
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
dvlfrnd



Joined: 09 Mar 2007
Posts: 15
dvlfrnd 11 Mar 2007, 14:41
i see,
Thank you very much for your explanation tantrikwizard
Post 11 Mar 2007, 14:41
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 11 Mar 2007, 15:59
Code:
mov ax, [bx+bx]    

Error reported by fasm: "invalid address"
Code:
mov ax, [es:cx]    

Error reported by fasm: "reserved word used as symbol"

Why fasm doesn't report "invalid address" for the last one too?
Post 11 Mar 2007, 15:59
View user's profile Send private message Reply with quote
tantrikwizard



Joined: 13 Dec 2006
Posts: 142
tantrikwizard 11 Mar 2007, 16:15
LocoDelAssembly wrote:
Why fasm doesn't report "invalid address" for the last one too?

Not sure, its something to do with the stage of compilation that produces the error. In either case it's invalid in 16 bit code.
Code:
mov ax, [bx+bx]    

This is using Index+Displacement addressing, it can be achieved in 16 bit code using:
Code:
add bx, bx
mov ax, [bx]    

valid 16 bit addressing modes are (from intel manual):
[BX + SI]
[BX + DI]
[BP + SI]
[BP + DI]
[SI]
[DI]
disp16
[BX]
[BX+SI]+disp8
[BX+DI]+disp8
[BP+SI]+disp8
[BP+DI]+disp8
[SI]+disp8
[DI]+disp8
[BP]+disp8
[BX]+disp8
[BX+SI]+disp16
[BX+DI]+disp16
[BX+SI]+disp16
[BX+DI]+disp16
[SI]+disp16
[DI]+disp16
[BP]+disp16
[BX]+disp16

I erronously said SP could be used as an addressing mode in 16 bit code in the previous post.
Post 11 Mar 2007, 16:15
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Goplat



Joined: 15 Sep 2006
Posts: 181
Goplat 11 Mar 2007, 16:42
dvlfrnd: Your two code samples are not equivalent, the first one fills addresses 0 to 63999, the other does 1 to 64000.
Post 11 Mar 2007, 16:42
View user's profile Send private message Reply with quote
dvlfrnd



Joined: 09 Mar 2007
Posts: 15
dvlfrnd 11 Mar 2007, 17:06
Quote:
dvlfrnd: Your two code samples are not equivalent, the first one fills addresses 0 to 63999, the other does 1 to 64000.

oh,yes i haven't noticed it,thanks Very Happy
Post 11 Mar 2007, 17:06
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 11 Mar 2007, 17:57
tantrikwizard, both codes was just an example to trigger the error messages, I'm not really needing "mov ax, [bx+bx]" to get working Razz

I'll not tell that reporting "reserved word used as symbol" when things like [bx+cx] (no need for segment override to trigger the same error message) appears, but I think that it misguide the unprevented programmer. A "invalid address" or "invalid addressing" are more appropiate IMHO.
Post 11 Mar 2007, 17:57
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.