flat assembler
Message board for the users of flat assembler.

Index > Main > fasm and fasmg x86_64 compile differences

Author
Thread Post new topic Reply to topic
chris03_dev



Joined: 24 Oct 2020
Posts: 3
chris03_dev
Good day.

I was learning to make my own ELF executable in elf.asm for flat assembler g when I compared the outputs of the otherwise identical elf2.asm for the original flat assembler. I noticed that the message won't print on the elf binary output, however, so I needed to take a look on the assembly binary output.

elf.asm hexdump:
Code:
0000000 457f 464c 0102 0001 0000 0000 0000 0000
0000010 0002 003e 0001 0000 10b7 0040 0000 0000
0000020 0040 0000 0000 0000 0000 0000 0000 0000
0000030 0000 0000 0040 0038 0002 0040 0000 0000
0000040 0001 0000 0002 0000 0000 0000 0000 0000
0000050 0000 0040 0000 0000 0000 0040 0000 0000
0000060 00b7 0000 0000 0000 00b7 0000 0000 0000
0000070 1000 0000 0000 0000 0001 0000 0001 0000
0000080 00b7 0000 0000 0000 10b7 0040 0000 0000
0000090 10b7 0040 0000 0000 0020 0000 0000 0000
00000a0 0020 0000 0000 0000 1000 0000 0000 0000
00000b0 6548 6c6c 0a6f 4800 c0c7 0001 0000 c748
00000c0 b0c6 0000 4800 c2c7 0007 0000 050f c748
00000d0 3cc0 0000 0f00 0005                    
00000d7    


elf2.asm hexdump:
Code:
0000000 457f 464c 0102 0001 0000 0000 0000 0000
0000010 0002 003e 0001 0000 10b7 0040 0000 0000
0000020 0040 0000 0000 0000 0000 0000 0000 0000
0000030 0000 0000 0040 0038 0002 0040 0000 0000
0000040 0001 0000 0002 0000 0000 0000 0000 0000
0000050 0000 0040 0000 0000 0000 0040 0000 0000
0000060 00b7 0000 0000 0000 00b7 0000 0000 0000
0000070 1000 0000 0000 0000 0001 0000 0001 0000
0000080 00b7 0000 0000 0000 10b7 0040 0000 0000
0000090 10b7 0040 0000 0000 0020 0000 0000 0000
00000a0 0020 0000 0000 0000 1000 0000 0000 0000
00000b0 6568 6c6c 0a6f 4800 c0c7 0001 0000 c748
00000c0 b0c6 4000 4800 c2c7 0007 0000 050f c748
00000d0 3cc0 0000 0f00 0005                    
00000d7
    


What's important is in 0x00000c4. As I see it, the specific instruction 'mov rsi, hello' has a different output between fasm 1 and fasmg. I need to understand why it does such, and how this could be fixed.

The include files used to in the 'elf.asm' file are unmodified, just in case someone wants to ask.


Description: File for fasm, for comparison with elf.asm
Download
Filename: elf2.asm
Filesize: 167 Bytes
Downloaded: 228 Time(s)

Description: File for fasmg, made without any ELF include files
Download
Filename: elf.asm
Filesize: 7 KB
Downloaded: 233 Time(s)

Post 12 Jan 2021, 06:54
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7990
Location: Kraków, Poland
Tomasz Grysztar
Your question (and this thread's title) is a bit misleading, because both sources that you provide can be assembled with fasmg, showing the same difference in output (becase fasmg assembles elf2.asm with the result identical to the one produced by fasm 1). Therefore this is not really about differences between fasm and fasmg, but about differences when trying to reconstruct a file made using standard formatter, which you would have even if you used fasmg exclusively for everything.

And the difference is there because you do not set up ORG for your segments, and because of that labels do not get proper addresses assigned and they just refer to file offsets. Simply adding an ORG there would cause some other problems for you, however - because ORG starts a new addressing space, you would need to modify STORE commands to point to the addressing space containing the headers, as it would no longer be the same one.

On a side note, I wouldn't recommend using EVAL in these macros. Under normal circumstances, EVAL is rarely really necessary. You can use REPEAT 1 and name concatenation to access numbered symbols . See my tutorial on making executable files from scratch for some examples.
Post 12 Jan 2021, 09:00
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.