Learning machine code.

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
Post Reply
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Learning machine code.

Post 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
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
User avatar
jojo
Member
Member
Posts: 138
Joined: Mon Apr 18, 2016 9:50 am
Libera.chat IRC: jojo
Location: New York New York

Re: Learning machine code.

Post 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.
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Re: Learning machine code.

Post 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.
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
User avatar
crunch
Member
Member
Posts: 81
Joined: Wed Aug 31, 2016 9:53 pm
Libera.chat IRC: crunch
Location: San Diego, CA

Re: Learning machine code.

Post 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.
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Re: Learning machine code.

Post 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-;(.
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
User avatar
jojo
Member
Member
Posts: 138
Joined: Mon Apr 18, 2016 9:50 am
Libera.chat IRC: jojo
Location: New York New York

Re: Learning machine code.

Post 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.
heat
Member
Member
Posts: 103
Joined: Sat Mar 28, 2015 11:23 am
Libera.chat IRC: heat

Re: Learning machine code.

Post 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
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
User avatar
crunch
Member
Member
Posts: 81
Joined: Wed Aug 31, 2016 9:53 pm
Libera.chat IRC: crunch
Location: San Diego, CA

Re: Learning machine code.

Post 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"
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Re: Learning machine code.

Post 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.
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Re: Learning machine code.

Post 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
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
tsdnz
Member
Member
Posts: 333
Joined: Sun Jun 16, 2013 4:09 am

Re: Learning machine code.

Post 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
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Learning machine code.

Post by iansjack »

You can also write your source code without the help of any sort of editor. Just enter the ASCII codes directly.
User avatar
MichaelFarthing
Member
Member
Posts: 167
Joined: Thu Mar 10, 2016 7:35 am
Location: Lancaster, England, Disunited Kingdom

Re: Learning machine code.

Post 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!
Post Reply