User:New16

From OSDev Wiki
Jump to navigation Jump to search

Opcode Programming

Any beginner should start here.

Before starting assembly or high-level language programming you should know: The processor does only understand opcode. Simply consider this languages named above to be helpful, but they must be interpreted by so called compilers, linkers and assemblers to create the necessary opcode.

So just grab an instance of "Intel® 64 and IA-32 Architectures Software Developer’s Manual", with the subtitle: "Combined Volumes: 1, 2A, 2B, 2C, 3A, 3B, 3C and 3D" (4618 pages in June 2016), and go on with this tutorial.

(Just type the title in the search at "intel.com" .)

Basics

You should read at least the following sections (I recommend this order.):

You might want to run the following code in an emulator. For windows user I recommend VirtualBox: Set up a new machine with "Typ: Other" and "Version: Other/Unknown (64-bit)" and make sure you find a floppy-controller under section "Storage".
You also need a hex-editor (f.e. "https://hexed.it/").
After editing and saveing the file, named: "something.img", you should close the hex-editor (-website).

First Program

Type in the hex editor (without the leading zero and the "h" at the end):

0EBh, 0FEh
;now expand this file with zeros until you reached address 510 (01FEh)
0, 0, ...
;at address 510 (01FEh) insert:
0AAh
;at adress 511 (01FFh) insert:
055h

Add this file to you floppy controller in your emulator (f.e. VirtualBox).
Run your virtual machine.
And you will see: nothing. But you will be able to notice a massive CPU-usage.
It worked! Whatever you have done...

Explanation

Lets start from the beginning, 0xEB and 0xFE is a JMP opcode which makes the computer execute this code over and over.
The last 2 bytes are the boot signature, for the computer to understand that this floppy is a bootable floppy disk.