Universities and machine code

  • Thread starter Deleted member 53988
  • Start date
D

Deleted member 53988

Guest
Hi,

The graudeejs said in 2014 the following about machine code:

"graudeejs wrote: Binary coding is used when assembler doesn't support some
instructions of CPU i.e. assembler is not new enough. So I wouldn't
say binary coding is dead. :)

You basically code in asm and then write instruction as byte sequence. :)"

"apple wrote:While Herbert Schildt says Assembly creates other
problems, people say that nobody uses nowadays binary code, many of
you contradicted these people".

"graudeejs wrote: Who cares what While Herbert Schildt says? Not me.

However he is true, that in 99.999999% real world stuff binary code /
assembly is not used".

"apple wrote:If it is true that Assembly does not create too many
problems, binary code is not dead and other answers you have posted on
this topic which also contradicts several programming statements
including statements made by Herbert Schildt",

"apple wrote: perhaps the knowledge of computer programming you learned
is a the best in the world".

"graudeejs wrote: I seriously doubt".

"apple wrote:I asked twice where you learned computer programming and
unfortunately did not respond".

"graudeejs wrote: You didn't (at least to me")

"apple wrote:I do not regret not having responded because both appeared
graudeejs saying that binary code is not dead".

"graudeejs wrote: In my university there are still assembly lessons. I love assembly. In some other universities there are even binary coding lessons".

"apple wrote: I beg you to tell me where you learned computer
programming, for example, Assembly, C, etc".?

"graudeejs wrote: At home, in front of my computer. Where else? Not in university... lol"

Reference: http://archive-org.com/page/3491382...eebsd.org/viewtopic.php?f=34&t=42856&start=25

Binary coding still is used when assembler doesn't support some
instructions of CPU?

i.e. assembler is not new enough?

However Herbert Schildt still is true, that in 99.999999% real world stuff binary code /
assembly is not used?

In some other universities still there are even binary coding lessons?

I wonder what Oko would say about it.
 
Apple is a well known troll around here. Citing him as a reference does no good.
 
EDIT: I quoted also graudeejs.
True, but quoting a notorious troll like apple can be considered meta-trolling. And when it comes to that guy, a lot of staff is quite trigger happy. This is just a PSA, please make your case without referencing that source.
 
True, but quoting a notorious troll like apple can be considered meta-trolling. And when it comes to that guy, a lot of staff is quite trigger happy. This is just a PSA, please make your case without referencing that source.

Crivens,

The my case is this:

Binary coding still is used when assembler doesn't support some
instructions of CPU?

i.e. assembler is not new enough?

However Herbert Schildt still is true, that in 99.999999% real world stuff binary code /
assembly is not used?

In some other universities still there are even binary coding lessons?

I wonder what Oko would say about it.
 
Please do not mix generation of programs and execution of them. Some times you need to, even in assembler decks, write an instruction in binary because the assembler does not know it.
Executing anything BUT binary is beyond a CPU, so every program execution involves binary, no matter how the program was build.
 
Please do not mix generation of programs and execution of them. Some times you need to, even in assembler decks, write an instruction in binary because the assembler does not know it.
Executing anything BUT binary is beyond a CPU, so every program execution involves binary, no matter how the program was build.

Crivens,

There are instructions in binary or machine code on FreeBSD development?

If yes, please quote examples.

Machine code is fun.
 
Terminology, this is not the same. Machine code is binary, not all binary is machine code. Hence the 'illegal instruction trap'.

The nearest to binary would be assembler source, with a 1:1 ratio of source statements to machine instruction.
 
Terminology, this is not the same. Machine code is binary, not all binary is machine code. Hence the 'illegal instruction trap'.

Crivens,

Sorry, I meant binary code.

EDIT:

Please do not mix generation of programs and execution of them. Some times you need to, even in assembler decks, write an instruction in binary because the assembler does not know it.
Executing anything BUT binary is beyond a CPU, so every program execution involves binary, no matter how the program was build.

Crivens,

There are instructions in binary code or machine code on FreeBSD development?

If yes, please quote examples.

Machine code is fun.
 
Binary coding still is used when assembler doesn't support some
instructions of CPU?

i.e. assembler is not new enough?
This is very rare. Any up-to-date assembler (e.g. fasm, nasm, gas, etc.) should (theoretically, at least) support the complete set of instructions in its target architecture, including the most peculiar and rarely-used instructions. Modern operating systems like FreeBSD include modern and up-to-date toolchains.

However Herbert Schildt still is true, that in 99.999999% real world stuff binary code / assembly is not used?
In the end, everything from the bootloader to your interpreted Python scripts (or rather the interpreter itself) is made of assembly instructions, which translate into bits of zeroes and ones, which are basically made of streams of electric pulses.

Even if you build some C++ code, under the hood there's a compiler-assembler tandem that's converting the high-level language functions to machine code, even though the developer may not know the slightest thing about assembly.

In some other universities still there are even binary coding lessons?
Most provide a single course in assembly at best if any at all. IT is such a vast field that you could spend an entire lifetime learning. Universities have priorities to meet and must cater to the ever-evolving requirements of labor markets.

There are instructions in binary or machine code on FreeBSD development?

If yes, please quote examples.
Binary, I very much doubt. If you want to see assembly code, run find /usr/src -name *.s

In modern times you'll find only a few operating systems written entirely in assembly (e.g. KolibriOS). Usually assembly is only used for things that cannot be done in higher level languages or that need to be highly optimized (setting up protected/long mode, setting up IDT, GDT and other such structures, fast memory moves, cryptographic computations, etc.) The rest is done in one or more high-level language (e.g. C).
 
I guess that I will add my two cents.

Assembly is a short hand for machine code. Machine code is just numbers viewed in hexadecimal. Look at the following code:

Code:
0804a780 <__do_global_ctors_aux>:
 804a780:       55                      push   %ebp
 804a781:       89 e5                   mov    %esp,%ebp
 804a783:       53                      push   %ebx
 804a784:       83 ec 04                sub    $0x4,%esp
 804a787:       a1 00 b0 04 08          mov    0x804b000,%eax
 804a78c:       83 f8 ff                cmp    $0xffffffff,%eax
 804a78f:       74 12                   je     804a7a3 <__do_global_ctors_aux+0x23>
 804a791:       31 db                   xor    %ebx,%ebx
 804a793:       ff d0                   call   *%eax
 804a795:       8b 83 fc af 04 08       mov    0x804affc(%ebx),%eax
 804a79b:       83 eb 04                sub    $0x4,%ebx
 804a79e:       83 f8 ff                cmp    $0xffffffff,%eax
 804a7a1:       75 f0                   jne    804a793 <__do_global_ctors_aux+0x13>
 804a7a3:       83 c4 04                add    $0x4,%esp
 804a7a6:       5b                      pop    %ebx
 804a7a7:       5d                      pop    %ebp
 804a7a8:       c3                      ret
 804a7a9:       90                      nop
 804a7aa:       90                      nop
 804a7ab:       90                      nop

This was obtained by using objdump -d on a binary file.

The first column is the linear address of the actual instruction in hexadecimal.

The second column with the variable number of hex digits is the iapx80686 32-bit instructions in machine code shown as hexadecimal (If you want to see binary, just directly convert from hex to binary). In general, the first byte is the opcode or the instruction itself. Some simple instructions are one or two bytes. Some instructions are longer because they are more complex (usually because of memory operands). Here's a little tidbit: Intel x64 CPUs can have instructions which are 15 bytes long! This is because Intel x86, x64 machines (AMD included) are CISC (Complex Instruction Set Computing) machines. This is in contrast to RISC (Reduced Instruction Set Computing) machines such as SPARC, MIPS, ARM, AVR, etc... which uses fixed fields in the instruction so the instructions are fixed size. A MIPS/32 machine always has 32-bit instructions. This actually simplifies the fetch and decode logic in the CPU's execution datapath.

The third column is the human readable instruction.

The forth column is the operands (parameters, data) to said instruction.

Using the file command on the same program gives this result:
Code:
binary: ELF 32-bit LSB executable, Intel 80386,
version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1,
for FreeBSD 9.0 (900044), not stripped
So the program is in machine code, even though it was written in C.

When it comes down to it, all CPUs, no matter what manufacturer, language, brand, family, instruction set, etc... all speak binary which is 1's and 0's which in turn translates into electrical impulses that move through logic circuits which performs the actual instructions. So adding two numbers together, the instruction decoder sets the gates to route the data through an adder (Usually a look-ahead carry adder) that physically adds the numbers together.

Now when it comes to compilers (I took a course in compilers...interesting stuff), for x86/x64, compilers use about 25 instructions or so. Now that is interesting because Intel CPUs and their clones (AMD) support over 1,000 instructions.
Here's a short list:

  • nop
  • push/pop
  • call/ret
  • mov
  • add/sub/mul/div
  • and/or/not/xor
  • shl/shr/rol/ror
  • jmp
  • jnz/jz/je/jne/ja/jae/jb/jbe/js/jns/and a few more that I can't remember....
  • cmp/test
That's about it I think. FreeBSD is written mostly in C, but there is some Assembler because C does not support certain things that the CPU might support. For Intel x86/x64 CPUs, there is a separately addressable I/O bus which uses instructions IN and OUT which cannot be generated by the C compiler. You have to use assembly (either inline or a separate .asm or .S file (platform dependent). Another one is the XCHGCMP instruction which is used for making spin locks (gcc and clang both have special builtin functions that will generate that instruction).

Hopefully this will answer your questions.
 
Hopefully this will answer your questions.

Maelstorm,

This does not answer the following questions:

However Herbert Schildt still is true, that in 99.999999% real world stuff binary code /assembly is not used?

In some other universities still there are even binary coding lessons?
 
Maybe some still teach coding in binary, mostly in compiler construction. You have to emit binary at some stage.

And please don't try to ride that dead horse apple left when he got the troll treatment. Get sources of your own for these claims. Then we may discuss if Herbert is full of core dump or not. Now, we are only discussing if we shall close threads.
 
And please don't try to ride that dead horse apple left when he got the troll treatment. Get sources of your own for these claims. Then we may discuss if Herbert is full of core dump or not. Now, we are only discussing if we shall close threads.

It is written in book C: The Complete Reference - Third Editions of Herbert Schildt:

"As a general rule: do not use assembler, creates too many problems".

However Herbert Schildt is true, that in 99.999999% real world stuff binary code /assembly is not used?
 
Depends... without the few lines of assembler in crt0.s, nothing out of a C compiler would work. So no python, sh, ...

He may be right for things done completely in assembler, but without some lines of it 99.999999% of code would not work.

I know of exactly one self-hosting OS which can do without assembler at all.
 
Maybe some still teach coding in binary, mostly in compiler construction. You have to emit binary at some stage.

Not true. You only emit assembly language. The assembler makes the transition from what the compiler outputs to machine code. Compilers have multiple stages of code analysis. The lexicographical analyzer and parser are the front end. They walk through the source code, generating the AST (abstract syntax tree) which is a series of interconnected nodes and lists. Nodes are used for breaking down statements, such as assignments and such. List are used for series of statements. Once you have that, you walk down the tree and generate an internal representation of the code. In our case, we used something called ILOC (Intermediate Language for Optimizing Compilers). Then you do live range analysis and register assignment. Optimization can happen at any stage. The professor who taught the class is one of the people who does optimization research using LLVM.

It is written in book C: The Complete Reference - Third Editions of Herbert Schildt:

"As a general rule: do not use assembler, creates too many problems".

However Herbert Schildt is true, that in 99.999999% real world stuff binary code /assembly is not used?

He's wrong. Because as I stated previously, everything goes to binary code or the CPU will not understand it. I have taken an assembly language class. It's lower division and it's a requirement for a degree in computer science.
 
Interesting, Maelstorm ... the C++ compiler I was involved with directly compiled to binary. If you needed an assembler file, that was done by disassembling the internal object code stream. Compilation is much faster that way. The code generator/peepholer are a bit more complex and harder to debug, but it is worth it. Anyone remembers 'draco' from Cris Gray, or the old turbo pascal systems? Try them in a VM, on modern hardware and enjoy a compiler+IDE living in L1 cache.
 
I've often read what a terrible book the Schildt book is. I own it but have never really delved into it.

I also used to bootstrap mini-computers using toggle switches and programmed EPROM's with wires. I did assembly programming exclusively on embedded processors for many years. I would not consider any school that doesn't teach assembly to CS students trustworthy or respectable.
 
Ok, those are usually part of VLSI design or computer architecture. With VLSI design, you will see binary code of a completely new level ;)
 
Back
Top