A
A
Akmal Kadirov2015-01-18 18:28:32
linux
Akmal Kadirov, 2015-01-18 18:28:32

How to run machine code?

Do not write in assembler, but write machine code and run it.
Probably there will be questions "why" and "for what" - after all, there is an assembler or si. The answer is simple - just for fun.
By the way, you need to run the code in Linux (debian)

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Armenian Radio, 2015-01-18
@gbg

Put dosbox
Write your code in any hex editor.
Save with com extension
Run.
On linux without dosbox you will also need to learn how to build an ELF executable.

J
jcmvbkbc, 2015-01-18
@jcmvbkbc

$ cat > hello.S <<'EOF'
        .data
.Lhello:
        .ascii "Hello, world\n"

        .text
        .global _start
_start:
        movl    $1, %ebx
        leal    .Lhello, %ecx
        movl    $13, %edx
        movl    $4, %eax
        int     $0x80
        movl    $1, %eax
        xorl    %ebx, %ebx
        int     $0x80
EOF
$ gcc -m32 hello.S -nostdlib -o hello
$ ./hello
Hello, world
$

It will be more difficult with bare machine code, because you will need to match the addresses encoded in it with what will be written in the ELF headers. You can make something like this source:
.text
        .global _start
_start:
.incbin "code"

put bare machine code in the code file. Compile as in the first case.
Alternatively, you can insert the dump directly into the assembler:
.text
        .global _start
_start:
        .byte 0xbb, 0x01, 0x00, 0x00, 0x00, 0x8d, 0x0d, 0xb8, 
        .byte 0x80, 0x04, 0x08, 0xba, 0x0d, 0x00, 0x00, 0x00, 
        .byte 0xb8, 0x04, 0x00, 0x00, 0x00, 0xcd, 0x80, 0xb8, 
        .byte 0x01, 0x00, 0x00, 0x00, 0x31, 0xdb, 0xcd, 0x80, 
        .byte 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 
        .byte 0x6f, 0x72, 0x6c, 0x64, 0x0a

You can go the other way and teach Linux to execute bare binaries. See https://www.kernel.org/doc/Documentation/binfmt_mi...

E
Eddy_Em, 2015-01-18
@Eddy_Em

My friend, even the most stubborn arduists no longer think of this! At least they write in assembler, but more often in a normal high-level language.
And under Peck, writing on mashcodes is pure BDSM!

D
Dmitry Polushkin, 2015-02-12
@dmitry-polushkin

Assembler is the same machine code, only using instructions that are accessible to human understanding, which in turn are simply "converted" into machine code, and for different processors in different "numbers". So, of course, you can open intel's documentation on processor opcodes, and start sculpting your creation in the editor using numbers, but you will quickly get tired of this, because. you will constantly forget what the previous line meant. Man, however, is not a digital device, but uses a system of symbols for a long time. Thus, it is much easier for people to understand each other using a symbolic system, and not a system of numbers.
Read: www.intel.com/content/dam/www/public/us/en/document...
I think the same thing exists in the public domain for AMD, ARM, AVR and other types of processors.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question