Author Topic: Equates across module boundaries  (Read 16174 times)

nobody

  • Guest
Equates across module boundaries
« on: April 20, 2009, 09:55:35 PM »
Jeff Duntemann here; I need to set up a SourceForge account one of the days...

Hey, I just did something that I thought was impossible, or at least impossible when I learned NASM a very long time ago: I passed an equate between two separately assembled modules, simply by marking the equate label GLOBAL in one module and EXTERN in the other. I then defined the equate in the usual fashion for extracting the length of a string:

message: db "Eat at Joe's!"
MSGLEN: equ $-message

Shazam! The length of message came across intact under the label MSGLEN and could be loaded in a register with MOV. My understanding of how NASM handles equates suggests that this is impossible, and I'd be curious to know how NASM inserts equates into an ELF object file. What I guess I want to know the most (given that the doc is silent on this matter) is whether this behavior is "kosher" and supported, experimental, accidental, deprecated, or what? I use NASM but I don't generally dig around inside its guts.

If it's a feature, I want to describe it in the next edition of my assembly book; if it's not a feature I'll let it slide.

Any advice? Thanks very much in advance.

--73--

--Jeff Duntemann
  Colorado Springs, Colorado

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Equates across module boundaries
« Reply #1 on: April 21, 2009, 02:08:32 AM »
Hello Jeff,

AFAIK, "equ" creates a symbol like any other, and "global"/"extern" should work on it. I guess the clue in the documentation would be "this is not a preprocessor symol, either". A preproccesor symbol never makes it into the code, of course, but "equ" creates a "real symbol". "objdump -t" describes it as "*ABS*". I think you can consider it a "feature" you can count on.

I'm fooling with a Linux version of your "eat4", using vt100 sequences to do the "gotoxy". I don't know how useful this is. How likely are we to encounter a machine (in the "desktop" target audience) that *doesn't* have vt100 support? You're probably better off using the display routines Jeff Owens is working on...

I think I've mentioned that in your "eat3", on line 113 (as downloaded from your site) "mov DX, LRXY" should be "mov DX, [LRXY]" (an important distinction!) Presumably you've got that fixed...

I'm about to answer a question on alt.lang.asm, which asks about books... and 64-bit code. Do you anticipate including any 64-bit material in the new edition?

Hey, we could throw in a plug for your site! http://www.duntemann.com isn't it?

Best,
Frank

nobody

  • Guest
Re: Equates across module boundaries
« Reply #2 on: April 21, 2009, 10:42:44 PM »
Yes, I looked at the symbol table listing the other day, and they seem to be stored just the same as any global would, which is an interesting and useful thing, assuming it's going to "stick" as a feature. In the past I used to create named dd items and give them the value of the associated equate when I needed to export a value defined as an equate. I guess I don't need to do that anymore, and it would be worth a page or two in my third edition.

Funny you should mention VT100 sequences. I did a screen control library a few days ago for the book, using the [yy;xxH sequence, and it works very well, as long as the console window is larger than the largest dimension passed to sys_write. I also used the [2J sequence for clearing the console window, with complete success. I've screwed with ncurses in the past, but it seems to be a lot more trouble than it's worth, and really doesn't belong in a beginner's book. I'm about to translate the terminal control procs to macros, and will then bake the whole thing into Chapter 10.

I would have fixed that old LRXY typo except that that was all DOS era BIOS stuff and just went out the window when I started in on the third edition. This one is all-Linux.

In the earlier chapters I mention the existence of 64-bit CPUs, but I have a page budget from the publisher and really can't afford to teach too much on it.

My new edition should be out by early 2010. I'm still plowing away on chapters, and although we may see page proofs by November, I don't think real books will be off-press before February. It's still ASSEMBLY LANGUAGE STEP BY STEP from John Wiley & Sons, Third Edition.

And my three main sites are indeed duntemann.com, junkbox.com (for Maker stuff) and contrapositivediary.com, my general-interest blog.

Good luck and many thanks for taking the time to respond. I'll go over to alt.lang.asm in the near future and see what's going on.

--73--

--JD--

nobody

  • Guest
Re: Equates across module boundaries
« Reply #3 on: April 22, 2009, 01:37:49 AM »
Yes, I looked at the symbol table listing the other day, and they seem to be stored just the same as any global would, which is an interesting and useful thing, assuming it's going to "stick" as a feature. In the past I used to create named dd items and give them the value of the associated equate when I needed to export a value defined as an equate. I guess I don't need to do that anymore, and it would be worth a page or two in my third edition.

Funny you should mention VT100 sequences. I did a screen control library a few days ago for the book, using the [yy;xxH sequence, and it works very well, as long as the console window is larger than the largest dimension passed to sys_write. I also used the [2J sequence for clearing the console window, with complete success. I've screwed with ncurses in the past, but it seems to be a lot more trouble than it's worth, and really doesn't belong in a beginner's book. I'm about to translate the terminal control procs to macros, and will then bake the whole thing into Chapter 10.

I would have fixed that old LRXY typo except that that was all DOS era BIOS stuff and just went out the window when I started in on the third edition. This one is all-Linux.

In the earlier chapters I mention the existence of 64-bit CPUs, but I have a page budget from the publisher and really can't afford to teach too much on it.

My new edition should be out by early 2010. I'm still plowing away on chapters, and although we may see page proofs by November, I don't think real books will be off-press before February. It's still ASSEMBLY LANGUAGE STEP BY STEP from John Wiley & Sons, Third Edition.

And my three main sites are indeed duntemann.com, junkbox.com (for Maker stuff) and contrapositivediary.com, my general-interest blog.

Good luck and many thanks for taking the time to respond. I'll go over to alt.lang.asm in the near future and see what's going on.

--73--

--JD--