I run the command view /bin/ls
on FreeBSD 10.3 and I can see the binary file unmodified:
Then on vim/view I run the command :%!xxd
and I can see the file in hex format as follows. I notice at the bottom of the page it is announced by vim that 1708 lines are added and 74 lines are deleted.
I close the vim by :q!
command and I open it again with view /bin/ls
then I run the vim command :%!xxd -b
to see the file in binary format which is shown below. At the bottom of the page it is written 4555 lines are added and 74 lines are deleted.
Now I wonder:
Why are some lines added and some deleted when running
:%!xxd
and:%!xxd -b
commands on vimOn the hex format, i.e. when
%!xxd
command is run, the line addresses are 00000000, 00000010, 00000020, 00000030 and so on. Looks like that's because each line contains 16 bytes, hence the 0x10 increment makes sense.On the binary format, i.e. when
%!xxd -b
command is run, the line addresses are 00000000, 00000006, 0000000c, 00000012 and so on. Looks like that's because each line contains 6 bytes, hence the 0x06 increment makes sense.Previously I was believing that each binary file contains each processor instruction in a single line and at the beginning of each line there is the relative address of that instruction starting from 0 for the first instruction. But Based on my observation of binary files on vim, it is not true. Now i wonder how the processor determines each instruction's opcode and operands, if the instructions are not formatted line-by-line on binary files.
UPDATE:
The last five lines on hex format are:
00006a70: 0100 0000 3000 0000 0000 0000 4862 0000 ....0.......Hb..
00006a80: 3e03 0000 0000 0000 0000 0000 0100 0000 >...............
00006a90: 0100 0000 0100 0000 0300 0000 0000 0000 ................
00006aa0: 0000 0000 8665 0000 d500 0000 0000 0000 .....e..........
00006ab0: 0000 0000 0100 0000 0000 0000 0a .............
The last five lines on binary format are:
00006aa4: 10000110 01100101 00000000 00000000 11010101 00000000 .e....
00006aaa: 00000000 00000000 00000000 00000000 00000000 00000000 ......
00006ab0: 00000000 00000000 00000000 00000000 00000001 00000000 ......
00006ab6: 00000000 00000000 00000000 00000000 00000000 00000000 ......
00006abc: 00001010 .
Therefore, I thinks the total number of bytes are the same for both hex and binary formats, I mean the address of the last byte of code for both would be 0x6abc
.
0x0a
) does/bin/ls
contain? – thrig Jun 5 '17 at 3:01:<range>!<command>
replaces the lines in the range with the output of the command - hence m lines added and n deleted, where m will probably be the current number of lines and n the previous number. – muru Jun 5 '17 at 3:45