flat assembler
Message board for the users of flat assembler.

Index > Main > Problem with [text] or text

Author
Thread Post new topic Reply to topic
freeze



Joined: 27 Oct 2004
Posts: 3
freeze
forgive me for being stupid. Sad , please be patient with me
I just started to learn assembly using flat assembler.

1.
Code:
org 256 ; offset addressing by 256 bytes
mov ah,2 ; value 2 in ah
mov dl,[text] ; load byte value form offset text now = 'a' into dl
int 21h ; dos function call ah=2h
int 20h ; exit to dos
text db 'a' ; declare byte a
    


2.
Code:
org 256 ; offset addressing by 256 bytes
mov ah,9 ; value 9 in ah
mov dx,text ; load word address of text into dx
int 21h ; dos function call ah=9h
int 20h ; exit to dos
text db 'hello world$' ; declare byte array with end symbol for dos function
    


3.
Code:
org 256 ; offset addressing by 256 bytes
mov ah,9 ; value 9 in ah
mov dx,[address_of_text]
int 21h ; dos function call ah=9h
int 20h ; exit to dos
text db 'hello world$' ; declare byte array with end symbol for dos function
address_of_text db 'text$'
    


why in no.1 when we assing dl with label 'text' we have to dereference it (using []) but you can assign dx with address of label 'text' in no.2 while in no.3 you must dereference it again
can someone explain to me?
Post 27 Oct 2004, 05:04
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
Hy freeze
comments by me, hope i have answered your question.
Post 27 Oct 2004, 06:21
View user's profile Send private message Visit poster's website Reply with quote
freeze



Joined: 27 Oct 2004
Posts: 3
freeze
Matrix wrote:
Hy freeze
comments by me, hope i have answered your question.


thank you Matrix,
but ...
Code:
org 256 ; offset addressing by 256 bytes 
mov ah,9 ; value 9 in ah 
mov dx,[address_of_text] 
int 21h ; dos function call ah=9h 
int 20h ; exit to dos 
text db 'hello world$' ; declare byte array with end symbol for dos function 
address_of_text db 'text$'    

can't be compiled
maybe it should
Code:
org 256
mov ah,9
mov dx,[address_of_text]
int 21h
int 20h
text db 'hello world$'
address_of_text dw text    


I could understand this if I assume that 'mov ah,9' needs an address as an input, while 'mov ah,2' needs an ascii code as an input, right? Confused
Post 27 Oct 2004, 07:14
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
Helo there,
yeah, you're right, i see you're getting it.

if you wnna put address of string to dx you needn't declare its offset first Smile
however i used to do it somtimes even with procedures, this way you can use an index instead of variable name.
You're on the right track if you write a vesatest program for example which indexes the messages to be written.
Code:
org 256 ; offset addressing by 256 bytes  
mov ah,9 ; value 9 in ah  
mov dx,address_of_text
int 21h ; dos function call ah=9h  
int 20h ; exit to dos  
text db 'hello world$' ; declare byte array with end symbol for dos function  
address_of_text db 'text$'
    


this is another thing but you didn't mean this i think:

Code:
org 256 ; offset addressing by 256 bytes
mov ah,9 ; value 9 in ah
mov dx,address_of_text
mov cx,[difference]
add dx,cx
int 21h ; dos function call ah=9h
int 20h ; exit to dos
text db 'hello world$' ; declare byte array with end symbol for dos function
address_of_text: db 'Your message here$'
address_of_text2: db 'Hy , how could this be? Smile$'
difference: dw address_of_text2-address_of_text
    


however you can force using [] with strings like:
Code:
org 256 ; offset addressing by 256 bytes
mov ah,9 ; value 9 in ah
mov dx,word [address_of_text-2]
int 21h ; dos function call ah=9h
int 20h ; exit to dos
text db 'hello world$' ; declare byte array with end symbol for dos function
pre_address_of_text dw address_of_text
address_of_text db 'text$'
    
Post 27 Oct 2004, 09:50
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
hey, seems like from my tutorial Wink

well, your code seems right, but name of variable should describe contents of variable, so "address_of_text" should hold ADDRESS of text, not text itself.
Post 27 Oct 2004, 11:11
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
freeze



Joined: 27 Oct 2004
Posts: 3
freeze
Thank you Matrix
m(_ _)m
now I can understand it.
Post 28 Oct 2004, 00:42
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. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.