Thread: True ASM vs. Fake ASM ????

  1. #1
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743

    Question True ASM vs. Fake ASM ????

    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
    My Website

    "Circular logic is good because it is."

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    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.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User VBprogrammer's Avatar
    Join Date
    Mar 2002
    Posts
    175
    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.

    Code:
    mov ecx, 20
    LoopPoint:
    ...
    Loop LoopPoint
    Its like doing this:

    Code:
    mov ecx, 20
    LoopPoint:
    ...
    dec ecx
    or ecx, ecx
    jnz LoopPoint
    VC++ 6

  4. #4
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    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.

  5. #5
    Unregd
    Guest
    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.

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    8
    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.

  7. #7
    Registered User Xei's Avatar
    Join Date
    May 2002
    Posts
    719
    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.

  8. #8
    ! |-| /-\ +3 1337 Yawgmoth's Avatar
    Join Date
    Dec 2002
    Posts
    187
    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.
    L33t sp3@k sux0rz (uZ it t@k3s 10 m1|\|ut3s 2 tr@nzl@te 1 \/\/0rd & th3n j00 h@\/3 2 g3t p@$t d@ m1zpelli|\|gz, @tr0(i0u$ gr@mm@r @|\|d 1n(0/\/\pr3#3|\|$1bl3 $l@|\|g. 1t p\/\/33nz j00!!

    Speling is my faverit sujekt

    I am a signature virus. Add me to your signature so that I may multiply.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ASM to C language
    By TAZIN in forum C Programming
    Replies: 22
    Last Post: 06-03-2009, 06:29 AM
  2. gcc asm code syntax
    By Uberapa in forum C Programming
    Replies: 4
    Last Post: 06-15-2007, 01:16 AM
  3. Looking for feedback on program segment
    By avron in forum C++ Programming
    Replies: 4
    Last Post: 05-07-2007, 04:38 PM
  4. MCI CD Player
    By soutine in forum Windows Programming
    Replies: 0
    Last Post: 11-02-2001, 05:03 PM
  5. True or False Quiz (Need help)
    By Twiggy in forum C Programming
    Replies: 9
    Last Post: 10-12-2001, 04:25 AM