PDA

View Full Version : True ASM vs. Fake ASM ????



DavidP
03-31-2003, 10:30 PM
I was pondering the meaning of life, along with several computer and algorithmic concepts, like I often do, as many of you know, and I came upon a question that has been lulling around in my mind for quite some amount of time now.

I thought of which board I should post this in, but as it is not related to C++, Game Programming, or any specific operating system, I felt it best to post it here.

As you might have guess by now, it is about the Assembly language. Now, many of us could easily recognize assembly if we saw it, for example:

mov ah, 01
mov dl, 02
int 21
int 20

That is a very simple assembly program right there. Also, many of us know that Assembly code can be translate directly into binary code (or machine code if you are anal about the name, as I know some people on this message board seem to be). For example, the latter program translated into binary would be the following:

(Actually I am going to display the hex code first):

B4 01 B2 02 CD 21 CD 20

(Then the binary):

1011 0100 0000 0001 1011 0010 0000 0010 1100 1101 0010 0001 1100 1101 0010 0000

(if my binary conversion was incorrect, please correct me).
(if you have any questions about converting assembly code into binary code, you can find the definitions of all assembly commands, and how to compose their binary equivalents in any documentation for a good Assembly program, such as Microsoft MASM.).

But anyways, back to my question....(sorry for all the information leading up to it).

I was reading my reference material for ASM, and saw these terms. I have also seen these in a lot of assembly code I have seen around the net, etc.:

IF, ELSEIF, ELSE, ENDIF, FOR, WHILE, REPEAT, SUBSTR, STRUCT, etc. (i dont think i have to go on, you have probably all seen them).

I don't understand how they all fit into the assembly language. Some of them, I understand. For example, a struct is just a declaration of a data type (BASICALLY), and so I can see how that might translate directly into machine code.

However, there are others which I do not see have the ability to translate directly into machine code, for example, the FOR loop which was stated in my ASM reference.

With my knowledge, a for loop requires initializations, conditions, and incrementation of variables, all of which, to the best of my knowledge, cannot be translated directly into machine code.

In fact, I was once taught how to do loops in assembly, using the various jmp commands, etc., and I can see how easily how those translate into direct machine code, but I cannot see how a for loop would.

In my view, a for loop would have to be translate into assembly code, and THEN into machine code, correct?

So if my assumption is correct, then why on earth is it included as part of an Assembler? In my views, if you are going to code in assembler, you should code in pure, hard, down and dirty Assembly language that is directly above the machine code, like Assembly language was always meant to be. Since when did for loops become part of that? For loops are not the only thing that I have seen. Look at the SUBSTR function which was included in my assembly reference.

Since when did SUBSTR become part of assembly? To the best of my knowledge, parsing a string and extracting a sub-string from it takes much more than just a few lines of code, and therefore can in now way be translated into a single line of machine code such as the definition for Assembly code states.

Then why has it been integrated into Assemblers? These two high-level commands are not the only ones that I have seen bobbing around in Assembly code, but they are the first that have come to my head as I have been writing this post.

But my point is, I am looking as several so called .asm files assembled using assemblers, which contain obvious high level coding!

Leave high level code to such languages as C++, C, Basic, Java, etc. That is what they are meant for. They are middle and high level languages.

Assembly is a low level language that is meant to be right above meachine code, so I am having trouble accepting the fact that such high level coding is being implemented into assemblers, when such coding does not translate directly into machine code.




Assembly - The automatic translation of symbolic code into machine code.

Source: The American Heritage® Dictionary of the English Language, Fourth Edition
Copyright © 2000 by Houghton Mifflin Company.

Assembly Language - A symbolic representation of
the machine language of a specific processor. Assembly
language is converted to machine code by an assembler...each line of assembly code produces one machine instruction.

The Free On-line Dictionary of Computing, © 1993-2001 Denis Howe

David no like use of high level stuff in asm :mad:

Magos
04-01-2003, 03:05 AM
Well, the obvious reason would be that instead of writing multiple lines of the same assemble code (cmp/bne/beq etc...) all over again you simply use if/for/while etc. However, I agree that if you didn't want to code in raw assembler, you'd use c or some other language.

VBprogrammer
04-01-2003, 03:23 AM
Yup you are right, Masm and HLA languages have high level commands which allow you to simplify the over-all design of a program whill keeping the core algorythms in ultra-fast ASM. This seems kind of perverse in the begining but you get used to it.

However LOOP is actually an ASM command! You set (e)cx to the number of illiterations of the loop and then use a loop label instruction where you want it to repeat.



mov ecx, 20
LoopPoint:
...
Loop LoopPoint


Its like doing this:



mov ecx, 20
LoopPoint:
...
dec ecx
or ecx, ecx
jnz LoopPoint

DavidP
04-01-2003, 12:12 PM
No, DavidP, these are decimal numbers. Depending on your assembler you have to write ``21h'' and ``20h'' or ``0x21'' and ``0x20''.


not when you use debug, it reads in as hexidecimal by default.

Unregd
04-01-2003, 04:26 PM
I can see why some people might think macro assembly is some wimped down C-asm hybrid that should be shot dead for its own good--these people tend to be the same people who want the least user friendly Linux distribution they can find--but they might not realize that the macro constructs are there to simplify repetitive code. Go ahead and write out your jmp commands every time you want to use a FOR loop; it's not like your assembler is going to care.

Everyone knows real x86 asm programmers use DOS DEBUG.COM instead of MASM or TASM anyway. If it can't fit within 64 kb you're just not trying hard enough.

npc
04-01-2003, 10:10 PM
In my view, a for loop would have to be translate into assembly code, and THEN into machine code, correct?


for risc processor like intel, yes.

for cisc processor like motorola, not necessarily.

Xei
04-02-2003, 01:00 AM
It's not fake ASM. All types of processors have their own different types of ASM. Just because some x86 ASM compilers allow you to use Macros it doesn't mean that your programming in a different language. Just like if you use an inline function in C++, does that mean that you are programming in something other than C++? No.

Yawgmoth
04-02-2003, 04:28 AM
I think macros CAN save time, but if you want to build your own compiler/assembler, you're going to need to know the REAL way to do a for loop, not the watered down fake asm way.