Question

I was compiling a program to find the maximum of numbers in an array.

Edited

I compiled it as follows:

gcc --save-temps max.c -o max

and then on doing

ls -l max*

the output was:

-rwxrwxr-x 1 tapan tapan  7296 Aug 16 01:45 max
-rw-rw-r-- 1 tapan tapan   233 Aug 16 01:45 max.c
-rw-rw-r-- 1 tapan tapan 17894 Aug 16 01:45 max.i
-rw-rw-r-- 1 tapan tapan  1308 Aug 16 01:45 max.o
-rw-rw-r-- 1 tapan tapan  1507 Aug 16 01:45 max.s

My question is: why is the size of .s assembly file larger than .o binary file?

I thought that .o file has binary strings so it will be larger.

Also the final file max has larger size as expected due to linked libraries. But the size of .o file makes me think that .o file doesn't have binary strings but something else. Please correct me if I am wrong somewhere.

Was it helpful?

Solution

If by "binary strings" you mean ASCII-encoded (i.e. each 0 or 1 is the ASCII characters 0x30 and 0x31) so you can open the file in a text editor and see 0001011011111101011101100..., then no. Just have a look at with cat or od (if you're on a unix) or a hex editor, it contains the binary data "directly". The opcode 01001010 takes up one byte in a binary file, not 8 ASCII characters which take 1 byte each.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top