flat assembler
Message board for the users of flat assembler.

Index > Main > problem with calling a label from other files

Author
Thread Post new topic Reply to topic
majidkamali1370



Joined: 31 Oct 2010
Posts: 50
Location: Iran
majidkamali1370 06 Nov 2011, 16:39
Hi.
I created a Header.inc file, which has below content

;;*********************************
PrintChar:
mov ah, 2
int 21
ret
;;*********************************

and an asm file that has below content

;;*********************************
org 100h
include 'Header.inc'

mov dl, 'A'
jmp PrintChar
;;*********************************

but when I run the com file it does not print 'A' on the screen.
Instead it prints 'P' on the screen.
What's the problem?
Can I create a procedure without using windows proc macros?

Thanks Very Happy
Post 06 Nov 2011, 16:39
View user's profile Send private message Send e-mail Yahoo Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
Location: In your JS exploiting you and your system
revolution 06 Nov 2011, 16:43
'Include' will include the external file just as if you had typed it directly
Code:
org 100h
;include 'Header.inc'

  PrintChar:
  mov ah, 2
  int 21
  ret

mov dl, 'A'
jmp PrintChar    
Post 06 Nov 2011, 16:43
View user's profile Send private message Visit poster's website Reply with quote
majidkamali1370



Joined: 31 Oct 2010
Posts: 50
Location: Iran
majidkamali1370 06 Nov 2011, 16:52
there are 2 files. first, header.inc and the second, project.asm file.
I don't know why it does not work.
Actually I want to create a function that prints a character and be in another file.
Post 06 Nov 2011, 16:52
View user's profile Send private message Send e-mail Yahoo Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
Location: In your JS exploiting you and your system
revolution 06 Nov 2011, 17:06
majidkamali1370: Look at the code I posted above. That is exactly what fasm assembles.

If you need me to give you a direct answer then do this:
Code:
org 100h

mov dl, 'A'
jmp PrintChar

include 'Header.inc'    
Post 06 Nov 2011, 17:06
View user's profile Send private message Visit poster's website Reply with quote
majidkamali1370



Joined: 31 Oct 2010
Posts: 50
Location: Iran
majidkamali1370 06 Nov 2011, 19:55
Thanks. It works. but in big projects, should I include all header files at the end?
Post 06 Nov 2011, 19:55
View user's profile Send private message Send e-mail Yahoo Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
Location: In your JS exploiting you and your system
revolution 06 Nov 2011, 20:04
You need to understand what include does. It inserts the text of the included file directly at the place of the include directive.

This would also work:
Code:
org 100h
jmp start: ;skip over the included code

include 'Header.inc' ;include our print function here

start:
mov dl, 'A'
jmp PrintChar    
Post 06 Nov 2011, 20:04
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1619
Location: Toronto, Canada
AsmGuru62 07 Nov 2011, 15:38
You need CALL - not a JMP.

Also, JMP START: may trigger anti-virus.
You can include all functions at the end of COM file:
Code:
org 100h
...

include 'Module1.asm'
include 'Module2.asm'
include 'Module3.asm'
    


Last edited by AsmGuru62 on 08 Nov 2011, 18:04; edited 1 time in total
Post 07 Nov 2011, 15:38
View user's profile Send private message Send e-mail Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 07 Nov 2011, 20:35
depending on what is in your header, you can also do that:
Code:
include 'header.inc'
mov dl,'A'
call printchar
ret
    


it will let you separate system specific code and applications codes.

Header.inc
Code:
org 100h
call start
ret ;quit the program
include 'printchar.inc'
start:
    
Post 07 Nov 2011, 20:35
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.