Page 1 of 2

Programming in raw hex - possible?

Posted: Wed Jan 16, 2008 4:20 pm
by Tootles
Here's something I've been getting the hump about; every time I've tried to assemble a piece of assembly code (when I was trying to learn how to program in assembly), it just wouldn't work, so I've been thinking - would it be possible (even if not practical), in your opinion, to write some simple programs in raw machine code? So, say I was writing a bootloader for an operating system, would a person perhaps be able to code it in a hex editor (this is assuming they have already written it in assembly language, and are just translating it), save it as a binary file, and then write it to the boot sector of the disk?

Posted: Wed Jan 16, 2008 5:00 pm
by Combuster
If assembled code does not work, how would it start working when the less-than-perfect you are doing the work normally done by a practically perfect assembler :roll:

Posted: Wed Jan 16, 2008 5:15 pm
by Solar
Possible, yes. In fact, that was the way it was done in the early days - paper flowchart, hexcode, punchcard.

Encouraged? Most certainly not. 8)

Posted: Wed Jan 16, 2008 8:37 pm
by Jef
i am sure that is the hard way, if you can do this.

When you debugging again and again, you begin to understand by reading the opcodes (in hex view binary) like h@ckers do (if you have good memory).
BUT this does not means that you can also write in hex.

If you cannot write in assembler, how you will do the same thing from more difficult way ???

Posted: Wed Jan 16, 2008 10:55 pm
by neon
Wasnt there a member here that started doing that? (Using machine code instead assembly--theres a thread about it)

I wonder how thats going now...

hardcoding!!!11111

Posted: Thu Jan 17, 2008 8:40 am
by Osbios
Yes, of course you can! Its called hardcoding.
The bigest Problem are the jump addresses. So most people use the nop command to fill space aftet "blocks" of commends. The adventage of this: you can make small changes on a block, and dont have to change jump addresses to this block or other blocks after the edited one.

You also have to callculate some values from binary to hex. But thats not very hard.

Posted: Thu Jan 17, 2008 9:02 pm
by crazygray1
neon wrote:Wasnt there a member here that started doing that? (Using machine code instead assembly--theres a thread about it)

I wonder how thats going now...
That was me, and yes it's going fine though I'm not writing the Bootloader right now that's what I'll be doing...

Posted: Fri Jan 18, 2008 9:28 am
by binutils
yes you can do it, especially, with some kind of machineS.
http://www.homebrewcpu.com/photo_gallery.htm etc etc

Posted: Fri Jan 18, 2008 10:26 am
by Tyler
binutils wrote:yes you can do it, especially, with some kind of machineS.
http://www.homebrewcpu.com/photo_gallery.htm etc etc
Actaully he wrote software in C. The minicomputer switches editing of memory is a nostalgic/debugging thing.

Posted: Fri Jan 18, 2008 11:25 pm
by earlz
here ya go

Code: Select all

0x90 ;nop
0xF4 ;hlt
those are the only codes I know how to use, but I know from typing in numbers and debugging my x86Lib project, that 0x00 is add modrm, 0x10 is adc modrm, and 0xF0 is lock

other than that, I have nothing memorized...

I could imagine writing simple programs in hex, but the addressing would be the hellish part, I would have to make a program that lets me use some sort of symbol table and compiles my hex code to resolve to the right addresses...lol...kinda pointless then though...

Posted: Sat Jan 19, 2008 8:14 am
by binutils
Tyler wrote:
binutils wrote:yes you can do it, especially, with some kind of machineS.
http://www.homebrewcpu.com/photo_gallery.htm etc etc
Actaully he wrote software in C. The minicomputer switches editing of memory is a nostalgic/debugging thing.
Perhaps, lately.
William Bruce Buzbee wrote: ...
7/7/2002
Lots of progress on the microcode rewrite. It looks like I'm going to end up with about half the microcode as the previous version. This is due to my more aggressive use of field decoding in the compacted microcode structure.
...
http://www.homebrewcpu.com/mcode_index.htm etc etc
--
PS: http://en.wikipedia.org/wiki/Microcode

Posted: Sun Jan 20, 2008 6:00 am
by JamesM
The only hex code I know off by heart is 0xEBFE , jmp $.

Re: Programming in raw hex - possible?

Posted: Sun Jan 20, 2008 7:04 am
by XCHG
toots wrote:Here's something I've been getting the hump about; every time I've tried to assemble a piece of assembly code (when I was trying to learn how to program in assembly), it just wouldn't work, so I've been thinking - would it be possible (even if not practical), in your opinion, to write some simple programs in raw machine code? So, say I was writing a bootloader for an operating system, would a person perhaps be able to code it in a hex editor (this is assuming they have already written it in assembly language, and are just translating it), save it as a binary file, and then write it to the boot sector of the disk?
If your Assembly codes don't work, how are you expecting to be able to write something even more low-level than that. It is like saying "I can't hold a 1 kilogram dumbbell but now I think I should start lifting 20 tons bulldozers off of the ground".

Writing code in anything low-level than Assembly is an utter waste of time. I sometimes think of writing Assembly codes as a waste of time also. If you have lots of time, then go for it but at the end of the day, you will be somebody who has learned to program in hex. Does anybody really care? Sometimes the level of difficulty of something is not directly associated with the level of appreciation you will achieve from it. But then again, it is all preference. Learning how to write BrainFuck programs is a waste of time but it helps you develop your mind even further so that's why many people still code in BrainFuck for the heck of it.

Back to your main topic, if you don't know how to write code in Assembly, learning how to write code in binary won't help you at all. If you didn't know how to use Front Page or DreamWeaver and you got stuck in creating a table for example, then you could use your HTML skills to manually edit the HTML file. But suppose your code doesn't work in assembly because instead of LEA EAX , [EDX + (ECX*0x04) + 22] you have LEA EAX , [EDX + (EDX*0x04) + 22]. How do you think your coding in binary abilities would help you fix this? :roll:

Posted: Sun Jan 20, 2008 7:28 am
by lukem95
i think it would be an utter waste of time, i know a few opcodes, but only from exploiting buffer overflows and from debugging.

they have a use, but programming them manually is not it.

Posted: Sun Jan 20, 2008 2:56 pm
by neon
CD21 - interrupt 0x21 (Go DOS!) :)

Its actually a 2byte opcode, CDnn. where nn is the interrupt number.

Of course, you can always check up on the processor manuals for the complete list...