Well that feature can sometimes be very annoying and a potential source of bugs. For example, here is how I found this whole backslash thing out. I had handled keystrokes in my kernel using a lookup table for scancodes and etc. Everything was working fine until I added some comments to each of the lines. After that, the space key was not working. Below is my code with the comments included:
You can see that the third line's comment is terminated by a backslash so the next line which was supposed to handle the space key was getting commented out and not assembled. This wasted a lot of my time trying to figure out what the problem was. Maybe they should do something else to handle multiline comments because there is a possibility that someone's single line comment is going to end with a backslash just like mine's.
Isn't NASM going to support multiline comments with the COMMENT keyword?
INVOKE __SetKDTEntry, OFFSET KDT, 0x2C, MAKEDWORD(0x01, '.', '>', 0x34), 0x00000000 ; > , .
INVOKE __SetKDTEntry, OFFSET KDT, 0x2D, MAKEDWORD(0x01, '/', '?', 0x35), 0x00000000 ; ? , /
INVOKE __SetKDTEntry, OFFSET KDT, 0x2E, MAKEDWORD(0x01, '\', '|', 0x2B), 0x00000000 ; | , \
INVOKE __SetKDTEntry, OFFSET KDT, 0x2F, 0x01202039, 0x00000000 ; Space
INVOKE __SetKDTEntry, OFFSET KDT, 0x30, 0x0100000E, OFFSET __KeyHandlerBackspace ; Backspace
You can see that the third line's comment is terminated by a backslash so the next line which was supposed to handle the space key was getting commented out and not assembled. This wasted a lot of my time trying to figure out what the problem was. Maybe they should do something else to handle multiline comments because there is a possibility that someone's single line comment is going to end with a backslash just like mine's.
Isn't NASM going to support multiline comments with the COMMENT keyword?
Isn't NASM going to support multiline comments with the COMMENT keyword?
Perhaps. All I know, is that form of multi-line support will break more things than it will help. As far as I am concerned, legacy comments with the semi-colon will be trimmed from the line prior to a full parse.
As for the actually "COMMENT" token, I think it would be more appropriate to make it %comment, perhaps with an %endcomment, instead.
The NASM source code, however, is full of hackish code that made sense for efficiency reasons... but totally destroys any serious attempts at expanding NASM. Soon, there will be more exceptions than rules in the code base.
Without saying too much, I am attempting to take care of that problem ;)
Thank you Spook. Appreciations.
I don't want to piggyback on this post but there is one more question about NASM that I have and haven't been able to figure it out yet so I'd appreciate it if someone could help me with this.
Can we create multiline macros in NASM that return a value like single line macros or something like EXITM in MASM? For example, let's say that you want to create two macros called SL and SH that return the Low Order Byte and the Byte #1 of the Source Index (ESI) and then you access them like this:
Is this possible in NASM? And if yes, how? Thanks in advance.
Can we create multiline macros in NASM that return a value like single line macros or something like EXITM in MASM? For example, let's say that you want to create two macros called SL and SH that return the Low Order Byte and the Byte #1 of the Source Index (ESI) and then you access them like this:
MOV AL , SL
MOV CL , SH
Is this possible in NASM? And if yes, how? Thanks in advance.
Yes, it is possible, but you need to subclass the "mov" into macro, and use %ifidni:
%include "asm.inc"
%define sh "esi_sh"
%define sl "esi_sl"
%macro mov 2
%ifidni %2, sh
push esi
mov %1,
pop esi
%elifidni %2, sl
push esi
mov %1,
pop esi
; add more ?
%else
mov %1,%2
%endif
%endm
main:
mov esi,12345678h
xor eax,eax
xor edx,edx
mov al,sl
mov dl,sh
cdecl printf,"%X %X",eax,edx ; prints 78 56
cdecl _getch
ret
I don't want to piggyback on this post but there is one more question about NASM that I have and haven't been able to figure it out yet so I'd appreciate it if someone could help me with this.
Can we create multiline macros in NASM that return a value like single line macros or something like EXITM in MASM? For example, let's say that you want to create two macros called SL and SH that return the Low Order Byte and the Byte #1 of the Source Index (ESI) and then you access them like this:
MOV AL , SL
MOV CL , SH
Is this possible in NASM? And if yes, how? Thanks in advance.
It is called "instruction overloading" and works as sapero posted, but I suggest using "%imacro" instead.
Okay so let me get this straight. For whatever instruction that might use SL or SH I am going to have to overload the instruction, right? Come to think of it I don't need SL and SH that much :lol:
Sapero,
Have you tested that code? because that doesn't work. But thank you anyway.
Spook,
The package for NASM documentation that I have downloaded off of SourceForge does not explain "%imacro" even a little bit. Is it just this documentation package that I have downloaded or are all documentations that come with NASM excluding this subject?
Thank you guys.
Sapero,
Have you tested that code? because that doesn't work. But thank you anyway.
Spook,
The package for NASM documentation that I have downloaded off of SourceForge does not explain "%imacro" even a little bit. Is it just this documentation package that I have downloaded or are all documentations that come with NASM excluding this subject?
Thank you guys.
4.3 Multi?Line Macros: %macro says:
It works well, ofcourse it was tested before.
Multi?line macros, like single?line macros, are case?sensitive, unless you define them using the alternative directive %imacro.
It works well, ofcourse it was tested before.