I'm making my best effort at following this tutorial as my first bit of ever actually writing assembly. Start small, right? ;)
Anyway... here's what I've got.
[patrick@manifold-arch Assembly]$ cat loader.s
.code16 # we're operating in 16bit real mode
.global begin # make the begin tag globally accessible
begin: # traditionally called _start, but who cares?
jmp begin # infinite loop!
.fill 510-(.-begin), 1, 0 # pad with zeroes till 510 bytes
Cool.
[patrick@manifold-arch Assembly]$ as -o loader.o loader.s
[patrick@manifold-arch Assembly]$ ld -o loader.bin loader.o --oformat binary -e begin --nmagic
[patrick@manifold-arch Assembly]$ ls -lh
total 12K
-rwxr-xr-x 1 patrick patrick 558 Mar 10 11:17 loader.bin
-rw-r--r-- 1 patrick patrick 1.3K Mar 10 11:16 loader.o
-rw-r--r-- 1 patrick patrick 288 Mar 10 10:49 loader.s
First, I was getting 4k files, so I rifled around until I discovered --nmagic. Problem solved. Kind of. My .o file is consistently smaller amusingly enough. But, when I slap the -n flag onto ld, I still wind up with an extra 48 bytes in file size.
[patrick@manifold-arch Assembly]$ objdump -D -Matt,i386 -b binary -m i386 -ls loader.bin
loader.bin: file format binary
Contents of section .data:
0000 04000000 20000000 05000000 474e5500 .... .......GNU.
0010 020001c0 04000000 00000000 00000000 ................
0020 010001c0 04000000 01000000 00000000 ................
0030 ebfe0000 00000000 00000000 00000000 ................
0040 00000000 00000000 00000000 00000000 ................
0050 00000000 00000000 00000000 00000000 ................
0060 00000000 00000000 00000000 00000000 ................
0070 00000000 00000000 00000000 00000000 ................
0080 00000000 00000000 00000000 00000000 ................
0090 00000000 00000000 00000000 00000000 ................
00a0 00000000 00000000 00000000 00000000 ................
00b0 00000000 00000000 00000000 00000000 ................
00c0 00000000 00000000 00000000 00000000 ................
00d0 00000000 00000000 00000000 00000000 ................
00e0 00000000 00000000 00000000 00000000 ................
00f0 00000000 00000000 00000000 00000000 ................
0100 00000000 00000000 00000000 00000000 ................
0110 00000000 00000000 00000000 00000000 ................
0120 00000000 00000000 00000000 00000000 ................
0130 00000000 00000000 00000000 00000000 ................
0140 00000000 00000000 00000000 00000000 ................
0150 00000000 00000000 00000000 00000000 ................
0160 00000000 00000000 00000000 00000000 ................
0170 00000000 00000000 00000000 00000000 ................
0180 00000000 00000000 00000000 00000000 ................
0190 00000000 00000000 00000000 00000000 ................
01a0 00000000 00000000 00000000 00000000 ................
01b0 00000000 00000000 00000000 00000000 ................
01c0 00000000 00000000 00000000 00000000 ................
01d0 00000000 00000000 00000000 00000000 ................
01e0 00000000 00000000 00000000 00000000 ................
01f0 00000000 00000000 00000000 00000000 ................
0200 00000000 00000000 00000000 00000000 ................
0210 00000000 00000000 00000000 00000000 ................
0220 00000000 00000000 00000000 0000 ..............
Disassembly of section .data:
00000000 <.data>:
0: 04 00 add $0x0,%al
2: 00 00 add %al,(%eax)
4: 20 00 and %al,(%eax)
6: 00 00 add %al,(%eax)
8: 05 00 00 00 47 add $0x47000000,%eax
d: 4e dec %esi
e: 55 push %ebp
f: 00 02 add %al,(%edx)
11: 00 01 add %al,(%ecx)
13: c0 04 00 00 rolb $0x0,(%eax,%eax,1)
...
1f: 00 01 add %al,(%ecx)
21: 00 01 add %al,(%ecx)
23: c0 04 00 00 rolb $0x0,(%eax,%eax,1)
27: 00 01 add %al,(%ecx)
29: 00 00 add %al,(%eax)
2b: 00 00 add %al,(%eax)
2d: 00 00 add %al,(%eax)
2f: 00 eb add %ch,%bl
31: fe 00 incb (%eax)
...
I see the zeroes from 13 to 1f, but that only accounts for 12 bytes, yes? It seems like that block shouldn't be there at all, but it still doesn't account for everything that I'm getting as extra.
And when I remove the padding, instead of ending up with a 4 byte binary like the author does, I wind up with a 50 byte binary.
I'm clearly doing something wrong, and it's probably just a flag or something. So I've got two questions: one, what am I doing wrong? And two: why does the author get such different outcomes (particularly regarding page alignment) than I do? The article's from 2018, so surely those commands weren't run on a 32-bit machine? I dunno. All I know is I need a hand. =)
Thanks in advance, and as always.