News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

I love Assembly but.......

Started by Robert Collins, December 23, 2004, 12:58:28 AM

Previous topic - Next topic

Robert Collins

I love Assembly. I actually started out in Assembly Language programs (long before I even knew about C++, VB, Delphi, Java, and other higher level languages) several years back on the IBM mainframe computers. Back then when you wrote an Assembly language program you really [/i] wrote programs at the assembly (machine-code is what we called it) level. If you were to examine an Assembly language source listing you saw about 95% pure machine-code instructions and about 5% of the other stuff (directives, a few macros, etc).

We didnt have 'debuggers' in the strict sense so when our programs crashed we has no choise but to look at hundreds of pages of core-dumps that the computer spilled out and try to resolve the problem(s) from there.

Today, I am no longer doing IBM mainframe Assembly programs because they are gone.

When I saw my first Assembly language source program for Win32 Assembly I was quite astounded. "Where in the hell are the machine-code instructions?" I asked myself. It seems to me as we get further and further into state-of-the-art technologies the programs are getting less and less looking like assembly language programs. Except for a couple of front-end stuff at the top of the source listing everything else in the assembly source had absolutely no resemblense to an assembly language program. As a matter of fact, I thought I was looking at some new breed of C/C++ or Visual Basic program. I almost decided not to get into Win32 Assembly because it appeared to me that this is just more Windows programming in the C/C++ style.

Oh, well, I going to do it anyway.     


donkey

If you like a lower level assembler you might try GoAsm, it has a few high level functions regarding strings and a very rudimentary macro language but none of the IF/ELSEIF/ENDIF or REPEAT/UNTIL stuff, you actually have to code them with instructions. Take a look, it is close enough to MASM that you are not losing any of what you've learned but it is not for the faint of heart, it is real assemlby, none of the toys you find in most others.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Robert Collins

Quote from: donkey on December 23, 2004, 01:03:33 AM
If you like a lower level assembler you might try GoAsm, it has a few high level functions regarding strings and a very rudimentary macro language but none of the IF/ELSEIF/ENDIF or REPEAT/UNTIL stuff, you actually have to code them with instructions. Take a look, it is close enough to MASM that you are not losing any of what you've learned but it is not for the faint of heart, it is real assemlby, none of the toys you find in most others.

On my own I would probably go in that direction just because of my 'love' for the real low-level coding but as it is I don't have the time to venture into that type of maticulus coding and the assembly that I am getting into is at the company's request and they decide what level I code at. Actually, I really do like the new high-level assembly coding. I was just making a comparison to now and then. I didn't like C and C++ when I first got into it but it grew on me and now I do like programming in it. I think when I made the transition from low-level to high-level it was just kind of dissapointing at first because I seem to have lost my inner friendship with the CPU and all those other neat things you get into down below.

hutch--

Robert,

There is a predictable sequence for code style over time. People learning use the higher level stuff because its easier to start with. Over time they learn how to do it all the hard way and once they have learnt that they go back to using the higher level stuff because you code faster in it.

Where it is important to know the difference is when you have to code algorithms that must be fast. bare mnemonics have advantages here when they are coded right.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dev_zero

Even if you choose to use MASM, you aren't forced to use all the macros. You can make all the things you need yourself, if that's what you want.

Mark_Larson


  Yea, I certainly don't use any of C like support in MASM. 
BIOS programmers do it fastest, hehe.  ;)

My Optimization webpage
htttp://www.website.masmforum.com/mark/index.htm

Maven

Quote from: Mark_Larson on December 23, 2004, 03:09:38 AM

  Yea, I certainly don't use any of C like support in MASM. 

Using high level syntax in ASM completely defeats the purpose of doing things in asm.

Robert Collins

I was just wondering about something. If you write a program in assembly and it is a Windows type program you wind up making the same API calls and then sprinkle here and there some assembly instructions. Then you build and link your .asm using MASM. Why would you not consider using MS VC, create a C project, make the same API calls to get your windows functions and then drop down to the asm level (which is supported in the VC IDE) and sprinkle your assembly code here and there instead of C code. Wouldn't that, in essense, be basically the same thing?

MANT

In essense, yes, it would be the same thing. Only for many of us it's more fun to do it in assembler. Some of us are interested in doing everything low-level; others are more interested in writing C and optimizing the bottlenecks as much as possible.

BTW, in your original post, which assembler's code were you looking at? When I first read it, I kind of figured you might be looking at HLA code, which is significantly different than all the other assemblers I can think of. Even when MASM code gets very high-level, you usually cannot mistake it for anything but assembler. HLA, on the other hand, can easily be mistaken for a high-level language like C or Pascal.

Maven

Quote from: Robert Collins on December 23, 2004, 03:56:42 AM
I was just wondering about something. If you write a program in assembly and it is a Windows type program you wind up making the same API calls and then sprinkle here and there some assembly instructions. Then you build and link your .asm using MASM. Why would you not consider using MS VC, create a C project, make the same API calls to get your windows functions and then drop down to the asm level (which is supported in the VC IDE) and sprinkle your assembly code here and there instead of C code. Wouldn't that, in essense, be basically the same thing?

I think the best bet is to do all your coding in a high level language and then do critical code in ASM.

Robert Collins

Quote from: Maven on December 23, 2004, 04:23:12 AM
Quote from: Robert Collins on December 23, 2004, 03:56:42 AM
I was just wondering about something. If you write a program in assembly and it is a Windows type program you wind up making the same API calls and then sprinkle here and there some assembly instructions. Then you build and link your .asm using MASM. Why would you not consider using MS VC, create a C project, make the same API calls to get your windows functions and then drop down to the asm level (which is supported in the VC IDE) and sprinkle your assembly code here and there instead of C code. Wouldn't that, in essense, be basically the same thing?

I think the best bet is to do all your coding in a high level language and then do critical code in ASM.

I think it all depends on the individual. I used to do assembly for the 'fun' of it (and I still do up to a point). Then I did assembly right down to the barest of bones programming, not because it was efficent but because that is what I liked doing. I even got so interested in computers and what makes them tick I even did some mirco coding (firmware) and man, you just don't get any lower than at the micro level. But now, I program for a living and I am bound by the policies of the company as to what I can and can't do. Because I have to do what my boss says I am not always happy with what I have to write a program for. I am not always happy about which language or level of programming I have to use. Even given the choise of language I probably would not pick assembly to do my job because the high-level languages are so much more efficent and faster to develop in. I like to get the project done and get on with the next assignment.

I am now getting into Win32 Assembly programming not because I think it is the best language for me to program in but because 1) I like it, 2) it's fun, 3) it gets me back to 'bond' I used to have with the computer in the good o'days.

rea

Also you can try nasm/yasm/fasm :)

QuoteUsing high level syntax in ASM completely defeats the purpose of doing things in asm.

I agree in the sintaxis, but not agree in the technique :).

High level lenguage is diferent than structured programming or object oriented programming, the 2 laters are techniques. High level lengauge mean mainly to abstract the machine opcodes and internal representation of the machine.

I agree because the sintaxis used for the structures of structured programming have a sintaxis like c/pascal, where I think they can be implemented for asm dont requiring to use a similar to such languages, but some that reflect more the mnemonics used.

Some one of you say: write in C and the dificult speed parts in asm, why not use an asm with a great suport for SS and OO, that provide a strong suport for them (yes including optimizers for this parts) and write the speed parts without the use of this techniques/tools provided with the assembler? there no exist such assembler :).

Robert Collins

Quote from: MANT on December 23, 2004, 04:15:10 AM
In essense, yes, it would be the same thing. Only for many of us it's more fun to do it in assembler. Some of us are interested in doing everything low-level; others are more interested in writing C and optimizing the bottlenecks as much as possible.

BTW, in your original post, which assembler's code were you looking at? When I first read it, I kind of figured you might be looking at HLA code, which is significantly different than all the other assemblers I can think of. Even when MASM code gets very high-level, you usually cannot mistake it for anything but assembler. HLA, on the other hand, can easily be mistaken for a high-level language like C or Pascal.


I really don't recall which one it was since I was looking at so many. Also, I was mainly just briefly scanning over them to see what I could see without trying to figure anything out. Below is an example of one that fits into that category. It isn't that it doesn't contain any assembly instructions but the overall appearance of it kind of made me think I was looking at a new way to write 'C' style Windows programs.


386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include mhook.inc
includelib mhook.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

wsprintfA proto C :DWORD,:DWORD,:VARARG
wsprintf TEXTEQU <wsprintfA>
.const
IDD_MAINDLG                     equ 101
IDC_CLASSNAME                   equ 1000
IDC_HANDLE                      equ 1001
IDC_WNDPROC                     equ 1002
IDC_HOOK                        equ 1004
IDC_EXIT                        equ 1005
WM_MOUSEHOOK equ WM_USER+6

DlgFunc PROTO :DWORD,:DWORD,:DWORD,:DWORD
.data
HookFlag dd FALSE
HookText db "&Hook",0
UnhookText db "&Unhook",0
template db "%lx",0
.data?
hInstance dd ?
hHook dd ?
.code
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,IDD_MAINDLG,NULL,addr DlgFunc,NULL
invoke ExitProcess,NULL

DlgFunc proc hDlg:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
LOCAL hLib:DWORD
LOCAL buffer[128]:byte
LOCAL buffer1[128]:byte
LOCAL rect:RECT
.if uMsg==WM_CLOSE
.if HookFlag==TRUE
invoke UninstallHook
.endif
invoke EndDialog,hDlg,NULL
.elseif uMsg==WM_INITDIALOG
invoke GetWindowRect,hDlg,addr rect
invoke SetWindowPos,hDlg,HWND_TOPMOST,rect.left,rect.top,rect.right,rect.bottom,SWP_SHOWWINDOW
.elseif uMsg==WM_MOUSEHOOK
invoke GetDlgItemText,hDlg,IDC_HANDLE,addr buffer1,128
invoke wsprintf,addr buffer,addr template,wParam
invoke lstrcmpi,addr buffer,addr buffer1
.if eax!=0
invoke SetDlgItemText,hDlg,IDC_HANDLE,addr buffer
.endif
invoke GetDlgItemText,hDlg,IDC_CLASSNAME,addr buffer1,128
invoke GetClassName,wParam,addr buffer,128
invoke lstrcmpi,addr buffer,addr buffer1
.if eax!=0
invoke SetDlgItemText,hDlg,IDC_CLASSNAME,addr buffer
.endif
invoke GetDlgItemText,hDlg,IDC_WNDPROC,addr buffer1,128
invoke GetClassLong,wParam,GCL_WNDPROC
invoke wsprintf,addr buffer,addr template,eax
invoke lstrcmpi,addr buffer,addr buffer1
.if eax!=0
invoke SetDlgItemText,hDlg,IDC_WNDPROC,addr buffer
.endif
.elseif uMsg==WM_COMMAND
.if lParam!=0
mov eax,wParam
mov edx,eax
shr edx,16
.if dx==BN_CLICKED
.if ax==IDC_EXIT
invoke SendMessage,hDlg,WM_CLOSE,0,0
.else
.if HookFlag==FALSE
invoke InstallHook,hDlg
.if eax!=NULL
mov HookFlag,TRUE
invoke SetDlgItemText,hDlg,IDC_HOOK,addr UnhookText
.endif
.else
invoke UninstallHook
invoke SetDlgItemText,hDlg,IDC_HOOK,addr HookText
mov HookFlag,FALSE
invoke SetDlgItemText,hDlg,IDC_CLASSNAME,NULL
invoke SetDlgItemText,hDlg,IDC_HANDLE,NULL
invoke SetDlgItemText,hDlg,IDC_WNDPROC,NULL
.endif
.endif
.endif
.endif
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
DlgFunc endp

end start

donkey

There is no language as elegant in it's simplicity as assembly. With only a few instructions you can build a working peice of code. Granted that many take the route of using it as C with a MOV instruction but that is nothing more than a personal choice. For others everything is a puzzle to be solved in the most optimal way. It is very difficult for a beginner or intermediate assembly language programmer to outpace a good optimizing C compiler, but that is not the only point of writing in assembler, it is also the understanding and control that it offers. Once you begin programming in assembly you will begin to truly understand how the x86 and Windows really work and also why in some cases they don't. I remember that I once posted a reply to a C++ board mentioning that the return value was in EAX, a few of the programmers there knew what EAX was, most had no idea. High level languages by nature must obscure the machine and provide a degree of separation, but though this may be fine for most people, there are a few that keep asking "why" and they inevitably end up finding the answers in assembly. Here you will find people like MANT, Raymond, Mark and Bogdan that will help to explain the answer and maybe even point out some new questions you never thought of. I came to assembler without any high level language and it is still the only language I use, HLL's tend to confuse and frustrate me as they keep imposing rules on my code, with assembler I am free to write what I want the way I want without artificial constraints placed on me by the compiler.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Robert Collins

Quote from: donkey on December 23, 2004, 06:04:14 AM
There is no language as elegant in it's simplicity as assembly. With only a few instructions you can build a working peice of code. Granted that many take the route of using it as C with a MOV instruction but that is nothing more than a personal choice. For others everything is a puzzle to be solved in the most optimal way. It is very difficult for a beginner or intermediate assembly language programmer to outpace a good optimizing C compiler, but that is not the only point of writing in assembler, it is also the understanding and control that it offers. Once you begin programming in assembly you will begin to truly understand how the x86 and Windows really work and also why in some cases they don't. I remember that I once posted a reply to a C++ board mentioning that the return value was in EAX, a few of the programmers there knew what EAX was, most had no idea. High level languages by nature must obscure the machine and provide a degree of separation, but though this may be fine for most people, there are a few that keep asking "why" and they inevitably end up finding the answers in assembly. Here you will find people like MANT, Raymond, Mark and Bogdan that will help to explain the answer and maybe even point out some new questions you never thought of. I came to assembler without any high level language and it is still the only language I use, HLL's tend to confuse and frustrate me as they keep imposing rules on my code, with assembler I am free to write what I want the way I want without artificial constraints placed on me by the compiler.

I absolutely agree. And that is why I Love Assembly. The unfortunate thing is when you work for the man you are not always at the liberty of '...being free to write what you want and the way you want...'. In my world of programming I not only have to worry about me later understanding what I did but more importantly is that I must make sure that others who follow after me will be able to understand what I did so that is why companies impose such standards that one must follow. It doesn't matter what language I use the company has their programming policies and that is that. I as an employee cannot just venture out on my own and create any program I want to or the way I want to. There is nothing I dislike more than to have to go get a program written by some other employee who didn't follow the standards of the programming department and wrote a total disaster program. We call it 'spaghetti code'. I think companies think that there is 'too much room for errors and esoteric programming' in assembly. High Level compiliers force you to use certain standard and conventions while assembly has alot of slack and that is what makes it an undesirable language in the eyes of the company. Personnaly, if I had my way I would do everything in Assembly but I also see the other side of the coin.