Comparing C to machine language

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

Comparing C to machine language

#1 Post by Flash »

https://www.youtube.com/watch?v=yOyaJXpAYZQ

A clear, easy-to-follow explanation of what happens when a simple C program is compiled.

User avatar
rufwoof
Posts: 3690
Joined: Mon 24 Feb 2014, 17:47

#2 Post by rufwoof »

Machine code is pure binary, which for us is easier to visualise using hex

8B 5D 32 is machine code in hex form that corresponds to 10001011 ... etc in binary. i.e. you look at each individual hex digit as a sequence of 4 bits, then 8 hex is 1000 binary, B hex (11 decimal) is 1011 binary ...etc.

mov ebx, [ebp+32h] is assembly, which is even easier for us to visualise compared to binary or hex machine code. Yet even easier for many/most is to use a higher level language such as C.

When you compile a C program it creates something like mylib.so that might contain 8B 5D 32 hex format object code (actual binary bits) that the machine knows how to process. You can disassemble that machine code so it can be viewed as assembler. The guy in the video has disassembled the machine code that the C program created - turned the binary machine code the C program created back to a more human readable assembler format. He's comparing C to assembler, not the "comparing C to machine language" that the video title suggests. He could just as well have compared C to Basic or Pascal or whatever. Assembler however is a lower level language (closer to machine code) compared to C, Basic, Pascal ..etc. that are considered as higher levels languages.
[size=75]( ͡° ͜ʖ ͡°) :wq[/size]
[url=http://murga-linux.com/puppy/viewtopic.php?p=1028256#1028256][size=75]Fatdog multi-session usb[/url][/size]
[size=75][url=https://hashbang.sh]echo url|sed -e 's/^/(c/' -e 's/$/ hashbang.sh)/'|sh[/url][/size]

User avatar
rockedge
Posts: 1864
Joined: Wed 11 Apr 2012, 13:32
Location: Connecticut, United States
Contact:

#3 Post by rockedge »

I once programmed short diagnostic programs flipping toggle switches and coding in Octal with the output of the program being lights on and off in the cockpit instrument panels and watching a row of lights above the switches. Did Hex on toggle switches and LED front panel to load the bootstrap loader for reading the TInyBasic operating system (microsoft's first product) from a paper tape roll using the tape reader on Teletype 33 to start up an ALTAIR 680B computer built from a kit.

Assembly language is even closer to programming in direct machine CPU instructions

Puppy Linux set up for development does a good job compiling C and C+ programs

User avatar
Burn_IT
Posts: 3650
Joined: Sat 12 Aug 2006, 19:25
Location: Tamworth UK

#4 Post by Burn_IT »

I spent most of my working life writing and supporting programs written in either Cobol or Pl/1 both of which are higher level languages -PL/1 being slightly lower than Cobol and closer to C.
Both - like C - are compiled and end up producing machine code via Assembler which you can get optionally listed (which was definitely recommended by on call support staff)
Anyway, a large part of my job was out of hours support of live production systems when they crashed and dumped in the middle of the night.That meant learning to read the dumps and interpreting the machine code and tracking it back to the original program to find out what had gone wrong.

It is at this point that well written and understandable code becomes important especially if you wanted to remain on speaking terms with me when it was not a program written by me that had failed.
I still twitch nervously when the phone rings late at night.
"Just think of it as leaving early to avoid the rush" - T Pratchett

User avatar
rockedge
Posts: 1864
Joined: Wed 11 Apr 2012, 13:32
Location: Connecticut, United States
Contact:

#5 Post by rockedge »

Hello Burn_IT!

right now COBOL programmers are a super hot commodity here! New Jersey will pay huge bounties and wages right now for example. Matter of fact every state's unemployment system run on mainframes running COBOL programs.....the entire USA banking system runs on COBOL and no young programmers knows how to debug it. Some of these programs are 30 - 40 years old but now to expand or add functions..good luck...so they are looking for the retired COBOL guys.......you could set the price the demand is so high right now

User avatar
Burn_IT
Posts: 3650
Joined: Sat 12 Aug 2006, 19:25
Location: Tamworth UK

#6 Post by Burn_IT »

Yes I know. I was discussing just that with my wife earlier in the week.
Obviously,living in the UK, any support would have to be remote.
I'm not really sure I want to go back to work at 70 in a stressful job having already had heart problems that forced me to retire early anyway, though I would enjoy solving dumps again.
Perhaps I could set up as an occasional crash expert.
Most of my company experience was in the engineering sector (including Rolls Royce engines) and Financial Systems (including several banks - Melon being one), not that the type of system involved is really relevant to cracking dumps though it can help to understand the circumstances.
"Just think of it as leaving early to avoid the rush" - T Pratchett

User avatar
Moose On The Loose
Posts: 965
Joined: Thu 24 Feb 2011, 14:54

#7 Post by Moose On The Loose »

rockedge wrote: [....]
Assembly language is even closer to programming in direct machine CPU instructions

Puppy Linux set up for development does a good job compiling C and C+ programs
Side note: I compiled and made an SFS for the latest GNU-C for precise-light

The trouble with compiling C and C++ programs generally comes from them not really being just C or C++ programs. They almost always need the correct version of each magic wiz-bang that they use. Many of those are available as source code so you can compile them before you compile the project you are working on. This would be great if those things didn't need their own magic wiz-bangs and as you work your way through it you discover you need A to compile B and B to compile A. This has been the reason I have set aside several projects and decided I didn't really need to do that.
I still run a very old version of Octave.

Freepascal works very well on several versions of Puppy and does actually allow code that is truly portable.

Post Reply