flat assembler
Message board for the users of flat assembler.

Index > DOS > problem with I\O

Author
Thread Post new topic Reply to topic
kb_08h



Joined: 03 Nov 2005
Posts: 12
Location: Ukraine
kb_08h 03 Nov 2005, 20:05
hi, guys.
i'm trying to write simple program that will open file (read only), read and then close it; here's the source:

Code:
org 100h
use16


;------------- data --------------
handle          dw      0
mess_ok         db      'file loaded sucsessfull$'
mess_error      db      "where's this f***ing file?!$"
file_name       db      'sample.txt',0
buffer  equ     $


mov     ax,3d00h
mov     dx,file_name
int     21h
jc      error

mov     [handle],ax
mov     bx,ax
mov     ah,3fh
mov     cx,0fde8h
mov     dx,buffer
int     21h

mov     ah,3eh
mov     bx,[handle]
int     21h

mov     dx,mess_ok


print:
mov     ah,9
int     21h

int     20h

error:
mov     dx,mess_error
jmp     print
    


the source compiling succesfully, but program not working; in dosbox program just "freeze", and in xp console it returns something like that
"NTVDM proccessor has found out the inadmissible instruction
CS:0ddb IP:0110 OP:63 73 65 73 73"

can you help me please?
I am very grateful to you for the help and attention.

p.s sorry for my engish spelling. =)

_________________
{D is for demoscene}
Post 03 Nov 2005, 20:05
View user's profile Send private message ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 03 Nov 2005, 20:08
Put all data below the code, you are executing the data instead of "mov ax,3d00h" and all the other instructions
Post 03 Nov 2005, 20:08
View user's profile Send private message Reply with quote
kb_08h



Joined: 03 Nov 2005
Posts: 12
Location: Ukraine
kb_08h 03 Nov 2005, 20:21
i tried to move data below the code, but recieved an error during compiling:
"mov dx,buffer
error: undefined symbol."
so i keep "buffer equ $" string before the main code, and put other data below the code as you say , program compiled, but it's still not working. =\

_________________
{D is for demoscene}
Post 03 Nov 2005, 20:21
View user's profile Send private message ICQ Number Reply with quote
kb_08h



Joined: 03 Nov 2005
Posts: 12
Location: Ukraine
kb_08h 03 Nov 2005, 21:09
i've moved "buffer equ $" right to the end of the code, no error during compiling but also no good result after executing. looked the source in debugger, obviously program terminate after second 21h interrupt, so problem must be somewhere here

Code:
mov     [handle],ax
mov     bx,ax
mov     ah,3fh
mov     cx,0fde8h
mov     dx,buffer
int     21h             ;read file
    

_________________
{D is for demoscene}
Post 03 Nov 2005, 21:09
View user's profile Send private message ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 03 Nov 2005, 21:52
If you need to put the buffer at the end of the initialized data then do this:

Code:
;------------- data -------------- 
handle          dw      0 
mess_ok         db      'file loaded sucsessfull$' 
mess_error      db      "where's this f***ing file?!$" 
file_name       db      'sample.txt',0 
buffer:    


Doing "buffer equ $" means that when you use "mov dx, buffer" will be assembled as "mov dx, $" which doesn't means that dx will be loaded with the offset of the end of initialized data.

I don't know if you are using the int 21h properly but fix this first.

[edit]Checked, here the code (exactly the same that yours except for the buffer):
Code:
org 100h
use16

mov     ax,3d00h
mov     dx,file_name
int     21h
jc      error

mov     [handle],ax
mov     bx,ax
mov     ah,3fh
mov     cx,0fde8h
mov     dx,buffer
int     21h

mov     ah,3eh
mov     bx,[handle]
int     21h

mov     dx,mess_ok


print:
mov     ah,9
int     21h

int     20h

error:
mov     dx,mess_error
jmp     print


;------------- data --------------
handle          dw      0
mess_ok         db      'file loaded sucsessfull$'
mess_error      db      "where's this f***ing file?!$"
file_name       db      'sample.txt',0
buffer:    

I'd checked with debug and the buffer is loaded with the contents of the file too.
[/edit]
Post 03 Nov 2005, 21:52
View user's profile Send private message Reply with quote
kb_08h



Joined: 03 Nov 2005
Posts: 12
Location: Ukraine
kb_08h 04 Nov 2005, 05:45
so every time when i need to put buffer i should use "buffer:", right?
i replaced "buffer equ $" with "buffer:" and it works now;

thank you guys for your support and attention.

_________________
{D is for demoscene}
Post 04 Nov 2005, 05:45
View user's profile Send private message ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 04 Nov 2005, 12:45
Well, just if you know what are you doing, for example putting
Code:
buffer:
anotherBuffer:    

both labels will share the same address so in this case will be better reserve bytes for buffer at least
Code:
buffer rb aSize ;aSize is a positive integer
anotherBuffer:    

Now both buffers has their own address. I suggest always reserve space instead of using label for clarity and for having no problems with other executable formats like PE that will raise page fault using labels for buffers (except if you put "buffer: rb aSize" of course) when you traying to access them. In fact, only is safe to put a buffer with a label at the end of the source for binary and COM executables, for the other formats is risky.
Post 04 Nov 2005, 12:45
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 31 Dec 2005, 22:30
ArrowASM 2.00c will work correctly with buffer equ $, but some others (e.g., LazyASM 0.52) will not. I've been told by LazyASM's author to use buffer=$ instead.

Also, something simple like SEMICOLON equ ';' will work in most assemblers but not LazyASM, so SEMICOLON=';' is again recommended. Go figure.
Post 31 Dec 2005, 22:30
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 02 Jan 2006, 13:00
Fasm's equ is a preprocessor directive... it doesn't store any value. it simply replaces the contents with the defined value. if you want to store some numeric constant, use =, like

buffer = $

but in fact it's the same as declaring a label, but I prefer the label, since it's much clearer.. you could also use

label buffer

and, optionally, add a size specifying the size (byte, word, dword, etc).
Fasm is very flexible and easy, yet powerful. Make sure you read the documentation to use it properly.


Hope it helps
Post 02 Jan 2006, 13:00
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 03 Jan 2006, 21:08
FASM is very powerful but perhaps a little confusing/overwhelming. The doc calls = a constant but it 'can be redefined' (which is odd wording).

constant : Unchanging in nature, value, or extent; invariable (from dictionary.com)

I do not use FASM exclusively, but when I do use it, I avoid macros (convenient but non-standard) and strucs (yuk) and other fancy stuff, at least to minimize changes for other assemblers. I usually do NOT trust one program by itself since they all have bugs and odd features.

P.S. In OpenWatcom 1.4 equ behaves differently than 1.3 did, plus blah=$ does not work like in LZASM, for instance. Also, NASM evaulates equ only once.

equ in one assembler does not necessarily equal equ in another. Razz

[EDIT]
As always, Privalov knows best. Smile
[/EDIT]


Last edited by rugxulo on 05 Jan 2006, 01:54; edited 1 time in total
Post 03 Jan 2006, 21:08
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8357
Location: Kraków, Poland
Tomasz Grysztar 04 Jan 2006, 15:03
Yeah, the "constant" term used here might be really confusing - this is mainly because this term was taken from other assemblers, where similar directives used to define the truly constant (not redefinable) values initially.

In fasm term "constant" is used for the compilation-time variables, as opposed to run-time variables. From the point of view of your program they are constants, from the point of view of your source they are variables.
This is because flat assembler actually constist of two layers of language - the interpreted language used to make macros and other tricks, and the compiled language - the x86 instructions. The variables of interpreted language are called constants (as they are constants from the point of view of compiled language) - thus the confusion.
Post 04 Jan 2006, 15:03
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.