flat assembler
Message board for the users of flat assembler.

Index > DOS > memory access with dx

Author
Thread Post new topic Reply to topic
realcr



Joined: 02 Apr 2007
Posts: 39
realcr
I wanted to test the fasm for dos assembler , so I wrote this simple code:
Code:

format MZ

      push    cs
  pop     ds

label1:
       mov dx,label1
       mov ax,[dx]

     mov     ax,4C00h
    int     21h

    


and I get:

Code:
D:\programs\FASM16~1>fasm testf.asm
flat assembler  version 1.67.21  (15360 kilobytes memory)
testf.asm [11]:
        mov ax,[dx]
error: reserved word used as symbol.
    


I don't understand what the assembler tells me.
When I tried it with si instead of dx , it worked.
Am I doing something wrong?

realcr.
Post 23 Jun 2007, 11:30
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
"dx" cannot be used to address memory in 16 bit code.

the error message in this case is very bad, i agree
Post 23 Jun 2007, 11:44
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
realcr



Joined: 02 Apr 2007
Posts: 39
realcr
thanks vid.

Someone told me to try it in masm and see if it works.
I wrote this code:


Code:
.model small
.stack 100
.data
    CLRF    db  13,10,'$'
    MSG     db  'passed the writing test!$'
.code
MAIN   Proc
        mov     AX,@Data
        mov     DS,AX
        
   mov     AH,9
        lea     DX,CLRF
        INT     21H
    label1:
   mov si,label1           ; load the label's location
        mov word ptr [si],1337h ; try to write to memory

        mov ax,1337h            
            cmp [si],ax             ; check the memory write
            jnz exit2

       ; if we get here it means the write to memory
       ; was successful 
        mov     AH,9
        lea     DX,MSG             ; load the message
        INT     21H               ; print the message to screen
        
   mov     AH,9            ; print the crlf thingy
        lea     DX,CLRF
        INT     21H

    exit2:
                             ; if we get here we exit the program

        mov     AH,4CH
        INT     21H

MAIN    Endp
End     MAIN
    



and I got:

Code:

C:\>test.exe

passed the7<riting test!

    


and we all know that 0x37 is the char "7" , which proves it is somehow possible.
Post 23 Jun 2007, 12:55
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
Goplat



Joined: 15 Sep 2006
Posts: 181
Goplat
Nowhere in that MASM example did you actually do a memory access with DX. It worked because you used SI.
Post 23 Jun 2007, 21:27
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Code:
   mov word ptr [si],1337h 
    


Please delete the MA$M code from your post. It's unnecessarily long and not related to the issue at all Confused

Code:
   use16
   org $100

   mov ax,[bx]
;  mov ax,[dx]
   mov ax,[bp]
   mov ax,[si]
   mov ax,[di]
   ud2
    


Quote:

"dx" cannot be used to address memory in 16 bit code.
the error message in this case is very bad, i agree


Right.

Should be:

Code:
Only BX, BP, SI, and DI can be used for indexing in 16-bit code
    

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 23 Jun 2007, 22:55
View user's profile Send private message Reply with quote
realcr



Joined: 02 Apr 2007
Posts: 39
realcr
I'm sorry for sending the wrong masm32 example,
However it does work with masm if you replaec the si with dx.

I tried to see the output in olly , and I fould out that masm actually moves dx into si , and then restores it , just in order to do the memory operation.

So you were right about not being able to use dx.

Thanks for help,
realcr.
Post 26 Jun 2007, 17:03
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
realcr wrote:

I tried to see the output in olly , and I fould out that masm actually moves dx into si , and then restores it , just in order to do the memory operation.

And that is a thing that an assembler shouldn't be doing, imho - ugly. One thing is if things happen "behind your back" when you use macros, but instructions should never be "magicified" like that.

Oh, and please call the assembler "MASM" and not "masm32" - the former is the name of the assembler, the latter is the name of that particular Australian's hodgepodge package.

_________________
Image - carpe noctem
Post 26 Jun 2007, 22:30
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Quote:
that masm actually moves dx into si


NOT amused Sad
Post 28 Jun 2007, 00:59
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-2020, Tomasz Grysztar.

Powered by rwasa.