954,135 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

writing a a program in machine code

Hi have one querery regarding writing in machine code,

address- instruction
00000 001 10000
00001 010 10000
00010 100 10000
00011 110 10001
00100 111 00000
10000 000 00001
10001 000 11111

i dont know how to write a program in machine code, which adds up to the numbers stored in cell 11000 11001, 11010 and stores the sum in cell 11011.

any help would be much appreciated angela

ang19
Newbie Poster
1 post since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

i have one question. why would you want to write a program in machine code? I mean now with such advanced programming languages from c++ to even java is there any point to learning java.

mikeandike22
Nearly a Posting Virtuoso
1,496 posts since May 2004
Reputation Points: 33
Solved Threads: 19
 

Hi you can write the Machine Code. Instead of writing mnemonics you can write opcodes in asm files , like
db 0aeh ;equal to far jmp instructions. Hope this will help u...

sivaramanNainar
Newbie Poster
2 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

If you are that much of a masochist, you would have to get hold of the technical reference manual(s) for your processor, and look up how assembly language instructions are encoded into machine code.

Short of writing an operating system for a brand new model of computer, without any possibility of cross assembly, I can't imagine why anybody would want to do it.

mathematician
Junior Poster
155 posts since Nov 2006
Reputation Points: 14
Solved Threads: 4
 

Do universities teach that any more? I thought writing programs in machine code went out in the early 1960s, before punch cards were invented.

Ancient Dragon
Retired & Loving It
Team Colleague
30,040 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
 

my dad used punchcards still at uni during the late 70's lol

jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,820
Solved Threads: 600
 

There are valid reasons why someone would want to write a program in machine code, though I can't myself see why anyone would need to deal in binary. Anyhow, you can hand assemble code by swapping mneumonics with their opcodes, which are mainly giving in hex.

Colin Mac
Posting Whiz
327 posts since Sep 2006
Reputation Points: 78
Solved Threads: 22
 
There are valid reasons why someone would want to write a program in machine code

Only two I can think of
1) academic purposes

2) on obscure os that does not have an assembler

Ancient Dragon
Retired & Loving It
Team Colleague
30,040 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
 

Only two I can think of 1) academic purposes

2) on obscure os that does not have an assembler

Patches are frequently applied in machine code. NASA's procurement process for Space Shuttle flight software had the vendor providing a "signed off" image. Subsequent fixes after image sign off were applied as machine code patches. I had 20 words of patch space to work with in the Shuttle's SP0 cockpit display processor. Split 8 here and 12 over there. A reassemply/recertification of the load image to collect them up together was too economically painful to think about. We did hex patches.

Obviously debuggers and such need to do it when they implement the ability to alter code on the fly, and OS internals often do a bit of it when applying patches to known broken apps before allowing them to execute. DOS 5 and later for example, patch the in memory image of applications built with a buggy version of the Rational Systems DOS extender before giving them control.

Purple Avenger
Light Poster
49 posts since Jan 2007
Reputation Points: 31
Solved Threads: 0
 
Patches are frequently applied in machine code. NASA's procurement process for Space Shuttle flight software had the vendor providing a "signed off" image. Subsequent fixes after image sign off were applied as machine code patches. I had 20 words of patch space to work with in the Shuttle's SP0 cockpit display processor. Split 8 here and 12 over there. A reassemply/recertification of the load image to collect them up together was too economically painful to think about. We did hex patches.

You proved my second reason (obscure os) -- not many people have the opportunity to program for a space shuttle. :)

Ancient Dragon
Retired & Loving It
Team Colleague
30,040 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
 

We had assemblers though. The SP0 wasn't all that obscure (in aerospace circles that is). Shuttle uses it, and the Navy's Harpoon missile is using them somewhere.

The DOS loader stuff isn't very obscure. Millions of copies of DOS 5 and later shipped.

Sometimes you simply can't get a commercial tool to produce what you need either. There's some hand assembled stuff in the guts of OS/2 because we couldn't get a compiler or assembler to spit out what was needed.

Purple Avenger
Light Poster
49 posts since Jan 2007
Reputation Points: 31
Solved Threads: 0
 
Hi have one querery regarding writing in machine code, address- instruction 00000 001 10000 00001 010 10000 00010 100 10000 00011 110 10001 00100 111 00000 10000 000 00001 10001 000 11111 i dont know how to write a program in machine code, which adds up to the numbers stored in cell 11000 11001, 11010 and stores the sum in cell 11011. any help would be much appreciated angela




for coding anything in machine code we need to stick to the processor what that is going to interpret the machine code. But still i have a doubt how u r going to run this file where u have the binaries. What is the OS u r going to rely up on. Make sure these things first.

OR u can do 1 thing, boot any system with ur own machine code. then dump this machine code in memory somewhere. Then move the processor registers like Iinstruction Pointers, Segment Register accourdingly. So that processor will start executing ur code. that all i can say 4 now.

thx,
Garni

Garni
Newbie Poster
8 posts since Feb 2007
Reputation Points: 10
Solved Threads: 1
 

Hi have one querery regarding writing in machine code,

address- instruction 00000 001 10000 00001 010 10000 00010 100 10000 00011 110 10001 00100 111 00000 10000 000 00001 10001 000 11111

i dont know how to write a program in machine code, which adds up to the numbers stored in cell 11000 11001, 11010 and stores the sum in cell 11011.

any help would be much appreciated angela


This is not machine code this is BIANRY it is what assembly code is turned into, you need to be looking at how to learn ASSEMBLY LANGUAGE.

This can be written using a simple text editor like notepad and then with a suitable compiler like MASM or similar can be converted into an OBJECT file, this is then linked with a linker to produce an EXECUTABLE file if it is larger than 64K or a COM file if it is smaller than 64K

Cheers John

JW1234
Newbie Poster
3 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

This is what an 8086 assmebly language program looks like

.model small
.stack
.data
message db "Hello world, I'm learning Assembly !!!", "$"

.code

main proc <--- Start of program
mov ax,seg message <--- Message Seg to AX
mov ds,ax

mov ah,09 <--- I/O function
lea dx,message
int 21h <--- Execute & Return

mov ax,4c00h <--- Move 004Ch to register AX
int 21h <--- Execute Function & return
main endp
end main

John (no clues guessing what it does !!!!!!!!!!!!)

JW1234
Newbie Poster
3 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

Lets take a look at a simple MASM32 program. Avoided invoke and macros for clarity.

.386
.model flat, stdcall

MessageBoxA PROTO :DWORD,:DWORD,:DWORD,:DWORD
ExitProcess PROTO :DWORD

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.data
  msg_title db "Title", 0
  msg_str   db "Text.", 0

.code
start:

  push 0
  push offset msg_title
  push offset msg_str
  push 0
  call MessageBoxA

  push 0
  call ExitProcess

end start


A brief C version.

#include <windows.h>

int main()
{
    MessageBox(0, "Text.", "Title", MB_OK);
    return(0);
}


Now, something you might see in a disassembler(@'s are xx's)

5469746C6500
  546578742E00

  6A00
  6800xxxxxx
  6806xxxxxx
  6A00
  E8xxxxxxxx
  6A00
  E8xxxxxxxx

  FF25xxxxxxxx
  FF25xxxxxxxx

That right there would be 427 ones and zeros, not including another KB of padding, headers, and tables. So unless you're one hardcore programmer, coding in machine code is beyond the scope of convention.

P.S. No one uses binary while dealing with op-codes.

MosaicFuneral
Posting Virtuoso
1,691 posts since Nov 2008
Reputation Points: 888
Solved Threads: 116
 

JW1234:

Binary code and machine code are the same thing.

BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
 

notice how this problem didn't get solved,
knowledge of this kind has disappeared and if you want it you must look for it everywhere. but people spitting in your face and slandering your language of choice is a bit annoying.

hamiltonham
Newbie Poster
1 post since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

First,
Determine exactly what this code does or is intended to do.

Re-write that application in a language that you do know-
Berkeley BASIC comes to mind
-since you say you don't want to use K&H.

Second,
Assemble your new code. -
THEN
With a good Hex editor such as MASM or TASM or the like,
Compare your new asmbly code with this older asmbly code

Do While:
Continue to revise your high(er) level language subrt'n
UNTIL: your new ASM code matches the old ASM code.

At this point you'll have
(1) An app which creates this piece of code,
(2) An app that you can read ! and modify ! for future changes.
(3) Some good tools in-which to work with,
and
(4) Some good knowledge of ...well,
of a lot of things ...

like - what to stay away from the next time.


Shift-Stop

Hi have one querery regarding writing in machine code,

address- instruction 00000 001 10000 00001 010 10000 00010 100 10000 00011 110 10001 00100 111 00000 10000 000 00001 10001 000 11111

i dont know how to write a program in machine code, which adds up to the numbers stored in cell 11000 11001, 11010 and stores the sum in cell 11011.

any help would be much appreciated angela

Shift-Stop
Newbie Poster
11 posts since Oct 2010
Reputation Points: 10
Solved Threads: 1
 

is there a way to decompile windows xp without any programming experience or experteese

welshhotty2010
Newbie Poster
1 post since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

"is there a way to decompile windows xp without any programming experience or experteese"

You might be able to disassemble it with a program like IDA Pro, but there is virtually no way of recovering the C source code.

mathematician
Junior Poster
155 posts since Nov 2006
Reputation Points: 14
Solved Threads: 4
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You