Active Topics

 


Reply
Thread Tools
Posts: 1 | Thanked: 0 times | Joined on Nov 2009
#31
Originally Posted by christexaport View Post
Can someone clarify the difference between source code and binary code? I'm just a user, trying to wrap my head around this whole Airplay thing. I wanted to blog about it weeks ago, but there's not much info in a language I can understand.

I, too, want to see some Airplay apps. This sounds good, but could be vaporware.
"source comparability" means that you can take the same source code and compile it for two platforms without changes. For example SDL is a platform that provides source compatibility. i.e. You should be able to compile and run any SDL program on any platform that SDL supports. Indeed source compatibility is the entire point of abstraction layers like SDL.

Airplay on the other hand provides "binary compatibility", which means that there is no need to even recompile the source code to run applications any platforms that Airplay supports.

Another example of a system that supports binary compatibility is java. In this case the claim is that .class files are not platforms specific and should run on any platform with a JVM.
 
Posts: 3,841 | Thanked: 1,079 times | Joined on Nov 2006
#32
Can someone clarify the difference between source code and binary code?
Source code:
Code:
#include <stdio.h>
int main (void)
{
 printf ("Hello, World\n");
 return (0);
}
Binary code: Use a C compiler and tell it to translate the above source code into binary code, aka machine code.
Internally it will first create an assembly representation, that is, machine code written in human readable form (this is not even all of it, just a snippet):
Code:
        .file   "hello.c"
        .section        .rodata
.LC0:
        .string "Hello, World"
        .text
.globl main
        .type   main, @function
main:
.LFB2:
        pushq   %rbp
.LCFI0:
        movq    %rsp, %rbp
.LCFI1:
        movl    $.LC0, %edi
        call    puts
        movl    $0, %eax
        leave
        ret
The 'movl', 'call', 'movq' etc. are assembly code for the Intel x86 CPU (processor). (Lines starting with a dot, e.g. .type, are so-called assembler directives and not CPU instructions). If I compile the same source code (the first piece of code, with the 'printf ("Hello, World\n")' for ARM (the CPU in our Nokia gadgets) it would look a bit different:

Code:
        .cpu arm10tdmi
        .fpu softvfp
        .file   "hello.c"
        .section        .rodata
        .align  2
.LC0:
        .ascii  "Hello, World\n\000"
        .text
        .align  2
        .global main
        .type   main, %function
main:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 1, uses_anonymous_args = 0
        mov     ip, sp
        stmfd   sp!, {fp, ip, lr, pc}
        sub     fp, ip, #4
        ldr     r0, .L2
        bl      printf
        mov     r0, #0
        ldmfd   sp, {fp, sp, pc}
The ARM CPU instructions are different from the x86 CPU instructions. ARM assembly language uses 'mov', ldmfd', 'bl', etc. which are specific for ARM. Some may do the same thing as an x86 instructions with a different name, but often there is no direct equivalent at all. And in any case the set of registers (r0 is one, above), i.e. the internal storage boxes, are different for different CPU architectures.

The assembly code is then translated to machine code, which are just numbers. A snippet of the binary (executable) file for x86 looks something like this when inspected with a hex editor (which shows each numeric value of each byte as a hexadecimal number):
Code:
000520: 48 89 6C 24 D8 4C 89 64 24 E0 48 8D 2D 93 01 20    H.l$.L.d$.H.-.. 
000530: 00 4C 8D 25 8C 01 20 00 4C 89 6C 24 E8 4C 89 74    .L.%.. .L.l$.L.t
000540: 24 F0 4C 89 7C 24 F8 48 89 5C 24 D0 48 83 EC 38    $.L.|$.H.\$.H..8
000550: 4C 29 E5 41 89 FD 49 89 F6 48 C1 FD 03 49 89 D7    L).A..I..H...I..
000560: E8 53 FE FF FF 48 85 ED 74 1C 31 DB 0F 1F 40 00    .S...H..t.1...@.
000570: 4C 89 FA 4C 89 F6 44 89 EF 41 FF 14 DC 48 83 C3    L..L..D..A...H..
000580: 01 48 39 EB 72 EA 48 8B 5C 24 08 48 8B 6C 24 10    .H9.r.H.\$.H.l$.
000590: 4C 8B 64 24 18 4C 8B 6C 24 20 4C 8B 74 24 28 4C    L.d$.L.l$ L.t$(L
0005a0: 8B 7C 24 30 48 83 C4 38 C3 90 90 90 90 90 90 90    .|$0H..8........
0005b0: 55 48 89 E5 53 48 83 EC 08 48 8B 05 08 01 20 00    UH..SH...H.... .
0005c0: 48 83 F8 FF 74 19 BB C8 06 60 00 0F 1F 44 00 00    H...t....`...D..
0005d0: 48 83 EB 08 FF D0 48 8B 03 48 83 F8 FF 75 F1 48    H.....H..H...u.H
0005e0: 83 C4 08 5B C9 C3 90 90 48 83 EC 08 E8 5F FE FF    ...[....H...._..
0005f0: FF 48 83 C4 08 C3 00 00 01 00 02 00 48 65 6C 6C    .H..........Hell
000600: 6F 2C 20 57 6F 72 6C 64 00 00 00 00 01 1B 03 3B    o, World.......;
When I 'execute' the file with the above unreadable stuff it'll write 'Hello, World' and a linefeed in my terminal window.

As you can see from the above, the source code [printf ("Hello, World\n");] can easily be inspected, modified, copied to, and compiled to run on another computer architecture (from a mainframe to an Intel CPU to an ARM CPU or the CPU that runs in your Panasonic TV, or anything).

The assembly code will only be usable for the target architecture only, but you could still go in and modify it somewhat (print something different, or print it twice, for example).

The pure machine code (the binary code) will only be usable on the target architecture and it would be very difficult to modify it to do something else. Not impossible, because almost nothing is, but still.
__________________
N800/OS2007|N900/Maemo5
-- Metalayer-crawler delenda est.
-- Current state: Fed up with everything MeeGo.

Last edited by TA-t3; 2009-11-20 at 11:21.
 
Posts: 1 | Thanked: 0 times | Joined on Jan 2010
#33
Thanks for the conscientious rundown on source vs binary, well said! I'd like to bring to the table the MoSync SDK, which actually IS open source (GPL v2) even if there also is a commercial version available for those who want to both sell commercial software and not to publish their source code (very similar to MySQLs model).

You use c/c++ to develop applications for a number of platforms, one of which is Moblin - not too far off from Maemo, I'd guess, as well as Symbian, j2me, winmob and more.

As for Airplay, I visited their 4.0 release and they had whipped up some kick-*** apps for show - hands down. But for natural reasons they will never support j2me - even though it matters less as time goes by.

Originally Posted by TA-t3 View Post
Source code:
Code:
#include <stdio.h>
int main (void)
{
 printf ("Hello, World\n");
 return (0);
}
Binary code: Use a C compiler and tell it to translate the above source code into binary code, aka machine code.
Internally it will first create an assembly representation, that is, machine code written in human readable form (this is not even all of it, just a snippet):
Code:
        .file   "hello.c"
        .section        .rodata
.LC0:
        .string "Hello, World"
        .text
.globl main
        .type   main, @function
main:
.LFB2:
        pushq   %rbp
.LCFI0:
        movq    %rsp, %rbp
.LCFI1:
        movl    $.LC0, %edi
        call    puts
        movl    $0, %eax
        leave
        ret
The 'movl', 'call', 'movq' etc. are assembly code for the Intel x86 CPU (processor). (Lines starting with a dot, e.g. .type, are so-called assembler directives and not CPU instructions). If I compile the same source code (the first piece of code, with the 'printf ("Hello, World\n")' for ARM (the CPU in our Nokia gadgets) it would look a bit different:

Code:
        .cpu arm10tdmi
        .fpu softvfp
        .file   "hello.c"
        .section        .rodata
        .align  2
.LC0:
        .ascii  "Hello, World\n\000"
        .text
        .align  2
        .global main
        .type   main, %function
main:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 1, uses_anonymous_args = 0
        mov     ip, sp
        stmfd   sp!, {fp, ip, lr, pc}
        sub     fp, ip, #4
        ldr     r0, .L2
        bl      printf
        mov     r0, #0
        ldmfd   sp, {fp, sp, pc}
The ARM CPU instructions are different from the x86 CPU instructions. ARM assembly language uses 'mov', ldmfd', 'bl', etc. which are specific for ARM. Some may do the same thing as an x86 instructions with a different name, but often there is no direct equivalent at all. And in any case the set of registers (r0 is one, above), i.e. the internal storage boxes, are different for different CPU architectures.

The assembly code is then translated to machine code, which are just numbers. A snippet of the binary (executable) file for x86 looks something like this when inspected with a hex editor (which shows each numeric value of each byte as a hexadecimal number):
Code:
000520: 48 89 6C 24 D8 4C 89 64 24 E0 48 8D 2D 93 01 20    H.l$.L.d$.H.-.. 
000530: 00 4C 8D 25 8C 01 20 00 4C 89 6C 24 E8 4C 89 74    .L.%.. .L.l$.L.t
000540: 24 F0 4C 89 7C 24 F8 48 89 5C 24 D0 48 83 EC 38    $.L.|$.H.\$.H..8
000550: 4C 29 E5 41 89 FD 49 89 F6 48 C1 FD 03 49 89 D7    L).A..I..H...I..
000560: E8 53 FE FF FF 48 85 ED 74 1C 31 DB 0F 1F 40 00    .S...H..t.1...@.
000570: 4C 89 FA 4C 89 F6 44 89 EF 41 FF 14 DC 48 83 C3    L..L..D..A...H..
000580: 01 48 39 EB 72 EA 48 8B 5C 24 08 48 8B 6C 24 10    .H9.r.H.\$.H.l$.
000590: 4C 8B 64 24 18 4C 8B 6C 24 20 4C 8B 74 24 28 4C    L.d$.L.l$ L.t$(L
0005a0: 8B 7C 24 30 48 83 C4 38 C3 90 90 90 90 90 90 90    .|$0H..8........
0005b0: 55 48 89 E5 53 48 83 EC 08 48 8B 05 08 01 20 00    UH..SH...H.... .
0005c0: 48 83 F8 FF 74 19 BB C8 06 60 00 0F 1F 44 00 00    H...t....`...D..
0005d0: 48 83 EB 08 FF D0 48 8B 03 48 83 F8 FF 75 F1 48    H.....H..H...u.H
0005e0: 83 C4 08 5B C9 C3 90 90 48 83 EC 08 E8 5F FE FF    ...[....H...._..
0005f0: FF 48 83 C4 08 C3 00 00 01 00 02 00 48 65 6C 6C    .H..........Hell
000600: 6F 2C 20 57 6F 72 6C 64 00 00 00 00 01 1B 03 3B    o, World.......;
When I 'execute' the file with the above unreadable stuff it'll write 'Hello, World' and a linefeed in my terminal window.

As you can see from the above, the source code [printf ("Hello, World\n");] can easily be inspected, modified, copied to, and compiled to run on another computer architecture (from a mainframe to an Intel CPU to an ARM CPU or the CPU that runs in your Panasonic TV, or anything).

The assembly code will only be usable for the target architecture only, but you could still go in and modify it somewhat (print something different, or print it twice, for example).

The pure machine code (the binary code) will only be usable on the target architecture and it would be very difficult to modify it to do something else. Not impossible, because almost nothing is, but still.
 
Reply


 
Forum Jump


All times are GMT. The time now is 06:38.