i am an assemly noobie. currently i am taking a class that concerns itself with different types of programming languages and the midterm project for me is to make a program in C and assembly, compare and contrast the programs, and compare and contrast the languages. problem is, i have no clue how to work with assembly. i have looked at some tutorials and i have downloaded at least ten free assemblers/compilers but i cannot even write enough proper code for any of the assemblers to get one measly line to appear in the command prompt. i have found code examples but i do not know how to implement the code for the assemlers i have.

i need to know:

a. the best assembler/compiler i can get without paying for it.
b. where i can find a list of the basic functions and routines (if any) appropriate to that assembler
c. how to implement a stack in assembly
d. how to read data from a file in assembly
e. anything else anyone is willing to give me. advice, code examples, assemblers, etc etc etc.

aim sn: Blumdude
e-mail: http://www.asmcommunity.net/board/cryptmail.php?tauntspiders=in.your.face@nomail.for.you&id=061d78231868196edb0fef01d73ac9ba orhttp://www.asmcommunity.net/board/cryptmail.php?tauntspiders=in.your.face@nomail.for.you&id=5ac224afa4626df4fb03785300f0c2af

if you dont posta reply here, please send me an e-mail with teh subject "Assembly help"

note: i can also use a unix assembler, if its easier to do assembly in unix.
Posted on 2004-02-27 23:34:17 by blumdude
start --->programs -->command prompt

cd\ ---> go to root ie c:\>

type debug.exe
you will the prompt change to - from c:\>

now type
a 100 -------> this is command for assembling 100 means it assembles at address 100
you will see this
116C:0100


now type what ever is shown below
116C:0100 DB B4 --------> db means define byte and 0xb4 is the byte you define
116C:0101 DB 09 -------> 0x09 is the byte you define here and so on
116C:0102 DB BA
116C:0103 DB 09
116C:0104 DB 1
116C:0105 DB CD
116C:0106 DB 21
116C:0107 DB C3
116C:0108 DB 20
116C:0109 DB 48
116C:010A DB 69
116C:010B DB 2C
116C:010C DB 57
116C:010D DB 6F
116C:010E DB 72
116C:010F DB 6C
116C:0110 DB 64
116C:0111 DB 21
116C:0112 DB 24


you want to see what you have assembled
type u 100 u == un assemble 100 is address
-U 100
116C:0100 B409 MOV AH,09
116C:0102 BA0901 MOV DX,0109
116C:0105 CD21 INT 21
116C:0107 C3 RET
116C:0108 204869 AND ,CL
116C:010B 2C57 SUB AL,57
116C:010D 6F DB 6F
116C:010E 726C JB 017C
116C:0110 64 DB 64
116C:0111 2124 AND ,SP

you want to see this in dat format
type d 100


-D 100
116C:0100 B4 09 BA 09 01 CD 21 C3-20 48 69 2C 57 6F 72 6C ......!. Hi,Worl
116C:0110 64 21 24 09 01 CD 21 C3-20 69 2C 57 34 00 5B 11 d!$...!. i,W4.[.


do you want run step by step
do g 100 ----> goes to 100 and executes one instruction


or use t ----> trace


or if you want to run this assembled program

type just g

-G 100

AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=116C ES=116C SS=116C CS=116C IP=0100 NV UP EI PL NZ NA PO NC
116C:0100 B409 MOV AH,09
-G
Hi,World!
Program terminated normally
-


well if you have successfully compleated and understood what is above you have done your first assembler program

which displays hi,world on console


now some basics

to see all commands in debug.exe use debug/?
the string is always terminated by $ == 0x24 not null as in ascii string
if you use int 21h
this is 16 bit assembly
well this is enough for now
more on queries
;)
Posted on 2004-02-28 01:46:04 by bluffer
good news: it ran it worked the computer said hi world to me, and i was overjoyed
bad news: i have no idea how to implement what i just learned within my larger scale program, that is, using assembly to implement a stack to read mathematical expressions in infix form, and evaluate it using postfix on the stack. in C this is so incredibly easy. assembly is quite different.

but i woudl like to thank you, because at least i know someone how to do something. is there any program i can use that i create a regular blah.asm file and it will compile and link it? hmmm.
Posted on 2004-02-28 03:11:33 by blumdude
bluffer, he meant he wants nowadays asm, not to be scared.
blumdude, go to http://www.masm32.com/ , there download MASM. From there on, you have dozens of options for IDE (if you want one). See the "IDEs" section on this board for downloads and comparisons. Coding in asm is similar to coding in C when you're calling API and using "if" statement. Since you asked how to open a file, I see you probably use "fopen" in C. There's no fopen in asm, you'll have to use the Win32 API "CreateFile" or "OpenFile"....
In the MASM8 package, there are many tutorials - read them , you'll see how easy it is to code.
Also, don't forget to write in your project that asm has OOP, too. And there actually is a wide variety of OOP frameworks for asm. Using some special "header" files, coded by people on this board, asm can act like C++ . Asm coders get called handycapped as regards programming design, that they only rule the lowest level, and can't understand the high-level functions. On an interview for work I was told "you asm coders aren't good programmers at all" . Well, not anymore. (and I proved him wrong).
Have fun with your project :)
Posted on 2004-02-28 03:18:10 by Ultrano
ok, i downloaded it and installed it, and i am reading the info that comes with it. if i have any more ?s i will either post here or start another thread, thanks!
Posted on 2004-02-28 03:34:39 by blumdude
Hi Blundude,

You will also need a few things...

Windows API reference:

The best reference available is the Platform SDK or MSDN library. The Library costs money but you can download the PSDK directly from Microsoft. It is rather large so you will probably need broadband.

If you want a smaller reference, there is the Win32.hlp file. This is available at Borland's site but it is quite old and not all of the available functions are represented. Generally it only includes those API functions up to Win95:

http://info.borland.com/devsupport/delphi/downloads/

You will find it near the bottom of the page (8MB)

Intel IA32 instruction reference:

You can order the IA32 architecture manuals from Intel, I believe they are still free for the P4.

There is a small HLP file that is quite good also though it only encompasses the instruction set up to the 486. You can download it from my site :

http://www.nt.net/donkey/files/x86eas.zip

Development environment

There are many excellent IDEs available, these will significantly reduce the learning curve with code completion and other RAD tools. I use RadASM but there is also WinAsm Studio, AsmEdit, EasyCode and others. See the IDEs: usage & development forum to get your hands on a free IDE. Note that all IDEs I mentioned are specific to MASM except RadASM, it can handle different assemblers if you later decide that another suits you better.

Examples and tutorials:

Iczelion
Mad Wizard
Posted on 2004-02-28 09:29:55 by donkey
i think using the windows api would be kind of out of the scope of what i need to do. but is that required with masm32 or radASM? all i really need in the end is a executable, preferably from the command prompt that will display all the 'answers' to the user directly in the console. i'm not really interested in the gui parts of the program, unless of course they are absolutely needed.

i downloaded radasm, i'm taking a look at it when i get back from work, thanks.
Posted on 2004-02-28 10:35:52 by blumdude
It depends what you want to do. If you are running in DOS mode the Windows API will not be of much use. But the Console is a part of Windows not DOS and it's functions are part of the API. The API is not only the GUI functions, it is also memory allocation, input/output etc... You are probably better off running your program in the console than in DOS. Win NT does not have a true DOS mode like Win9x and many things will not work in 2K/XP that will in 9x. The Windows console may be your best bet and for that you need the API reference. Also you should be aware that the current MASM32 package will not link 16 bit code, you will require an older link.exe in order to do DOS code.
Posted on 2004-02-28 10:41:09 by donkey
ok, well that's a problem.

i am going to be coding on a winXP p4, and my program will need to work on windows2000 p3. will that be a problem as well?
Posted on 2004-02-28 10:47:32 by blumdude

ok, well that's a problem.

i am going to be coding on a winXP p4, and my program will need to work on windows2000 p3. will that be a problem as well?


Nope, Console mode is for all versions of Windows. If you have acceptable output on Win2K then generally it will work on all platforms. There is a console template in RadASM for both MASM32 and GoAsm that you can use to get a head start building your application. Just have to use WriteFile and the console handle to send output to the console window. Most assemby programmers write console apps, I am an exception in that I only ever write GUI applications but you will be able to get alot of help with any problems here.
Posted on 2004-02-28 11:01:34 by donkey
alright, thanks, now i need to leave, more information is welcome from anyone!
Posted on 2004-02-28 11:04:39 by blumdude
Also if Windows XP is an NT-based operating system, application run in a different way on Windows 2000!

Many ppl are coding on XP today. And the result are crashing applications on 2K.

Long time i used the following syntax:



myFunction proc [b]uses[/b] edi edx myParameter:DWORD
...
ret
myFunction endp

....and applications still keep crashing in 2K. After using


myFunction proc myParameter:DWORD
local myReturnvalue:DWORD
pushad
...
popad
mov eax,myReturnvalue
ret
myFunction endp

.... things become better. And the code needs less bytes!

In addition to this, M$ is perfect in not naming problems!
Simple test: GetModuleHandleA
Registers affected on NT/2K/XP/2K3 : EAX
Registers affected on 95/98/ME : EAX, ECX, EDX
Quicklook in Win32.HLP -> one return value !!

And now we can imagine why high level languages needs tons of SEH crap to blow up the exe size....

Think about this possible errors when searching a solution for crashing apps...
Posted on 2004-02-28 16:19:44 by cu.Pegasus
You shouldn't depend on the values in ECX and EDX after calling a normal Windows API function, they can be anything. This is stated in the manual. Similarly, your callback functions can change EAX, ECX and EDX to whatever.
Posted on 2004-02-28 17:08:20 by Sephiroth3
cu.Pegasus, http://www.asmcommunity.net/board/index.php?topic=6670 - search for "Register preservation". After reading that, it should be obvious what your errors are. And that there's no reason to blame Microsoft, nor to use the silly zealot abbreviation "M$".
Posted on 2004-02-28 19:19:37 by f0dder
cu.Pegasus,

Your application is probably crashing in win2k because you made use of ebx but never preserve it. And of course Sephiroth3 is right, you should always assume that eax, edx, ecx is not preserved after you call an api.
Posted on 2004-02-28 21:29:27 by roticv
what is eax edx ecx?!?!

and why do i need to use them???
Posted on 2004-02-29 02:55:29 by blumdude
Hi,

EAX,EBX,ECX,EDX,EDI,ESI,EBP,ESP and EIP are registers. The ESP and EBP registers are used for handling the stack, the EIP register is the instruction pointer and the rest are general purpose registers used to manipulate data. The x86 family of microprocessors is not capable of moving data directly from memory to memory, all data must first either pass through a register or the stack. Also registers are required for specific functions, many math functions such as MUL or DIV work only with numbers in EAX. ESI and EDI are the source and destination indexes, they are used for many functions available to REP. ECX is a general purpose register that is also used as a counter in many instructions. EDX is used to hold the high order DWORD of some operations or the remainder of a DIV.

EAX,EBX,EDX,ECX -> use them for anything
ESI,EDI -> use them for most things but also for REP
EBP,ESP -> you can modify these but best not to until you understand the stack
EIP -> don't play with it

Registers in bold must be preserved in a callback (ie DlgProc)

If you are not familiar with registers and their uses, you will have alot of problems in asm, they are at the heart of it all. You should check out the WIKI book, I think there is a section on them.

Also register instructions are smaller and using them where you can instead of memory is much much much faster.
Posted on 2004-02-29 03:08:05 by donkey
yeah i have downloaded many tutorials and basically got an overview of things, but its really all confusing, not having taken any sort of class yet. i have written one program so far! but it was cut and pasted, and i have yet to comment it for myself yet. how in the world do people do this. its so tedious.
Posted on 2004-02-29 03:25:09 by blumdude
Hi Blumdude,

You will find that most asm programmers have a single trait in common, the fanatical obsession with detail. You cannot get far in assembly language if you are expecting to have all of the tasks taken care of behind the scenes like in HLLs. In assembler everything is done by you, there are very few exceptions. You will find as you get more familiar with the structure and syntax that it becomes more intuitive and easy to understand but you still must handle all the details yourself. This can be seen two ways, if you are a control freak like most people here it fits your personality well, if you like to have the minutia taken care of by the compiler, well, it will be a long tedious road.
Posted on 2004-02-29 03:30:53 by donkey
this is all just frustrating, because after reading and downloading examples and learning about a million new things, i still spent two hours fixing two lines of code. i look at all the commented code, and all the totorials and it all is way over my head. guess i'll have to break down and buy myself a assembly for dummies book, i'm sure thats been made (maybe titled differently). thanks for everyones help, but even if i buy myself a textbook or some other form of learning guide, i think i'm pretty much hopelessly lost.
Posted on 2004-02-29 04:01:15 by blumdude