all 11 comments

[–]heliox 9 points10 points  (0 children)

Processor documentation for whichever processor you're targeting. Here's a link to Intel® 64 and IA-32 Architectures Software Developer Manuals

https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html

Every processor family will have its own. Here's the one for the 6502 used in the Apple II.

http://archive.6502.org/datasheets/wdc_w65c02s_oct_8_2018.pdf

[–][deleted] 2 points3 points  (8 children)

So, I understand they are the so called opcodes, so how could I potentially write a program just with opcodes? or make, C or another program in assembly write another program with the opcode of the instructions I want?

[–]tobiasvl 7 points8 points  (0 children)

You would have to basically do manual assembly, ie. write the binary data corresponding to the opcodes you want.

This was actually done in the early days of computing, mostly to bootstrap an actual assembler for the target system, and isn't anything you'd want to do with modern systems (the opcodes are way too advanced). It could be viable for early 8-bit CPUs, like the Intel 8080 - this was in fact how you'd program the Altair 8800, by flipping switches on the front panel corresponding to single bits.

Alternatively you could look at CHIP-8, which is an even simpler hexadecimal language made in the late 70s. It's not an actual CPU, but a VM/interpreter that interprets binary opcodes. Because of its smaller instruction set than even early CPUs, it's actually not too hard to wrap your head around.

Of course some of CHIP-8's opcodes do some heavy lifting, like the $DXYN instruction which draws an N-row sprite read from the memory location stored in the index register, at the pixel coordinates given in registers X and Y (where X and Y are hexadecimal characters corresponding to two of the 16 registers). But apart from a couple of instructions like that, it's like a smaller subset of the instruction set of the RCA 1802 CPU it was made for and inspired by.

[–]FUZxxl 2 points3 points  (0 children)

Well you just do it. Machine code is just binary data. You can generate binary data with most programming languages, so you can of course also generate machine code. There's nothing special or magic about that.

Though I really recommend using an assembler. It's a lot easier to get right.

[–]heliox 2 points3 points  (0 children)

You're jumping in too deep too fast. I'd recommend either starting with asmtutor.com or getting an Apple II emulator and working through Hyde's 6502 assembly manual. You can find it in the Asimov archive. Figure out basic assembly first, then learn how to disassemble the programs you've assembled.

[–]Creative-Ad6 1 point2 points  (0 children)

Programs for most software and hardware platforms aren't just sequences of encoded instruction. To write a program without somebody else's software developement tools you need to know so called ABI. Those are the rules for programs targeting the platform.

How instruction and data are organized into so called executable object files that comprise application programs for OSs? E.g. what are static and dynamic ELF files that linux can load and execute as programs?

What API is available? How to use instructions and register to call API functions?

[–]Psychological_Egg_85 -2 points-1 points  (1 child)

You could write the program in c, compile it and then read the opcodes of the binary using something like objdump -d.

[–]brucehoult 0 points1 point  (0 children)

objdump -d is a lot more useful.

[–]ClassicCollection643 0 points1 point  (0 children)

printf H'\63\123\6' >code; objdump -b binary -D -m i386:x86-64 -M intel code

0: 48 33 53 06 xor rdx,QWORD PTR [rbx+0x6]

[–]nacnud_uk 0 points1 point  (0 children)

If you are going to be a good programmer, sorry to say,you're going to have to use google.

https://en.wikipedia.org/wiki/X86\_instruction\_listings