Jump to content

Hon can I make variables or labels public?

- - - - -

  • Please log in to reply
5 replies to this topic

#1
Monreal

Monreal

    Newbie

  • Members
  • PipPip
  • 21 posts
Hi il have the following variables defined in a file called "player.asm" but I need to have access to them from another file called "behavior.asm". How can I access those variables form the other file?

Since using the procedures defined in "player" is easy (using extrn and public), I supposse there is a way to access the variables too.

Player.asm (just showing the data part) :


Title  Player1

model small


;parts of the player's ship

play1 struc  

   playX db ?

   playY db 25

   alive db 1

ends


;this is the player

plyr struc

   Lplay1 <38,,,>

   Cplay1 <39,,,>

   Rplay1 <40,,,>

   Front play1 <39,24,,>

   lives db 2

   ship db 202

   score dw 0

ends


.data

   me plyr <>



#2
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
Do you assemble "player.asm" and "behavior.asm" separately and then link them into one executable, or do you include one into another?

In other words, do you assemble player.asm, then assemble behavior.asm, and then link both into an executable file? Or do you use include to put the files together and assemble everything into one file?

I don't know TASM syntax, however, so maybe anyone else on this forum knows how to do that in TASM; I do know how to do that in MASM32, though.

#3
Monreal

Monreal

    Newbie

  • Members
  • PipPip
  • 21 posts

RhetoricalRuvim said:

Do you assemble "player.asm" and "behavior.asm" separately and then link them into one executable, or do you include one into another?

In other words, do you assemble player.asm, then assemble behavior.asm, and then link both into an executable file? Or do you use include to put the files together and assemble everything into one file?

I don't know TASM syntax, however, so maybe anyone else on this forum knows how to do that in TASM; I do know how to do that in MASM32, though.

Yes, I assemble them separately and then link them into an .exe. Since you allow procedures to be publi with "public my_procedure" and call them in the main file with " extrn my_procedure : proc", I suposse there is a similar way for the variables.

Thanks

#4
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
I am pretty sure that's possible; I don't have TASM on my computer, but maybe you could try it and tell us what happens.

#5
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
What're you trying to make public, plyr?
sudo rm -rf /

#6
Monreal

Monreal

    Newbie

  • Members
  • PipPip
  • 21 posts
I finally got the answer. If you want to make a public variable you have to specify that in its module, and then specify its type and its 'extrn' status in the main file. If the variable is of struc type you have to copy and paste the definition of the structure.

For example, in a file called "aux.asm" we'll have 2 variables that we'll use in "main.asm"
so the thing would go like this:

aux.asm:


Title aux

.model small


;parts of the player's ship

play1 struc  

   playX db ?

   playY db 25

   alive db 1

ends


;this is the player

plyr struc

   Lplay1 <38,,,>

   Cplay1 <39,,,>

   Rplay1 <40,,,>

   Front play1 <39,24,,>

   lives db 2

   ship db 202

   score dw 0

ends


.data


me plyr <>

rand db ?


;making those variables public

public me

public rand


main.asm:


Title main file

.model small


.stack


; we need to include the struc definitions so the assembler knows how to deal

;with "me"


;parts of the player's ship

play1 struc  

   playX db ?

   playY db 25

   alive db 1

ends


;this is the player

plyr struc

   Lplay1 <38,,,>

   Cplay1 <39,,,>

   Rplay1 <40,,,>

   Front play1 <39,24,,>

   lives db 2

   ship db 202

   score dw 0

ends


.data


extrn me :plyr

extrn rand :byte


.code


...






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users