Author Topic: im having trouble with my include file  (Read 14415 times)

Offline william427

  • Jr. Member
  • *
  • Posts: 23
im having trouble with my include file
« on: July 27, 2014, 07:33:41 PM »
hi im using 32 bit when I include my inc.asm file  ,as long as I have only section .text or code it works
but what if I need to send that and a string, like section .data   too?
is there any other way, because have to send stuff threw inc.asm file I guess.

thanks
billy

Offline Anonymous

  • Jr. Member
  • *
  • Posts: 78
  • Country: us
Re: im having trouble with my include file
« Reply #1 on: July 27, 2014, 07:54:36 PM »
Could you post your code so we can see how you implemented it???
Usually the way I include files is like this
Code: [Select]
section .data

section .bss

section .text

%include "include.asm"

global _start:

_start:



« Last Edit: July 27, 2014, 07:56:53 PM by Anonymous »
Thanks in advance, Anonymous

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: im having trouble with my include file
« Reply #2 on: July 27, 2014, 10:01:21 PM »
Hi billy,

It isn't clear exactly what the problem is. "%include" is essentially a "cut and paste" operation, and it's pasted in where the "%include" occurs. For example, in the code Anonymous offers...
Code: [Select]
section .data

section .bss

section .text

; %include "include.asm"
; suppose our hypothetical include file,
; pasted in here, said:

section .data
    foo db "this is my string", 10, 0
; and that's all

; whoops! we're no longer in "section .text"!
global _start:

_start:
; ...

There's a "__SECT__" macro known to Nasm that can be used to work around this. RTFM. In my opinion, this isn't worth bothering about. Just put your "section" directives where you need 'em - outside the "%include" - and you won't need to worry about "section" changes inside the "%include".

If that isn't your actual problem, show us some example code that illustrates it.

Best,
Frank





Offline william427

  • Jr. Member
  • *
  • Posts: 23
Re: im having trouble with my include file
« Reply #3 on: July 27, 2014, 10:24:58 PM »
hi yall

everything will work ,but the data section.
what do I look under to find more about this "__SECT__" ?


Code: [Select]

i  equ 0
x equ 100




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     mov eax, i
L1:
     
      add eax, 1     
      mov ebx, eax     
      cmp ebx, x  ;; Compares whether the                                 counter has reached x
      JL    L1    ; If it is less than  x,                                                         then jump to L1
 

 sendmsg                         db "the answer = ", 0 



Offline william427

  • Jr. Member
  • *
  • Posts: 23
Re: im having trouble with my include file
« Reply #4 on: July 27, 2014, 10:40:24 PM »
I looked up   _SECT_ will that work from a %include file?
thanks

Offline Anonymous

  • Jr. Member
  • *
  • Posts: 78
  • Country: us
Re: im having trouble with my include file
« Reply #5 on: July 27, 2014, 10:49:16 PM »
Assuming this is the include file this is what it should look like at least this is how I would do it
Code: [Select]
section .data
i  equ 0
x equ 100

 sendmsg                         db "the answer = ", 0 
section .text


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ExFunc:
     mov eax, i
L1:
     
      add eax, 1     
      mov ebx, eax     
      cmp ebx, x  ;; Compares whether the                                 counter has reached x
      JL    L1    ; If it is less than  x,                                                         then jump to L1
 
ret
Then when you include this in your main file implement it like so:
Code: [Select]
section .data

section .bss

section .text
%include "Exfunc.asm"
global _start:

_start:

;some code goes here

Thanks in advance, Anonymous

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: im having trouble with my include file
« Reply #6 on: July 27, 2014, 10:54:44 PM »
http://www.nasm.us/xdoc/2.11.05/html/nasmdoc6.html#section-6.3.1

Not at all clear how this is going to help you. Sure it'll work in an "%include" file. An "%include" file is essentially a "cut and paste" operation. It'll work exactly as if everything was in one file.


Perhaps what you want to do is...
Code: [Select]

i  equ 0
x equ 100



; this appears to be "section .text" although you don't say
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     mov eax, i
L1:
     
      add eax, 1     
      mov ebx, eax     
      cmp ebx, x  ;; Compares whether the                                 counter has reached x
      JL    L1    ; If it is less than  x,                                                         then jump to L1
 
[section .data] ; note square brackets!
 sendmsg                         db "the answer = ", 0 
__SECT__ ; changes back to whatever the previous section was

Best,
Frank


Offline william427

  • Jr. Member
  • *
  • Posts: 23
Re: im having trouble with my include file
« Reply #7 on: July 27, 2014, 11:04:46 PM »
thanks yall
anonymous that worked
thanks

Offline william427

  • Jr. Member
  • *
  • Posts: 23
Re: im having trouble with my include file
« Reply #8 on: July 27, 2014, 11:07:18 PM »
thanks frank  thatll give me two ways to solve it

im not getting errors now and its working
thanks