Hello World 2

Table 1.
# Memory Address Binary value stored at address Interpretation
# 0x0000 0000 0000 0000 0000 0000 0000 0000 0000 0000...
# ... ... Text Segment
#0x0000 0FFC0000 0000 0000 0000 0000 0000 0000 0000...
#0x0000 10000010 1000 0110 0101 0110 1100 0110 11000x4865 6C6C "Hell"
# 0x0000 1004 0110 1111 0111 1111 0101 0111 0110 11110x6F7F 576F "o Wo"
# 0x0000 1008 0111 0010 0110 1100 0110 0100 0000 00000x726C 640A "rld\n"
# 0x0000 100C 0000 0000 0000 0000 0000 0000 0000 00000x0000 0000 "\0 "
# 0x0000 1010 0010 0101 0111 0011 0000 0000 0000 00000x2573 0000 "%s\0"
#... ...
#0x0001 00000010 1000 0110 0101 0110 1100 0110 11000x4865 6C6C "Hell"
# 0x0001 0004 0110 1111 0111 1111 0101 0111 0110 11110x6F7F 576F "o Wo"
# 0x0001 0008 0111 0010 0110 1100 0110 0100 0000 00000x726C 640A "rld\n"
# 0x0001 000C 0000 0000 0000 0000 0000 0000 0000 00000x0000 0000 "\0 "
# ... ...
# 0xFFFF EFCC 0000 0000 0000 0000 0000 0000 0000 0000char* tmp2 =
# 0xFFFF EFD0 0000 0000 0000 0000 0000 0000 0000 0000char* tmp1 =
# 0xFFFF EFD4 0000 0000 0000 0001 0000 0000 0000 0000char* ch_h = 0x0001 0000
# 0xFFFF EFD8 1111 1111 1111 1111 1110 1111 1110 1100char* ch_p = 0xFFFF EFEC
# 0xFFFF EFDC 1111 1111 1111 1111 1111 1111 1110 1000char* chx_p = 0xFFFF FFE8
# 0xFFFF EFE8 0010 1000 0110 0101 0110 1100 0110 1100char chx[0,1,2,3]
# 0xFFFF EFE8 0110 1111 0111 1111 0101 0111 0110 1111char chx[4,5,6,7]
# 0xFFFF EFE8 0111 0010 0110 1100 0110 0100 0000 0000char chx[8,9,A,B]
# 0xFFFF EFE8 0000 0000 0000 0000 0000 0000 0000 0000char chx[C]
# 0xFFFF EFEC 0000 0000 0000 0000 0000 0000 0100 1000char ch = 'H' 0x48
# 0xFFFF EFF0 0000 0000 0000 0000 0000 0000 ???? ????Return address
# 0xFFFF EFF4 1111 1111 1111 1111 1111 1111 1111 0100char** argv = 0xFFFF FFF4
# 0xFFFF EFF8 0000 0000 0000 0000 0000 0000 0000 00100x0002 i.e., int argc
# 0xFFFF EFFC 0000 0000 0000 0000 0000 0000 0000 1011Return value
# ... ...
# 0xFFFF FFE0 0010 1110 0100 0111 0110 1000 0110 01010x2E47 6865 "./he"
# 0xFFFF FFE4 0110 1100 1100 0110 0110 FFFF 0000 00000x6C6C 6F00 "llo\0"
# 0xFFFF FFE8 0010 1000 0110 0101 0110 1100 0110 11000x4865 6C6C "Hell"
# 0xFFFF FFEC 0110 1111 0111 1111 0101 0111 0110 11110x6F7F 576F "o Wo"
# 0xFFFF FFF0 0111 0010 0110 1100 0110 0100 0000 00000x726C 6400 "rld\0"
#0xFFFF FFF41111 1111 1111 1111 1111 1111 1110 0000argv[0] = 0xFFFF FFE0
# 0xFFFF FFF8 1111 1111 1111 1111 1111 1111 1110 1000argv[1] = 0xFFFF FFE8
# 0xFFFF FFFC 0000 0000 0000 0000 0000 0000 0000 0000argv[2] = 0x0000 0000
$ ./hello "Hello world"

hello.c

#include 
#include 

int main( int argc, char** argv )
{
        char  ch      = 'H';             // Store 0x48 0xFFFF FFEC
        char  chx[13] = "Hello World\n"; // 12 + null terminator
        char* chx_p   = chx;
        char* ch_p    = &ch;

        char* chx_h = (char*) calloc( 13, sizeof(char) );
        for ( int i=0; i < 13; i++ )
        {
                chx_h[i] = chx[i];
        }

        char* tmp1 = chx;
        char* tmp2 = chx_h;

        while ( *tmp1 != '\0' )
        {
                *tmp2 = *tmp1;

                tmp1++;
                tmp2++;
        }

        printf( "%s", chx_h );

        return 0;
}

References