Copyright (C) 2000-2012 |
GNU Info (nasm.info)Section 6.2.76.2.7. `obj' Extensions to the `EXTERN' Directive ------------------------------------------------- If you declare an external symbol with the directive extern foo then references such as `mov ax,foo' will give you the offset of `foo' from its preferred segment base (as specified in whichever module `foo' is actually defined in). So to access the contents of `foo' you will usually need to do something like mov ax,seg foo ; get preferred segment base mov es,ax ; move it into ES mov ax,[es:foo] ; and use offset `foo' from it This is a little unwieldy, particularly if you know that an external is going to be accessible from a given segment or group, say `dgroup'. So if `DS' already contained `dgroup', you could simply code mov ax,[foo wrt dgroup] However, having to type this every time you want to access `foo' can be a pain; so NASM allows you to declare `foo' in the alternative form extern foo:wrt dgroup This form causes NASM to pretend that the preferred segment base of `foo' is in fact `dgroup'; so the expression `seg foo' will now return `dgroup', and the expression `foo' is equivalent to `foo wrt dgroup'. This default-`WRT' mechanism can be used to make externals appear to be relative to any group or segment in your program. It can also be applied to common variables: see *Note Section 6.2.8::. automatically generated by info2www version 1.2.2.9 |