OSDev.org
https://forum.osdev.org/

Learning machine code.
https://forum.osdev.org/viewtopic.php?f=11&t=30940
Page 1 of 1

Author:  NunoLava1998 [ Fri Oct 21, 2016 1:30 pm ]
Post subject:  Learning machine code.

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

Author:  jojo [ Fri Oct 21, 2016 1:36 pm ]
Post subject:  Re: Learning machine code.

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.

Author:  NunoLava1998 [ Fri Oct 21, 2016 1:53 pm ]
Post subject:  Re: Learning machine code.

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.

Author:  crunch [ Fri Oct 21, 2016 2:43 pm ]
Post subject:  Re: Learning machine code.

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.

Author:  NunoLava1998 [ Fri Oct 21, 2016 2:46 pm ]
Post subject:  Re: Learning machine code.

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-;(.

Author:  jojo [ Fri Oct 21, 2016 2:48 pm ]
Post subject:  Re: Learning machine code.

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.

Author:  heat [ Fri Oct 21, 2016 2:53 pm ]
Post subject:  Re: Learning machine code.

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

Author:  crunch [ Fri Oct 21, 2016 2:54 pm ]
Post subject:  Re: Learning machine code.

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"

Author:  NunoLava1998 [ Sat Oct 22, 2016 12:05 am ]
Post subject:  Re: Learning machine code.

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.

Author:  NunoLava1998 [ Sat Oct 22, 2016 12:05 am ]
Post subject:  Re: Learning machine code.

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

Author:  tsdnz [ Sat Oct 22, 2016 1:38 am ]
Post subject:  Re: Learning machine code.

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

Author:  iansjack [ Sat Oct 22, 2016 2:08 am ]
Post subject:  Re: Learning machine code.

You can also write your source code without the help of any sort of editor. Just enter the ASCII codes directly.

Author:  MichaelFarthing [ Sat Oct 22, 2016 5:37 am ]
Post subject:  Re: Learning machine code.

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!

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/