c++ - Easiest way to get textualized binary (0s and 1s) for a simple C/CPP program on OSX -
First of all, I know this is a very strange request. I want it as a teaching aid in a computer classroom. It's good to be able to display an instruction in its binary form, which are going to bits in opcode, logic, etc. Full hex is fine, but I am looking for binary if possible.
I am using OSX (Mountain Lion).
I used the following commands (different) to get the assembly:
clang -emit-llvm -s sum CAP clang -S-mllvm - I used the following command to get some hex values: otowal sum. O -tV
But I would really like to get a complete line of binary copy instruction in some way. Some would be ideal to be underlying, but maybe it's asking too much.
I think I could only see the obj code in a hex editor, but did not believe that they would be correctly aligned properly to read or understand "easy".
I can talk only for Linux, but perhaps it still helps. For example (sum.cpp):
#include For example, to get an interspersed source-hex-asm-output, Objdump
. ; Iostream & gt; using namespace std; Int zodiac (int a, int b) {return a + b; } Int main () {int a = 3, b = 4, c; C = Yoga (A, B); Cout & lt; & Lt; C & lt; & Lt; Endl; Return 0; }
Compilation & amp; Objdump:
clang ++ -g sum.cpp objdump -d -S -C -Mintel a.out & gt; Objdump.txt
You can find inside the objdump.txt
and get:
00000000004007f0 & lt; Sum (int, int)>: #include & lt; Iostream & gt; using namespace std; Int Sum (int a, int b) {4007f0: 89 7c 24 Fc mov DWODTttR [RSP-0x4], ADI4007F 4: 89 74 24FOM Dvord PTR [RSP-0x8], ASI Return A + B; 4007f8: 8b 74 24 Fc mov ESI, DWORD PTR [RSP 0x4] 4007fc: 03 74 24 To add F8 ESI, DWORD PTR [RSP 0x8] 400800: 89 f0 mov eax, ESI 400802: C3 Retired 400,803: 66 66 66 66 2e 0f 1f data32 data32 data32 nop word ptr cs: [Rax + Rax * 1 + 0x0] 40080a: 84 00 00 00 00 0000000000400810 & lt; Main & gt:: Integer main () {400,810: 55 push RBP 400,811: 48 89 E5 Mov RBP, RSP 400814: 48 83 EC 20 Dy. RF, 0x20 400818: C745 FC 00 00 00 MOG DeDWRS PTR [RBP- 0x4], 0x0 int aA3, b = 4, c; 40081f: C7 45 F8 03 00 00 MOV DWORD PTR [RBP-0x8], 0x3 400826: C7 45 F4 04 00 00 MOV DWORD PTR [RBP-0xc], 0x4 c = zodiac (A, B); 40082d: 8b 7 days F8 mov EDI, DWORD PTR [RBP-0x8] 400830: 8b 75 F4 Mov ESI, DWORD PTR [RBP-0xc] 400833: e8 B8 FF FF FF Phone 4007f0 & LT; Amount (int, int)> 400838: 48 8D3C 25 40D 60Lia RDI, DS: 0x600d40 40083F: 00 400840: 89 45 FT MOV Deedblock PTR [RBP-0x10], EX Cot & LT; & Lt; C & lt; & Lt; Endl; 400843: 8b 75 f0 mov esi, dword ptr [rbp-0x10] 400846: e8 05 fe ff ff call 400650 & lt; Std :: ostream :: operator & lt; (Int) @ plt & gt; 40084b: 48 8d 34 25 B0 06 40 Li RSI, DS: 0x4006b0 400,852: 00 400853: 48 89 C7 mov RDI, Rax 400856: E8 45 Fe FF FF Call 4006a0 & lt; Std :: ostream :: operator's & lt; & Lt; (STD :: Ostream End (*) (Study :: Ostream End) @ PTT & gt; 40085b: B900 00 00 00 MOG ECX, 0x0 Returns 0; 400860: 48 89 45 e8 mov QWORD PTR [RBP-0x18], Rax 400864: 89c8 mov eax, ECX 400866: 48 83C4 20Ad RSP, 0x20 40086a: 5D Pop RBP 40086b: C3 Retired 40086c: 0f 40 00 nop 1f DWORD PTR [rax + 0x0]
The last step will be to develop a program that converts hex into binary.
Comments
Post a Comment