flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Something Like C's Data Declaration...

Author
Thread Post new topic Reply to topic
system error



Joined: 01 Sep 2013
Posts: 671
system error
Hi... new to macro. I made this macro;

Code:
macro float [a,b]
{
        forward
        a dq b
}    


Code:
float length,23.11,width,0.221
float result,0.0    


Is it possible to have a macro so that I can instead declare my variables like these (supposed to be similar to C's declaration);

Code:
float length=23.11,width=0.221    


Appreciate your answers.
Post 20 Dec 2013, 09:45
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17270
Location: In your JS exploiting you and your system
revolution
I expect that using match can give you that functionality:
Code:
macro float [arg] {
 forward
 match a==b,arg \{
  a dq b
 \}
}    
Post 20 Dec 2013, 13:58
View user's profile Send private message Visit poster's website Reply with quote
system error



Joined: 01 Sep 2013
Posts: 671
system error
revolution wrote:
I expect that using match can give you that functionality:
Code:
macro float [arg] {
 forward
 match a==b,arg \{
  a dq b
 \}
}    
Love you revo!
Post 22 Dec 2013, 06:23
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal
I've provided endless macros like this for X86+ARM. Example: This supports standard C declarations: char, short, int, float, double:
Code:
macro verify e {
 if ?s eq 0
  display `e
  'Error: ' e
 end if
}

; define variable of type, name, value

macro !DV type, name, value {
 local l
 l=$
 name type value ; example: msg db 'Hello'
 name#.$=$-l     ; size
}

; define b/w/d/q/t variable

macro !D1 a, b { !DV db, a, b }
macro !D2 a, b { !DV dw, a, b }
macro !D4 a, b { !DV dd, a, b }
macro !D8 a, b { !DV dq, a, b }
macro !DF a, b { !DV dt, a, b }

;;;;;;;;;;;;;; DEFINE HL VARIABLE ;;;;;;;;;;;;;;;;

; define X. syntax: type then any a/a=b
; sequence/s separated with ,s. example:
; NUMBER x, y, w=320, h=240
; variables=0 if there is no initial value

macro !D type, [p] {
 common
  if p eq
   'Name expected'
  end if
 forward
  define ?s 0
  match =0 a==b, ?s p \{ ; a=b
   type a, b
   define ?s 1
  \}
  match =0 a=,, ?s p \{  ; a, (next)
   type a, 0
   define ?s 1
  \}
  match =0 a, ?s p \{    ; a (end)
   type a, 0
   define ?s 1
  \}
  verify variable
}

; HL variable names

macro char [a]   { !D !D1, a }
macro short [a]  { !D !D2, a }
macro int [a]    { !D !D4, a }
macro float [a]  { !D !D4, a }
macro double [a] { !D !D8, a }    
You can also create byte arrays and text variables:

Code:
; verify size of block/text/array

macro verify.size n {
 if n eq
  'Size must be specified'
 else if ~ n eqtype 0
  'Size must be numeric'
 else if n eq 0
  'Size cannot be zero'
 end if
}

; define byte array. BLOCK b(size)

macro BLOCK [p] {
 forward
  define ?s 0
  match =0 (size), ?s p \{
   verify.size size
   db size dup(0)
   define ?s 1 
  \}
  match =0 name(size), ?s p \{
   verify.size size
   !DV db, name, size dup(0)
   define ?s 1
  \}
  verify BLOCK
}

; create HL 'text' variable/s. TEXT t='X'.
; note: (n) is the size
 
macro TEXT [p] {
 forward
  local l
  define ?s 0
  ; TEXT t(n)='abc'
  match =0 name(size)==text, ?s p \{
   l=$
   verify.size size
   !DV db, name, <text,0>
   times (size-($-l)) db 0
   define ?s 1
  \}
  ; TEXT t(n)
  match =0 name(size), ?s p \{
   verify.size size
   !DV db, name, size dup(0)
   name\#.$=size
   define ?s 1
  \}
  ; TEXT t='abc'
  match =0 name==text, ?s p \{
   !DV db, name, <text,0> ; name db 't', 0
   define ?s 1
  \}
  ; TEXT t
  match =0 name, ?s p \{
   'Size must be specified:' name
   define ?s 1
  \}
  verify TEXT
}    
PS: In C, float is dd=32BIT and double is dq=64BIT. Here, Intel 16BIT relative "word" is assumed. Why we're still using 16BIT words and notations like LP ("long pointer") I have no idea. Personally, I think db/dw/dd should be replaced with strict sizes d8/d16/d32.
Post 23 Dec 2013, 12:46
View user's profile Send private message Reply with quote
system error



Joined: 01 Sep 2013
Posts: 671
system error
m3ntal wrote:
I've provided endless macros like this for X86+ARM. Example: This supports standard C declarations: char, short, int, float, double:
Code:
macro verify e {
 if ?s eq 0
  display `e
  'Error: ' e
 end if
}

; define variable of type, name, value

macro !DV type, name, value {
 local l
 l=$
 name type value ; example: msg db 'Hello'
 name#.$=$-l     ; size
}

; define b/w/d/q/t variable

macro !D1 a, b { !DV db, a, b }
macro !D2 a, b { !DV dw, a, b }
macro !D4 a, b { !DV dd, a, b }
macro !D8 a, b { !DV dq, a, b }
macro !DF a, b { !DV dt, a, b }

;;;;;;;;;;;;;; DEFINE HL VARIABLE ;;;;;;;;;;;;;;;;

; define X. syntax: type then any a/a=b
; sequence/s separated with ,s. example:
; NUMBER x, y, w=320, h=240
; variables=0 if there is no initial value

macro !D type, [p] {
 common
  if p eq
   'Name expected'
  end if
 forward
  define ?s 0
  match =0 a==b, ?s p \{ ; a=b
   type a, b
   define ?s 1
  \}
  match =0 a=,, ?s p \{  ; a, (next)
   type a, 0
   define ?s 1
  \}
  match =0 a, ?s p \{    ; a (end)
   type a, 0
   define ?s 1
  \}
  verify variable
}

; HL variable names

macro char [a]   { !D !D1, a }
macro short [a]  { !D !D2, a }
macro int [a]    { !D !D4, a }
macro float [a]  { !D !D4, a }
macro double [a] { !D !D8, a }    
You can also create byte arrays and text variables:

Code:
; verify size of block/text/array

macro verify.size n {
 if n eq
  'Size must be specified'
 else if ~ n eqtype 0
  'Size must be numeric'
 else if n eq 0
  'Size cannot be zero'
 end if
}

; define byte array. BLOCK b(size)

macro BLOCK [p] {
 forward
  define ?s 0
  match =0 (size), ?s p \{
   verify.size size
   db size dup(0)
   define ?s 1 
  \}
  match =0 name(size), ?s p \{
   verify.size size
   !DV db, name, size dup(0)
   define ?s 1
  \}
  verify BLOCK
}

; create HL 'text' variable/s. TEXT t='X'.
; note: (n) is the size
 
macro TEXT [p] {
 forward
  local l
  define ?s 0
  ; TEXT t(n)='abc'
  match =0 name(size)==text, ?s p \{
   l=$
   verify.size size
   !DV db, name, <text,0>
   times (size-($-l)) db 0
   define ?s 1
  \}
  ; TEXT t(n)
  match =0 name(size), ?s p \{
   verify.size size
   !DV db, name, size dup(0)
   name\#.$=size
   define ?s 1
  \}
  ; TEXT t='abc'
  match =0 name==text, ?s p \{
   !DV db, name, <text,0> ; name db 't', 0
   define ?s 1
  \}
  ; TEXT t
  match =0 name, ?s p \{
   'Size must be specified:' name
   define ?s 1
  \}
  verify TEXT
}    
PS: In C, float is dd=32BIT and double is dq=64BIT. Here, Intel 16BIT relative "word" is assumed. Why we're still using 16BIT words and notations like LP ("long pointer") I have no idea. Personally, I think db/dw/dd should be replaced with strict sizes d8/d16/d32.


Too much for me, but thanks.
Post 18 Jan 2014, 17:28
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-2020, Tomasz Grysztar.

Powered by rwasa.