Page 1 of 1

Learning machine code.

Posted: Fri Oct 21, 2016 1:30 pm
by NunoLava1998
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: Select all

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: Select all

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: Select all

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

Re: Learning machine code.

Posted: Fri Oct 21, 2016 1:36 pm
by jojo
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:
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.

Re: Learning machine code.

Posted: Fri Oct 21, 2016 1:53 pm
by NunoLava1998
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:
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.

Re: Learning machine code.

Posted: Fri Oct 21, 2016 2:43 pm
by crunch
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.

Re: Learning machine code.

Posted: Fri Oct 21, 2016 2:46 pm
by NunoLava1998
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-;(.

Re: Learning machine code.

Posted: Fri Oct 21, 2016 2:48 pm
by jojo
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.

Re: Learning machine code.

Posted: Fri Oct 21, 2016 2:53 pm
by heat
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

Re: Learning machine code.

Posted: Fri Oct 21, 2016 2:54 pm
by crunch
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"

Re: Learning machine code.

Posted: Sat Oct 22, 2016 12:05 am
by NunoLava1998
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.

Re: Learning machine code.

Posted: Sat Oct 22, 2016 12:05 am
by NunoLava1998
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

Re: Learning machine code.

Posted: Sat Oct 22, 2016 1:38 am
by tsdnz
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

Re: Learning machine code.

Posted: Sat Oct 22, 2016 2:08 am
by iansjack
You can also write your source code without the help of any sort of editor. Just enter the ASCII codes directly.

Re: Learning machine code.

Posted: Sat Oct 22, 2016 5:37 am
by MichaelFarthing
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!