<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'output format' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'output format' posted on the 'x86 Assembly' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2012 Programmers Heaven</copyright>
    <pubDate>Thu, 09 Feb 2012 08:36:39 -0800</pubDate>
    <lastBuildDate>Thu, 09 Feb 2012 08:36:39 -0800</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>output format</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/409296/409296/output-format/</link>
      <description>Hi, i got some problems where I can't find a solution for.&lt;br /&gt;
&lt;br /&gt;
Let's say I wrote something like this:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;global kernel
kernel:
	mov ax, 0xb800
	mov ds, ax
	mov ax, 0
	mov si, ax
	mov al, 'x'
	mov byte [ds:si], al
ret
loop1: jmp loop1&lt;/pre&gt;&lt;br /&gt;
This put the letter 'x' directly in the video memory.&lt;br /&gt;
So if I assemble it in a flat binary, put it on a floppy and boot from it, it works perfectly.&lt;br /&gt;
&lt;br /&gt;
Now the problem is, if I want to combine my assembly object file with a object file from let's say a 'c' program, I can't use the flat binary format.&lt;br /&gt;
So i have to use the elf format.&lt;br /&gt;
So if I use "nasm kernel.asm -f elf -o kernel.o"&lt;br /&gt;
and dissasmble the file and check the specific code it looks like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;00000000  66B800B88ED8      mov eax,0xd88eb800
00000006  66B800006689      mov eax,0x89660000
0000000C  C6                db 0xC6
0000000D  B078              mov al,0x78
0000000F  3E678804C3        mov [dword ds:ebx+rax*8],al
00000014  EBFE              jmp short 0x14
&lt;/pre&gt;&lt;br /&gt;
You see that my "&lt;pre class="sourcecode"&gt;mov ds, ax
mov si, ax&lt;/pre&gt;&lt;br /&gt;
aren't there anymore. And as you could think the code doesn't work anymore.&lt;br /&gt;
&lt;br /&gt;
So is it possible to link assembly with other files using a flat binary?&lt;br /&gt;
Or is it possible to fix the problem of my disapearing code?&lt;br /&gt;
btw: if I use inline assembly in gcc and write the same code and compile it, the exact code dissapears.&lt;br /&gt;
So its not only the problem of nasm, also of gcc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I hope someone understands me? And knows an answer?&lt;br /&gt;
&lt;br /&gt;
If you want more info, just tell me :) thanks..&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/409296/409296/output-format/</guid>
      <pubDate>Sat, 14 Nov 2009 13:14:29 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>Re: output format</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/409296/409993/re-output-format/#409993</link>
      <description>For instance:&lt;br /&gt;
MOV SI, AX -&amp;gt; 89C6&lt;br /&gt;
MOV DS, AX -&amp;gt; 8ED8&lt;br /&gt;
MOV AX, B800 -&amp;gt; B800B8&lt;br /&gt;
00000000  xxB800B88ED8      mov eax,0xd88eb800&lt;br /&gt;
00000006  66B800006689      mov eax,0x89660000&lt;br /&gt;
0000000C  C6                db 0xC6&lt;br /&gt;
That code is there...&lt;br /&gt;
I don't know much about 32-bit&lt;br /&gt;
instruction format, but is your GCC generating&lt;br /&gt;
32-bit code, it looks alot like 16-bit though?&lt;br /&gt;
&lt;br /&gt;
The bootup process is called bootstrapping&lt;br /&gt;
because it is like strapping up a pair of&lt;br /&gt;
boots, one part of the system brings up&lt;br /&gt;
other usually larger parts of the system into&lt;br /&gt;
memory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/409296/409993/re-output-format/#409993</guid>
      <pubDate>Sat, 28 Nov 2009 12:24:02 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>Re: output format</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/409296/409998/re-output-format/#409998</link>
      <description>Basically you're mixing 16-bit and 32-bit code.&lt;br /&gt;
&lt;br /&gt;
For flat binaries, Fasm generates 16-bit code by default,&lt;br /&gt;
but switches to 32-bit if the Elf format is specified. GCC assembles to 32-bit code by default.&lt;br /&gt;
&lt;br /&gt;
Now, notice the prefix 66 in front of the instructions. This prefix changes the operand size. In 16-bit mode, the prefix tells the processor to use the 32-bit eax instead of the default 16-bit ax. In 32-bit mode, it's the other way around.&lt;br /&gt;
&lt;br /&gt;
When compiling to the 32-bit Elf format, Fasm inserts the prefix, because the operand is ax. However, the disassembler is configured to always assume that it sees 16-bit code, so it thinks the prefix means to take eax instead of ax. In that case, since the operands are both 4 bytes instead of 2, the disassembler reads a larger immediate value of 0xd88eb800 instead of 0xb800. The 0xd88e part is the opcode for "mov ds, ax", but now it is considered part of the preceeding instruction and gets lost.&lt;br /&gt;
&lt;br /&gt;
I hope this makes sense.&lt;br /&gt;
&lt;br /&gt;
Also, in user mode Linux you won't be able to write directly to video memory like you could in a bootstrap program, so it won't work anyway :(</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/409296/409998/re-output-format/#409998</guid>
      <pubDate>Sat, 28 Nov 2009 17:41:11 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
  </channel>
</rss>
