Author Topic: Reading Assembly from standard input  (Read 19834 times)

Offline Fl0wless

  • Jr. Member
  • *
  • Posts: 5
Reading Assembly from standard input
« on: July 15, 2021, 06:34:33 PM »
Hello! I'm generating assembly and want to pass it to nasm. (How) Can I pass the source via stdin? (I tried the standard - but it didn't work.) Couldn't find anything on the web or in the forums. Or do I have to create a temp file?
Many thanks!

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Reading Assembly from standard input
« Reply #1 on: July 16, 2021, 10:42:35 PM »
Hi Fl0wless

Welcome to the forum.

Nasm takes multiple passes over the file you present to it, so I don't think stdin  is going to work.

Best,
Frank


Offline Fl0wless

  • Jr. Member
  • *
  • Posts: 5
Re: Reading Assembly from standard input
« Reply #2 on: July 17, 2021, 10:25:07 AM »
Hi! Thanks for the answer, that is a bit unfortunate. Although that makes me a bit curious. Why does Nasm need to read the file multiple times? Does the preprocessor not work on a token basis? Do you try to generate the result on the fly without having the file fully in-memory (like old c compilers did out of space constraints)? Or is it some other reason? Much appreciated!

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Reading Assembly from standard input
« Reply #3 on: July 17, 2021, 11:26:28 PM »
Code: [Select]
jmp foo
How far away is "foo"? Can it be a short jump or does it have to be a  near jump?

If you want a single pass assembler. try spasm/rosasm. (that's not a serious suggestion)
There may be other single pass assemblers... I don't know...
 Nasm started off as two pass and went to  multi pass after 0.98.

Best,
Frank



Offline Fl0wless

  • Jr. Member
  • *
  • Posts: 5
Re: Reading Assembly from standard input
« Reply #4 on: July 18, 2021, 10:51:18 AM »
But why re-parse the asm file? Why not store the token stream in-memory? Do you then not have to re-apply the macros?

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Reading Assembly from standard input
« Reply #5 on: July 18, 2021, 10:19:33 PM »
Nasm is Nasm.
If you prefer some other assembler. go for it.

Best,
Frank


Offline Fl0wless

  • Jr. Member
  • *
  • Posts: 5
Re: Reading Assembly from standard input
« Reply #6 on: July 19, 2021, 11:44:03 AM »
No, no, that's not meant as criticism! Just purely out of interest.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Reading Assembly from standard input
« Reply #7 on: July 19, 2021, 10:16:52 PM »
I really don't know. That's just the way it was done. I believe it does reprocess macros, yes.

Let me try a question for you... Why in the world would you want to produce a file the source for which has vanished forever?

Best,
Frank


Offline Fl0wless

  • Jr. Member
  • *
  • Posts: 5
Re: Reading Assembly from standard input
« Reply #8 on: July 25, 2021, 05:59:15 AM »
Well, I could generate assembly, spawn Nasm as a subprocess, pipe the assembly in, and not worry about creating files / deleting files / worrying about old code fragments. Like I said, not really important, was just my initial approach.
Best regards,
Janis