• Advertisement
Sign in to follow this  

How was the first assembler made?

This topic is 4839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do you program a compiler for the lowest level programming language? Are assemblers programmed in binary? And at what point can as assembler be called an assembler instead of another programming language? With all the high level macros, can MASM and TASM really be called assemblers?

Share this post


Link to post
Share on other sites
Advertisement
If you really want, you can program computers in machine language. In fact, people did that for longer than you'd guess. These were the days of punchcards, where you'd write an entire program before the computer would ever see a single character of it.

As you've correctly identified, the line between "assembler" and "compiler" is at times a vague one. I still think it's a legitimate distinction, however, and I think the key is that the code you write in MASM/TASM has a distinct mapping onto machine language. This differs from C, Java, etc. in that the assembler is not free to optimize, choose registers, etc. It has macros, but you always know what macros those opcodes evaluate to.

Share this post


Link to post
Share on other sites
Alright, so an assembler's macros translate into low-level asm, and then into hexcodes, and then machine code; whereas high level languages like C++ do a whole lot of crap in between?

Share this post


Link to post
Share on other sites
Used to be the case that high-lev language compilers would compile down to assembler, then build a binary out of that assembler code. Modern compilers (VC++ for instance) compiles directly to binary.

Sounds like you've got a good handle on it =)

Share this post


Link to post
Share on other sites
Bingo. Of course, in assembler you end up doing that "whole lot of crap in between" yourself. The advantage of HLLs (high-level languages) over assembler is that they free you from the minutiae of controlling the CPU while allowing you to have complete control over the important part, namely what your program actually _does_. The disadvantage is that sometimes you want that full control.

Share this post


Link to post
Share on other sites
Thanks for explaining it both of you! This has puzzled me for a while, because I actually found some high-level assemblers easier than C++ for some things. I'm just learning about calling interupts (Namely 24h), and now what sneftel said about doing all the crap your self makes sense :)

Share this post


Link to post
Share on other sites
Quote:
Original post by kingpinzs
how would you write a programe in binary today?


my guess would be use a hex editor...

you could also easily write a program in a high level language that just lets you write a binary file

Share this post


Link to post
Share on other sites
I mean binary is 1 and 0 right.

can I actuly right in 1 and 0 or is just hex that repersents the 1 and 0?

Share this post


Link to post
Share on other sites
Just make a blank non .txt file and start using coding in binary. After your done, just rename the file to .exe and your good to go. Of course you must know the structure of an executable, you must know what all of the binary opcodes translate to in hex, and you gotta know a lot of assembly. Doing this for a 32 bit OS that requires all of that stupid PE BS would take months and months of coding everyday.

I suggest you pick up an older version of dos and than start hacking away. Your not going to have to worry about loading dlls, making system calls, PE structure, and the rest of the works. You could getting an executing program in under 3 minutes. Especially if you made or use a tool to convert hex into binary. The program would have one assembly command. This would be -> int 21h. Your file would be two bytes.
GL!

Share this post


Link to post
Share on other sites
The lowest I've ever programmed in is hexadecimal codes, and using the GetRealDebugger to compile them into a .com file. I don't know about machine code.

EDIT: Xorjesus beat me, and with a great explaination.

PS: Xorjesus, if you make it a .com file, do you need to know the pe format or could you just use low level asm statements?

Share this post


Link to post
Share on other sites
Quote:
Original post by Drakkcon
How do you program a compiler for the lowest level programming language? Are assemblers programmed in binary? And at what point can as assembler be called an assembler instead of another programming language? With all the high level macros, can MASM and TASM really be called assemblers?


The first assembler was coded in machine code, but after that there was boot strap effect in that the next assembler could be coded in assembly and assembled by the first an so on.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
If you really want, you can program computers in machine language. In fact, people did that for longer than you'd guess. These were the days of punchcards, where you'd write an entire program before the computer would ever see a single character of it.


If you really want, you can take a comp. org. class, design your own computer (or at least some sort of Turing machine*), and build it out of CMOS or TTL chips, load your program using some manual toggle switches (you'll need some protocol so that it knows when you're done entering a given value, and probably some "debouncing" circuits too), and watch your output on some LEDs. "And I would have gotten away with it too, if it weren't for that blasted undergrad thesis." [grin]

Quote:
It has macros, but you always know what macros those opcodes evaluate to.


I think you got your order of source and destination arguments wrong [wink]

* Of course, not Turing-complete in the formal sense; you will have (probably very small) bounds on "tape length", number of possible machine states, etc.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
If you really want, you can program computers in machine language. In fact, people did that for longer than you'd guess. These were the days of punchcards, where you'd write an entire program before the computer would ever see a single character of it.

As you've correctly identified, the line between "assembler" and "compiler" is at times a vague one. I still think it's a legitimate distinction, however, and I think the key is that the code you write in MASM/TASM has a distinct mapping onto machine language. This differs from C, Java, etc. in that the assembler is not free to optimize, choose registers, etc. It has macros, but you always know what macros those opcodes evaluate to.


A friend of mine can program in hexa. He is crazy.

EDIT: seems he isn't the only one :)

Share this post


Link to post
Share on other sites
Quote:
Original post by xorjesus
Just make a blank non .txt file and start using coding in binary. After your done, just rename the file to .exe and your good to go.

1 in a .txt isn't saved as 1 in binary.

Share this post


Link to post
Share on other sites
This is because we do not have direct access to bits on the CPU just bytes. That is why we use Hex to represent at a minimum, 8 bits. ie. FF = 255 = 11111111.

If you are looking for a self compiling assembler I would suggest FASM, it also does multiple passes for optimization and is being updated on a regular basis. It can even compile itself, output MS COFF files, PE files, and DLL's.

Flat Assembler
http://flatassembler.net/index.php

BTW i'm no expert on this subject at all so if I'm wrong let me know, thanks.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
AFAIK you cannot program in binary. Binary isn't a "language." The 1's and 0's represent the yes and no decisions made by the processor itself. When you hear about binary, you're hearing what decisions the processor is making. Correct me if I'm wrong, but it is impossible to write "111010010101010101001010100101010101001...." and have it do something.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
AFAIK you cannot program in binary. Binary isn't a "language." The 1's and 0's represent the yes and no decisions made by the processor itself. When you hear about binary, you're hearing what decisions the processor is making. Correct me if I'm wrong, but it is impossible to write "111010010101010101001010100101010101001...." and have it do something.

But if you can program in hex, then you can program in binary.

If you can open up a program in a hex editor and see what it is made up of, then I can see no reason why you couldn't, with the proper knowledge obviously, write your programs in hex/bin. Aren't crackers, in some sense, programming when they open a program in a hex editor and change some instructions?

Share this post


Link to post
Share on other sites
You can't directly access bits on a CPU, you can use bytes to represent a series of bits and thats it. The CPU itself can access the bits of a byte. Like I said before Hex values represent 8 bits of information and this is how bits are manipulated. But I think an ASM freak could probably clear this up and give a good underlying description of whats happening. From ASM to bytecode to CPU etc.. Like I said I'm no expert.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
AFAIK you cannot program in binary. Binary isn't a "language." The 1's and 0's represent the yes and no decisions made by the processor itself. When you hear about binary, you're hearing what decisions the processor is making. Correct me if I'm wrong, but it is impossible to write "111010010101010101001010100101010101001...." and have it do something.


As many others have said, there no difference between coding in hex and binary. I have seen some hex editors which allow you to see the binary representation too. In that case, you could actually type 1s and 0s to create a working program.

Dwiel

Share this post


Link to post
Share on other sites
I've programmed in hex with GetRealDebugger, but all my program did was output a single character to the screen by storing a character in a register I can't remember, and calling interrupt 24h. That was a waste of time, so I'll stick with asm =)

Share this post


Link to post
Share on other sites
Quote:
Original post by Codemonger
Like I said before Hex values represent 8 bits of information...
Actually, one hex digit represents 4 bits of information, which has a range of 16 values or states. That's what hexadecimal means, after all: base 16.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Tazzel3D
Quote:
Original post by Anonymous Poster
AFAIK you cannot program in binary. Binary isn't a "language." The 1's and 0's represent the yes and no decisions made by the processor itself. When you hear about binary, you're hearing what decisions the processor is making. Correct me if I'm wrong, but it is impossible to write "111010010101010101001010100101010101001...." and have it do something.


As many others have said, there no difference between coding in hex and binary. I have seen some hex editors which allow you to see the binary representation too. In that case, you could actually type 1s and 0s to create a working program.

Dwiel


Well actually yes, there is a large difference between hex opcodes and binary.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement