flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > combine variables at one place...

Author
Thread Post new topic Reply to topic
qeos



Joined: 15 Jan 2008
Posts: 15
qeos 17 Apr 2008, 13:48
haw may I combine variables at some plase/segment?

like this:

Code:
new a, 'dsds'

mov ax, ax
...

new b, 'asfasd'    


to this ==>

Code:
mov ax, ax
...

a db 'dsds'
b db 'asfasd'    
Post 17 Apr 2008, 13:48
View user's profile Send private message 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 17 Apr 2008, 13:52
Here is my little "globals" macros that probably does something close to what you need.
Code:
;file name: globals.inc v0.0
;
;sets up five macros to define global data:
;
;.idata         - declaration of initialised global data
;.udata             - declaration of uninitialised global data
;.sdata           - declaration of initialised global string data
;.bcode              - declaration of one-time start up executed code
;.ecode             - declaration of one-time shut down executed code
;
;and sets up another 5 macros to instantiate the global data
;
;iData           - instantiate the initialised global data
;uData             - instantiate the uninitialised global data
;sData           - instantiate the initialised global string data
;bCode              - instantiate the one-time start up executed code
;eCode             - instantiate the one-time shut down executed code


;All macros are used like this:
;
;
;        .idata
;     {
;             global_var1 rd 1
;   }
;
;
;   .bcode
;     {
;             call MODULE_init_lut
;               ... other arbitrary code
;   }
;
;
;   iData
;      bCode


;initialised global data

.idata_list equ

macro .idata {
 local z
     .idata_list equ .idata_list,z
       macro z
}

macro iData {
 match data_list,.idata_list \{
                irp instr,data_list \\{
                      instr
               \\}
  \}
}


;uninitialised global data

.udata_list equ

macro .udata {
  local z
     .udata_list equ .udata_list,z
       macro z
}

macro uData {
 match data_list,.udata_list \{
                irp instr,data_list \\{
                      instr
               \\}
  \}
}


;global string data

.sdata_list equ

macro .sdata {
 local z
     .sdata_list equ .sdata_list,z
       macro z
}

macro sData {
 match data_list,.sdata_list \{
                irp instr,data_list \\{
                      instr
               \\}
  \}
}


;one time start-up initialisation/allocation code

.bcode_list equ

macro .bcode {
   local z
     .bcode_list equ .bcode_list,z
       macro z
}

macro bCode {
 match code_list,.bcode_list \{
                irp instr,code_list \\{
                      instr
               \\}
  \}
}


;one time shut-down deinitialisation/deallocation code

.ecode_list equ

macro .ecode {
      local z
     .ecode_list equ .ecode_list,z
       macro z
}

macro eCode {
 match code_list,.ecode_list \{
                irp instr,code_list \\{
                      instr
               \\}
  \}
}    
Post 17 Apr 2008, 13:52
View user's profile Send private message Visit poster's website Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP 17 Apr 2008, 13:56
?! I think that's a little much than he required, but good macro(s). Does he want a more OOP-style of initializing variables? He may try this:
Code:
macro new name,string {
name db string }
    

Note this is just a high-level view of what the macro would look like, I highly doubt the one I just posted would actually work. I can't test it now, school computers...

EDIT: Oh, I see he would like them to be grouped in one section. I believe the only way to do this is to not use the macro in the middle of the code, but group them like so:
Code:
section '.data' data readable writeable
..
new a 'asd'
new b 'asdflas'
..

; would give
..
a db 'asd'
b db 'asdflas'
..
    
Post 17 Apr 2008, 13:56
View user's profile Send private message Visit poster's website 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 17 Apr 2008, 14:05
AlexP wrote:
?! I think that's a little much than he required, but good macro(s). Does he want a more OOP-style of initializing variables?
My macros are not OOP style initialisation, they are designed to do just what the OP asked, and that is, to place all the data into one section, even though they may be defined in different places throughout the code.
Post 17 Apr 2008, 14:05
View user's profile Send private message Visit poster's website Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP 18 Apr 2008, 02:58
Well then.. fine... and I did not call your macros OOP-style. I simply stated that it looks like (from his 'new' keyword) that he was trying to build a more OOP-style ASM programming. I may make use of those macros, I have an idea...
Post 18 Apr 2008, 02:58
View user's profile Send private message Visit poster's website Reply with quote
qeos



Joined: 15 Jan 2008
Posts: 15
qeos 18 Apr 2008, 12:31
2revolution, I think this is what I need.. thank
Post 18 Apr 2008, 12:31
View user's profile Send private message Reply with quote
qeos



Joined: 15 Jan 2008
Posts: 15
qeos 18 Apr 2008, 12:58
Code:
.gvar_list equ 

macro vars { 
     local z 
    .gvar_list equ .gvar_list,z 
        macro z 
} 


macro globalVar { 
      match var_list,.gvar_list \{ 
         irp instr,var_list \\{ 
                      instr 
              \\{ 
 \} 
}     


Code:
vars
{
asdf db 'asdfasdf'
}

globalVar    


Quote:
flat assembler version 1.67.26 (1031068 kilobytes memory)
test.asm [8]:
globalVar
masmo.inc [29] globalVar [2]:
irp instr,var_list \\{
error: incomplete macro.

I dont understand where is trouble?
Post 18 Apr 2008, 12:58
View user's profile Send private message 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 18 Apr 2008, 13:12
qeos wrote:
Code:
.gvar_list equ 

macro vars { 
    local z 
    .gvar_list equ .gvar_list,z 
        macro z 
} 


macro globalVar { 
      match var_list,.gvar_list \{ 
         irp instr,var_list \\{ 
                      instr 
              \\{ 
 \} 
}     


Code:
vars
{
asdf db 'asdfasdf'
}

globalVar    


Quote:
flat assembler version 1.67.26 (1031068 kilobytes memory)
test.asm [8]:
globalVar
masmo.inc [29] globalVar [2]:
irp instr,var_list \\{
error: incomplete macro.

I dont understand where is trouble?
You have a reversed curly bracket in the closing of the irp. Use:
Code:
.gvar_list equ 

macro vars { 
      local z 
    .gvar_list equ .gvar_list,z 
        macro z 
} 


macro globalVar { 
      match var_list,.gvar_list \{ 
         irp instr,var_list \\{ 
                      instr 
              \\}
  \} 
}     
Post 18 Apr 2008, 13:12
View user's profile Send private message Visit poster's website Reply with quote
qeos



Joined: 15 Jan 2008
Posts: 15
qeos 18 Apr 2008, 13:49
big thanks!
Post 18 Apr 2008, 13:49
View user's profile Send private message 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.