NASM - The Netwide Assembler

Please login or register.

Login with username, password and session length
Advanced search  

News:

Author Topic: Extending standard.mac  (Read 1242 times)

Bryant Keller

  • Forum Moderator
  • Full Member
  • *****
  • Offline Offline
  • Posts: 360
    • About Bryant Keller
Extending standard.mac
« on: March 22, 2016, 06:26:28 AM »

A huge portion of the code in NASMX has been to add _size suffixes to type and registers for internal use as well as the sizeof() macro. The built-in struc macro has always (to my knowledge) supported this and I was wondering if anyone thought it would be useful to extend the built-in Dx RESx directives in the same way? It'd be a fairly trivial extension to standard.mac (I've already tested it locally and got a working patch) and would be fairly useful imho. Here is the patch of code I've been playing with:

Code: [Select]
diff --git a/standard.mac b/standard.mac
index 60c0387..0cd6c6f 100644
--- a/standard.mac
+++ b/standard.mac
@@ -88,6 +88,87 @@
     __SECT__
 %endmacro
 
+%imacro db 1+.nolist
+%00 db %1
+%00 %+ _size EQU ($-%00)
+%endmacro
+
+%imacro dw 1+.nolist
+%00 dw %1
+%00 %+ _size EQU ($-%00)
+%endmacro
+
+%imacro dd 1+.nolist
+%00 dd %1
+%00 %+ _size EQU ($-%00)
+%endmacro
+
+%imacro dq 1+.nolist
+%00 dq %1
+%00 %+ _size EQU ($-%00)
+%endmacro
+
+%imacro dt 1+.nolist
+%00 dt %1
+%00 %+ _size EQU ($-%00)
+%endmacro
+
+%imacro do 1+.nolist
+%00 do %1
+%00 %+ _size EQU ($-%00)
+%endmacro
+
+%imacro dy 1+.nolist
+%00 dy %1
+%00 %+ _size EQU ($-%00)
+%endmacro
+
+%imacro dz 1+.nolist
+%00 dz %1
+%00 %+ _size EQU ($-%00)
+%endmacro
+
+
+%imacro resb 1.nolist
+%00 resb %1
+%00 %+ _size EQU ($-%00)
+%endmacro
+
+%imacro resw 1.nolist
+%00 resw %1
+%00 %+ _size EQU ($-%00)
+%endmacro
+
+%imacro resd 1.nolist
+%00 resd %1
+%00 %+ _size EQU ($-%00)
+%endmacro
+
+%imacro resq 1.nolist
+%00 resq %1
+%00 %+ _size EQU ($-%00)
+%endmacro
+
+%imacro rest 1.nolist
+%00 rest %1
+%00 %+ _size EQU ($-%00)
+%endmacro
+
+%imacro reso 1.nolist
+%00 reso %1
+%00 %+ _size EQU ($-%00)
+%endmacro
+
+%imacro resy 1.nolist
+%00 resy %1
+%00 %+ _size EQU ($-%00)
+%endmacro
+
+%imacro resz 1.nolist
+%00 %resz %1
+%00 %+ _size EQU ($-%00)
+%endmacro
+
 %imacro struc 1-2.nolist 0
     %push
         %define %$strucname %1

This would simplify things like using sys_write with a built-in size for the defined strings. Not exactly sure how useful there res* versions would be, but I added them for completeness. Does anyone else think this would be useful? Possible pitfall is, it could cause errors in peoples code who already manually put these *_size symbols in their code, but so long as it's a documented feature, i don't think anyone would mind, especially considering how clear the error messages are for this kind of thing:

Code: [Select]
test.asm:19: error: symbol `strMessage_size' redefined

Bryant Keller

  • Forum Moderator
  • Full Member
  • *****
  • Offline Offline
  • Posts: 360
    • About Bryant Keller
Re: Extending standard.mac
« Reply #1 on: March 24, 2016, 04:04:22 AM »

Scratch this idea, after playing around a bit It becomes evident that this could really cause a lot of unnecessary symbols that will do little more than fill up memory.