Author Topic: Very New to Nasm Macro's  (Read 7532 times)

nobody

  • Guest
Very New to Nasm Macro's
« on: December 14, 2006, 04:58:35 AM »
Hey all, first post here, this is my problem using a Macro:

Cls - Create Linux String
%macro Cls 1, 2+
 %1 db %2, 10
 %1Length Equ $-%1
%endmacro

I get an error at this line:
 Cls Message, "Hello World!"

The error message:
 hello.asm:7: error: parser: instruction expected

Here is the whole code if anyone is interested, thanks all! :)

%macro Cls 1, 2+
 %1 db %2, 10
 %1Length Equ $-%1
%endmacro

SECTION .Data
 Cls Message, "Hello World!"
SECTION .Text
Global Main
 Main:
  Mov Edx, MessageLength
  Mov Ecx, Message
  Mov Ebx, 1
  Mov Eax, 4
  Int 0x80
  Mov Ebx, 0
  Mov Eax, 1
  Int 0x80

nobody

  • Guest
Re: Very New to Nasm Macro's
« Reply #1 on: December 14, 2006, 05:07:05 AM »
All Macro's are Tasm/Masm compliant and I need to see if Nasm is gonna be the proper tool for use in the future(Its Free, I can Make anything I want, ect) as opposed to the other 2 who are either expensive(Tasm) or won't allow code to be created for other Operating Systems(Masm)

Thank you everyone for your help :)

Now that I think of it Tasm probably isn't that compatible with *nix either.

nobody

  • Guest
Re: Very New to Nasm Macro's
« Reply #2 on: December 16, 2006, 05:28:39 AM »
I am very new to Nasm style coding, but am adept at basic Assembly, I could really use help.

The reason I like the idea of Nasm goes in two parts:

1. Open Source, not so much that anyone can program for it, but that it is always changing, always adding to itself.

2. Multi-Platform, I like the idea that my programs assemble on Windows, Linux, Dos, and (with hope) OS X.

As an example, here is the first Macro Tasm/Masm programs usually call:

DefineProgram Macro Processor, Alignment, OperatingSystem, Model, Stack
  IFIDN , <8086>
    BS_Cpu Equ 1
  ENDIF
  IFIDN , <186>
    BS_Cpu Equ 2
    .186
  ENDIF
  IFIDN , <286>
    BS_Cpu Equ 3
    .286
  ENDIF
  IFIDN , <386>
    BS_Cpu Equ 4
    .386
  ENDIF
  IFIDN , <486>
    BS_Cpu Equ 5
    .486
  ENDIF
  IFIDN , <586>
    BS_Cpu Equ 6
    .586
  ENDIF
  IFB
    Echo Use: DefineProgram Processor, SegmentSize, OperatingSystem, Model, Stack
    .ERR Processor Error (8086/186/286/386/486/586)
  ENDIF
  Include BSM\Core\PkCpu.mac
  Include BSM\Core\InCore.mac

IFIDN ,
    BS_SegmentSize Equ 0
  ENDIF
  IFIDN , <16>
    BS_SegmentSize Equ 1
    Option Segment:USE16
  ENDIF
  IFIDN , <32>
    BS_SegmentSize Equ 2
    Option Segment:USE32
  ENDIF
  IFB
    Echo Use: DefineProgram Processor, SegmentSize, OperatingSystem, Model, Stack
    .ERR Segment Size Error (Null/16/32)
  ENDIF

IFIDN ,
    BS_Os Equ 1
    IFB
      Echo Use: DefineProgram Processor, SegmentSize, OperatingSystem, Model, Stack
      .ERR Model Error (Tiny/Compact/Small/Medium/Large/Huge)
    ENDIF
    .Model Model
    IFIDN ,
      BS_Model Equ 1
      BS_NearData Equ 1
      BS_NearCode Equ 1
    ENDIF
    IFIDN ,
      BS_Model Equ 2
      BS_NearData Equ 1
      BS_NearCode Equ 1
    ENDIF
    IFIDN ,
      BS_Model Equ 4
      BS_NearCode Equ 1
    ENDIF
    IFIDN ,
      BS_Model Equ 3
      BS_NearData Equ 1
    ENDIF
    IFIDN ,
      BS_Model Equ 3
    ENDIF
    IFIDN ,
      BS_Model Equ 3
    ENDIF
    IFB
      BS_Model Equ 4
    ENDIF
    IFNB
      .Stack Stack
    ENDIF
    Include BSM\Core\OsDos.mac
  ENDIF
  IFIDN ,
    BS_Os Equ 2
   .Model Flat, StdCall
    Option Casemap:None
    Include BSM\Core\OsWinMain.mac
  ENDIF
  IFIDN ,
    BS_Os Equ 3
    Include BSM\Core\OsBoot.mac
  ENDIF
  IFIDN ,
    BS_Os Equ 4
    Include BSM\Core\OsLinux.mac
  ENDIF
  IFB
    Echo Use: DefineProgram Processor, SegmentSize, OperatingSystem, Model, Stack
    .ERR Operating System Error (Dos/Windows/Boot/Linux)
  ENDIF
EndM

The Linux part is mostly fiction at this point, but it will be the endpoint for such programs as this:

Include BSM\Core.mac
DefineProgram 8086, Null, Linux
StartData
 Cgs S_HW, "Hello World!"
EndData
StartProgram
 PrintString S_HW
 Exit
EndProgram

I really wish this project to go somewhere, if only to help those wanting to learn assembly.

Anyways, Hot Damn 100 has gone to my head, thank you all!

P.S. (Cgs = Create Generic String(OS Dependent, meaning only 1 line would need changed to switch Operating Systems)

P.S.S. I'm not sure how Nasm would work with an 8086 processor defined, but as long as calls remained Interrupts and their Registers remained 16-bit or under, I don't see a problem ;|