Programming in raw hex - possible?

Programming, for all ages and all languages.
User avatar
Tootles
Posts: 15
Joined: Tue Jan 15, 2008 5:23 am

Programming in raw hex - possible?

Post 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?
Have a day.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post 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:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post 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)
Every good solution is obvious once you've found it.
User avatar
Jef
Member
Member
Posts: 112
Joined: Tue Jan 08, 2008 7:25 am
Location: Greece
Contact:

Post 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 ???
Keep coding...
...the sky is the limit

AsteriOS project: http://www.mindfields.gr/main/index.php ... &Itemid=27
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post 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...
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Osbios
Member
Member
Posts: 116
Joined: Fri Jun 10, 2005 11:00 pm

hardcoding!!!11111

Post 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.
User avatar
crazygray1
Member
Member
Posts: 168
Joined: Thu Nov 22, 2007 7:18 pm
Location: USA,Hawaii,Honolulu(Seriously)

Post 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...
Codname: Cipher
Working On: Design Doc(CFFS file system)
User avatar
binutils
Member
Member
Posts: 214
Joined: Thu Apr 05, 2007 6:07 am

Post by binutils »

yes you can do it, especially, with some kind of machineS.
http://www.homebrewcpu.com/photo_gallery.htm etc etc
Tyler
Member
Member
Posts: 514
Joined: Tue Nov 07, 2006 7:37 am
Location: York, England

Post 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.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Post 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...
User avatar
binutils
Member
Member
Posts: 214
Joined: Thu Apr 05, 2007 6:07 am

Post 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
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

The only hex code I know off by heart is 0xEBFE , jmp $.
User avatar
XCHG
Member
Member
Posts: 416
Joined: Sat Nov 25, 2006 3:55 am
Location: Wisconsin
Contact:

Re: Programming in raw hex - possible?

Post 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:
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.
User avatar
lukem95
Member
Member
Posts: 536
Joined: Fri Aug 03, 2007 6:03 am
Location: Cambridge, UK

Post 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.
~ Lukem95 [ Cake ]
Release: 0.08b
Image
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post 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...
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Post Reply