flat assembler
Message board for the users of flat assembler.

Index > Main > How can DB contain string?

Author
Thread Post new topic Reply to topic
Kristian_



Joined: 13 Nov 2004
Posts: 38
Kristian_
Hi!
As far is I know one byte can contain one letter right? So how can I define db and string and getaway with this? And another thing, I have a little problem with me code here, I can't copy value from one register to another:

Code:
   ORG 256   MOV AH, 9    MOV AX, 5   MOV [variable], AX   MOV DX, [variable]   INT 21h      INT 20h     variable db 10    

I get error on this: MOV DX, [variable]
It say's that size doesn't match!! What is wrong? And last question! What is the deference between variable and constant? Thank you!
Post 14 Nov 2004, 12:23
View user's profile Send private message Reply with quote
roticv



Joined: 19 Jun 2003
Posts: 374
Location: Singapore
roticv
The data in [variable] is byte size while the data in ax is word size. How can you move a 16bit value into a 8bit value? Of course the size does not match

The difference between a variable and a constant is that the value in a variable can change, but the value in the a constant is always the same.
Post 14 Nov 2004, 12:33
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
Hy again,
Code:
org 256 ; originate variables and generate a com file
mov dx,word [vart] ; now we will put $4421 in dx

mov dx,string_byte_array ; this puts offset in for dos function
mov ah,9 ; int 21h ah = 9h parameter
int 21h

int 20h ; exit
vart db $21
db $44

string_byte_array: db 'Hello World!$' ; dos string terminator is '$', some use #0 , some are pascal typed beginning has lenght
    
Post 14 Nov 2004, 16:05
View user's profile Send private message Visit poster's website Reply with quote
Kristian_



Joined: 13 Nov 2004
Posts: 38
Kristian_
Thank you very much!
I have another question about labels!
for example I want to test if var1 = var2, so I write this code:

Code:
org 256mov ah, 9mov ax, var1mov bx, var2cmp ax, bx               ;       if(ax == bx){je somelabel                ;       goto somelabel; } else {jmp end                     ;       goto end; }somelabel:              ; how can I know where does label ends?mov dx, trueint 21hint 20hend mov dx, falseint 21hint 20hvar1 db 1var2 db 1true db "TRUE$"false db "FALSE$"    

After I compile and execute this code, program like waits for something, when I press any key it goes back to command line! What is wrong? And how can I know where does label ends? And about fasm tutorials! I read this one from http://decard.net/ Where can I find more? Thank you!
Post 14 Nov 2004, 17:25
View user's profile Send private message Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4
Kristian_ wrote:
Thank you very much!
I have another question about labels!
for example I want to test if var1 = var2, so I write this code:

Code:
org 256mov al, [var1]  ; < [ ]mov bl, [var2]  ; < [ ]cmp al, bl                  ;       if(al == bl){je somelabel           ;       goto somelabel; } else {jmp end                     ;       goto end; }somelabel:              ; how can I know where does label ends?mov ah, 9          ; <mov dx, trueint 21hint 20hend:       ; < :mov ah, 9   ; <mov dx, falseint 21hint 20hvar1 db 1var2 db 1true db "TRUE$"false db "FALSE$"     

After I compile and execute this code, program like waits for something, when I press any key it goes back to command line! What is wrong? And how can I know where does label ends? And about fasm tutorials! I read this one from http://decard.net/ Where can I find more? Thank you!


\\\\||////
(@@)
ASHLEY4.

Batteries not included, Some assembly required.
Post 14 Nov 2004, 17:47
View user's profile Send private message Reply with quote
Kristian_



Joined: 13 Nov 2004
Posts: 38
Kristian_
Thank you!
But how does FASM know where does label ends? Isn't label something similar to macro? For example macro starts with { and after end of the macro body there is } What about label? Thank you!
Post 14 Nov 2004, 21:49
View user's profile Send private message Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4
You may be mix up labels, with proc, look here for info on how labels work in fasm.
http://www.decard.net/index.php?body=tajga&chapter=chap03

\\\\||////
(@@)
ASHLEY4.

Batteries not included, Some assembly required.
Post 15 Nov 2004, 00:25
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
to give an accurate and complete answer to your question: How can DB contain string?

db is not containing the string itself in any way
db is a reserved word for assembler meaning : declare byte
Code:
db $33 ; declares 1 byte with value of 33h
db $12,$13,$14,$15 ; declares 4 bytes with value of $12,$13,$14,$15
db 'Hello' ; declares a byte array, this character pattern will be db-ed into your code
db 'Hello','$' ; declares a byte array, this character pattern will be db-ed into your code, you can also use , operator to start another array, or single byte like:
db 'Hello',13,10,'$' ; this is a valid array, byte 13 10 are CR LF moves to beginning of next line, '$' is dos string terminator
    
Post 15 Nov 2004, 20:20
View user's profile Send private message Visit poster's website 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.