OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Mar 19, 2024 1:08 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Learning machine code.
PostPosted: Fri Oct 21, 2016 1:30 pm 
Offline
Member
Member

Joined: Sun Oct 09, 2016 4:38 am
Posts: 273
So you want to program some binary just from assembler? Great. If you want, you can get this tutorial to help you, and write a Hello World without getting your NASM.
Okay, let's do this.
First, look at opcodes for the 8086/8088 or common instructions in the 6502. We're doing 8088 today.
So, let's translate this:
Code:
mov ax, 5Ch
mov dl, ax
mov ch, ax

into pure 8088 binary.
I'm just gonna skip the possible deadline you MAY hit. First, let's do some "off-code" stuff, and restore any possible changes, to not hit the deadline (there is no opcode for specifically making AX 5C possible directly.)
Let's set BX to 005Ch. We have to use words, and this is the same value anyway!
"0xBB 0x00 0x5C"
And properly set BX to ax doing mov ax, bx.
"0x89 0xD8".
We can't clear BX. That's not a problem. The code never does anything with BX anyway.
Let's do
Code:
mov dl, ax
mov ch, ax
, though.
We, cannot move by ourselves "mov dl, ax". Let's do the equivalent: "mov dl, 5Ch". This is available.
"0xB2 0x5C".
That was easy.
Same problem with "mov ch, ax". Let's do the equivalent, which is available, yet again.
"0xB5 0x5C".
The program terminates.



TL;DR: That code in the closest-to-code-possible-way-in-8088 = 0xBB 0x00 0x5C 0x89 0xD8 0xB2 0x5C 0xB5 0x5C.

And if you want to switch to VGA:

0xB0 0x13 0xCD 0x40

which is
Code:
mov ah, 13h
int 10h
.

Those are some examples. You can simply do "mov ah, ACh" by doing:
0xB0 0xAC.
0xB0 = mov ah
0xAC = , ACh
= mov ah, ACh

_________________
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS


Top
 Profile  
 
 Post subject: Re: Learning machine code.
PostPosted: Fri Oct 21, 2016 1:36 pm 
Offline
Member
Member
User avatar

Joined: Mon Apr 18, 2016 9:50 am
Posts: 138
Location: New York New York
Wow. Even knowing what you were getting at, I did not understand a word of it. You either need to rewrite this much longer with greatly more exhaustive prose or much shorter as:

Quote:
If you want to hand-assemble some code, get a copy of your CPU manual and look up the opcode tables


No offense, but you seem to be suffering from I'm-not-as-smart-as-I-think-I-am syndrome of late. No worries, I think many people start out there. But it's something you need to be self aware of.

_________________
The OS is P5. Don't expect it to build.


Top
 Profile  
 
 Post subject: Re: Learning machine code.
PostPosted: Fri Oct 21, 2016 1:53 pm 
Offline
Member
Member

Joined: Sun Oct 09, 2016 4:38 am
Posts: 273
jojo wrote:
Wow. Even knowing what you were getting at, I did not understand a word of it. You either need to rewrite this much longer with greatly more exhaustive prose or much shorter as:

Quote:
If you want to hand-assemble some code, get a copy of your CPU manual and look up the opcode tables


No offense, but you seem to be suffering from I'm-not-as-smart-as-I-think-I-am syndrome of late. No worries, I think many people start out there. But it's something you need to be self aware of.

It looks confusing but if you look, it is pretty much understandable, and also explains some things you may run into.
The website i mentioned has the information i got from.

_________________
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS


Top
 Profile  
 
 Post subject: Re: Learning machine code.
PostPosted: Fri Oct 21, 2016 2:43 pm 
Offline
Member
Member
User avatar

Joined: Wed Aug 31, 2016 9:53 pm
Posts: 81
Location: San Diego, CA
Why are you posting this here?
There is almost no reason I can think of for directly coding in the opcodes, outside of very specific applications like code injection.

If you really want to learn about how assembly is translated into machine code, I suggest you write a simple assembler or disassembler.

_________________
Some of my open-source projects:
Ext2/ELF32 bootloader
Lightweight x86 assembler, designed to be portable for osdev
Scheme in under 1000 lines of C


Top
 Profile  
 
 Post subject: Re: Learning machine code.
PostPosted: Fri Oct 21, 2016 2:46 pm 
Offline
Member
Member

Joined: Sun Oct 09, 2016 4:38 am
Posts: 273
crunch wrote:
Why are you posting this here?
There is almost no reason I can think of for directly coding in the opcodes, outside of very specific applications like code injection.

If you really want to learn about how assembly is translated into machine code, I suggest you write a simple assembler or disassembler.

This is to teach people, not learn-it-myself-how-can-i-do-it-help-plz-i-need-it-halp-pls-;(.

_________________
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS


Top
 Profile  
 
 Post subject: Re: Learning machine code.
PostPosted: Fri Oct 21, 2016 2:48 pm 
Offline
Member
Member
User avatar

Joined: Mon Apr 18, 2016 9:50 am
Posts: 138
Location: New York New York
Nuno, I'm trying to be a nice guy, here, but frankly the irritation over the fact that you don't seem to actually slow down and listen to anyone -- especially when they're trying to help you out and give you pointers instead of just resorting to insulting you -- is starting to get even to me, dude.

_________________
The OS is P5. Don't expect it to build.


Top
 Profile  
 
 Post subject: Re: Learning machine code.
PostPosted: Fri Oct 21, 2016 2:53 pm 
Offline
Member
Member

Joined: Sat Mar 28, 2015 11:23 am
Posts: 103
NunoLava1998 wrote:
crunch wrote:
Why are you posting this here?
There is almost no reason I can think of for directly coding in the opcodes, outside of very specific applications like code injection.

If you really want to learn about how assembly is translated into machine code, I suggest you write a simple assembler or disassembler.

This is to teach people, not learn-it-myself-how-can-i-do-it-help-plz-i-need-it-halp-pls-;(.


Do you realize the subforum you're posting in? I can help you out. It's O S D E V E L O P M E N T. Yes, it's not the FASM forum boards, or stack overflow, or a random blog. Not a place for stupid "tutorials".

Oh, and I hope you realize everything you typed out on your "tutorial" can be replaced by a simple "Go look for the Opcode tables on the Intel manual". And no, nobody uses machine code directly anymore, that's why they invented assembly.

edit: typo

_________________
If some of you people keep insisting on having backwards compatibitity with the stone age, we'll have stone tools forever.
My Hobby OS: https://github.com/heatd/Onyx


Top
 Profile  
 
 Post subject: Re: Learning machine code.
PostPosted: Fri Oct 21, 2016 2:54 pm 
Offline
Member
Member
User avatar

Joined: Wed Aug 31, 2016 9:53 pm
Posts: 81
Location: San Diego, CA
NunoLava1998 wrote:
crunch wrote:
Why are you posting this here?
There is almost no reason I can think of for directly coding in the opcodes, outside of very specific applications like code injection.

If you really want to learn about how assembly is translated into machine code, I suggest you write a simple assembler or disassembler.

This is to teach people, not learn-it-myself-how-can-i-do-it-help-plz-i-need-it-halp-pls-;(.


A 9 year old has no business writing tutorials about machine code, let alone anything. I remember writing a tutorial about something when I was 15 and looking back I can't believe I thought I had the knowledge to actually teach something to other people.
I have seen no evidence that you have learned enough to teach other people, or present knowledge in a coherent manner. I'm not saying this to be mean, but you should stop, take a breath, and focus on teaching yourself before posting half baked "tutorials"

_________________
Some of my open-source projects:
Ext2/ELF32 bootloader
Lightweight x86 assembler, designed to be portable for osdev
Scheme in under 1000 lines of C


Top
 Profile  
 
 Post subject: Re: Learning machine code.
PostPosted: Sat Oct 22, 2016 12:05 am 
Offline
Member
Member

Joined: Sun Oct 09, 2016 4:38 am
Posts: 273
jojo wrote:
Nuno, I'm trying to be a nice guy, here, but frankly the irritation over the fact that you don't seem to actually slow down and listen to anyone -- especially when they're trying to help you out and give you pointers instead of just resorting to insulting you -- is starting to get even to me, dude.

I'm sorry, just trying to be nice here.

_________________
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS


Top
 Profile  
 
 Post subject: Re: Learning machine code.
PostPosted: Sat Oct 22, 2016 12:05 am 
Offline
Member
Member

Joined: Sun Oct 09, 2016 4:38 am
Posts: 273
crunch wrote:
NunoLava1998 wrote:
crunch wrote:
Why are you posting this here?
There is almost no reason I can think of for directly coding in the opcodes, outside of very specific applications like code injection.

If you really want to learn about how assembly is translated into machine code, I suggest you write a simple assembler or disassembler.

This is to teach people, not learn-it-myself-how-can-i-do-it-help-plz-i-need-it-halp-pls-;(.


A 9 year old has no business writing tutorials about machine code, let alone anything. I remember writing a tutorial about something when I was 15 and looking back I can't believe I thought I had the knowledge to actually teach something to other people.
I have seen no evidence that you have learned enough to teach other people, or present knowledge in a coherent manner. I'm not saying this to be mean, but you should stop, take a breath, and focus on teaching yourself before posting half baked "tutorials"

okay

_________________
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS


Top
 Profile  
 
 Post subject: Re: Learning machine code.
PostPosted: Sat Oct 22, 2016 1:38 am 
Offline
Member
Member

Joined: Sun Jun 16, 2013 4:09 am
Posts: 333
NunoLava1998 wrote:
......................
Mate, you are posting stuff that is 20 years old.

Start writing some code, when you get stuck ask some questions, there is plenty of people that will help.

Ali


Top
 Profile  
 
 Post subject: Re: Learning machine code.
PostPosted: Sat Oct 22, 2016 2:08 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
You can also write your source code without the help of any sort of editor. Just enter the ASCII codes directly.


Top
 Profile  
 
 Post subject: Re: Learning machine code.
PostPosted: Sat Oct 22, 2016 5:37 am 
Offline
Member
Member
User avatar

Joined: Thu Mar 10, 2016 7:35 am
Posts: 167
Location: Lancaster, England, Disunited Kingdom
Hey folks read the posts properly.

He's effectively said 'sorry' and rather elegantly I thought with the the whispered ok. Give him a break!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group