OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 6:04 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Shifting the argument of a macro in NASM?
PostPosted: Fri May 27, 2005 2:54 am 
Hi all,
I have defined a macro to install an exception in assembly. The arguments for the macro will be the function address, segment selector and DPL of an exception. How do i shift the higher word of the function address to fill the "offset(16-31)" field in the IDT? NASM supports shifting only for scalar values. How do i shift the argument of a macro? Here is my macro,
Code:
%macro INSTALL_EXCEPTION 3
        dw      %1
        dw      %2
        db      00h
   %if %3=0
        db      0x8E
   %else
        db      0xEE
   %endif
        dw      (%1 >> 16)   ; Here is the problem...
%endmacro


Any help appreciated.


Top
  
 
 Post subject: Re:Shifting the argument of a macro in NASM?
PostPosted: Fri May 27, 2005 1:39 pm 
I think is about the nasm version you are using?? (what is the problem you see???)

This work OK for me...

Code:
%macro SH 1
   %assign _xx_ %1 << 16
   dw %1 << 16
   %error _xx_
%endmacro

%macro S 1
   %assign _xx_ %1 >> 16
   %assign __xx %1 & 0xFFff0000
   %assign __xx __xx >> 16
   dw __xx
   dw %1 >> 16
   %error _xx_ :::: __xx
%endmacro


SH 2
SH 5
SH 6
S 2
S 5
S 6
S 65536
S 65537
S 65536+1
S 0xAAbb8833
S 0x1100FEDC


43707 => 0xAA00
4352 => 0x1100

I have a relative old one? NASM version 0.98.38 compiled on Sep 12 2003.


Top
  
 
 Post subject: Re:Shifting the argument of a macro in NASM?
PostPosted: Fri May 27, 2005 11:35 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

With NASM (all versions) it won't allow operations to be performed on labels, as the labels are relative to something rather than usable (scalar) values. To convert a label into a scalar value you need to do something like:

Code:
%define codeBaseAddress 0x012345

    org codeBaseAddress

    dw ( ((%1-$$)+codeBaseAddress) >> 16)


This works because "(%1 - $$)" is the same as "offset_within_section - offset_within_section", which is a scalar number, and "(scalar_difference + scalar_value)" is also a scalar number. It's messy, but you end up shifting a scalar number rather than the offset within a section :).

In the NASM manual, see section "10.1.4 TIMES Doesn't Work". It's not an obvious place to look but describes the same problem and the same solution (note: the manual is talking above code where ORG=0, or where the "codeBAseAddress" above wouldn't be needed).

@rae: your macro isn't shifting the address of a label - it works because it's shifting a scalar value.


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 101 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group