News:

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

The Basics

Started by creature0077, October 12, 2005, 11:35:27 PM

Previous topic - Next topic

creature0077

Hey, I just started an assembly class and my teacher is a grad student and wrote the notes we have to study for class.  We don't have a book to go with and his notes suck ass basically.  I don't understand the purpose of using all these registries and need to find a good refence online but there is so many that are so complicated I just get lost.  I need something for both, 16-bit and 32-bit, something easy to start out with and something with a couple of examples.  It would help if I knew some codes for displaying variables, registers and flags to the console window.

MusicalMike

Registers, are short term memory storage on the cpu. The eax, ebx, ecx, and edx, general purpose registers are all you will really have to worry about as a beginner. the eip register for instance contains the memory address of the next executable instruction to be exicuted, and shouldn't be modified dirrectly. the eax register generally is used to hold what ever value is returned by a function. Since moving the data of one memory location dirrectly to another can't be accomplished by one mov instruction, typically you would do something like this.


mov eax, someVar
mov anotherVar, eax
;moves the value of someVar, to anotherVar


to display text on the screen, masm comes with a function called StdOut, and can also do input opperations with StdIn. These functions make subsequent api calls which intern display text on the console, and read console input. Check out the help guides that come with your copy of masm32, it should be in a dirrectory like c:\masm32\help. If you want formal training in assembly, look at randal hydes Art Of Assembly (this book uses a special kind of assembler called HLA (High Level Assembler) which is a great teaching tool and will teach you everything you need to know about registers, pointers, various memory addressing modes (which I at first found very scary at first), function calls, the stack, the heap, the intel x86 archetecture, and other things. One thing you should know, int 21h is not good in windows. Infact, the int (interupt) instruction, will see very little use in 32 bit (windows) assembly language. Randal hyde also has a section on this forum if you want to ask him anything. You should be able to get a free copy of Art of Assembly at http://www.nostarch.com/frameset.php?startat=assembly, if you want to pay for it, or http://webster.cs.ucr.edu/AoA/Windows/index.html, which is a beta release of it completely free. Finally, I will end with a programthat demonstrates simple console io just to get you started.


.586
.model flat, stdcall

option casemap:none

include windows.inc
include kernel32.inc
include masm32.inc

includelib kernel32.lib
includelib masm32.lib

.data
myStr db 10 dup(0)

.code

Start:

push 10
push offset myStr
call StdIn
Push offset myStr
call StdOut
push 5000
call Sleep
push 00h
call ExitProcess

End Start


Good luck.

creature0077

That was a good example but the assembler that my teacher tells us to use doesn't contain masm32.lib and i don't know if we are allowed to use that at this time.  I'll try to find it and add it so I can just test and see how everything works.  Thanks for helping me get started!

creature0077

I can't get that example to work, even after adding make32.lib to my folder in my masm32 directory.  You can check out the type of masm that my teacher provides us with.  There isn't a help file or folder which doesn't make it any easier.  I love programing in C++ and C and such but my teacher isn't making things easy for me and I'm trying not to complain.  I'm going to read Art of Assembly and try to figure things out.  The masm I use you can download from...

http://crystal.uta.edu/~vasudeva/teaching/cse2312_fall05/resources.html

Vortex

creature0077,

Welcome to the forum.

Your basepackage.zip contains both of 16-bit and 32-bit tools, I should say you that you can get the complete masm32 package from Hutch's website :

http://www.masm32.com/masmdl.htm

With some minor modifications, your source code is assembled without any problem :
.586
.model flat, stdcall

option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\masm32.inc

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\masm32.lib

.data
myStr db 10 dup(0)
.code

start:

invoke StdIn,ADDR myStr,10
invoke StdOut,ADDR myStr
push   5000
invoke Sleep,5000
invoke ExitProcess,0

END start

hutch--

Vortex is correct here, the bulk of the package is old DOS version masm accesories from the early 90s with a later version of ML and a later LINK for 32 bit. It assumes Kip Irvine's library witout it being present and the basic SDK libraries which are also missing.

The ML version is OK but I would be inclined to get the entire MASM32 project as it works as is and all you need to source if it has to be used is Kip Irvine's library and code.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

creature0077

I asked my teacher if I can include the masm32.inc and other files and he told me I can't for this assignment, he only wants me to use irvine32.inc, which has only windows.inc, kernel32.inc, user32.inc, gdi32.inc, and shell32.inc.  He told me to use the WriteInt function to display the variables to the screen but I can't figure out how to make that work right. 

include irvine32.inc

.data

A DWORD ?

B DWORD 2, 4, 6, 8

D DWORD 6 DUP(?)

.code

Start:
   mov A, 15h      ;direct mode, 15h into vari A
   mov eax, 50h   
   mov [A], eax      ;indirect mode, 50h into vari A
   mov esi, [B+0Ch]   ;indexed mode, move 4th element to register
   mov ebx, 02h   
   mov edi, [B+ebx+06h]    ;based indexed mode, move 3rd to register
   mov [D+08h], edi   ;move register from B to D using indexed mode


   call DumpRegs
   exit

End Start

hutch--

If you are using Kip Irvine's stuff, you should at least have some reference to it, I have no idea what is in his work including his include files and what his library is. I would make sure you have the include file(s), libraries and know the format required to use them.

There is a couple of minor mistakes in te code you posted which is the difference between ininialised and uninitialised data.

.data
B DWORD 2, 4, 6, 8

.data?
A DWORD ?
D DWORD 6 DUP(?)
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

gusto

sounds similar to my class... im just as lost  :dance:

creature0077

Ok, thanks corrected those mistakes.  You can check out the include library from the link I listed before.  It's all in a zip file.

GregL

creature0077,

This may help you. There is a help file for Irvine's library here:

http://www.nuvisionmiami.com/books/asm/files/IrvineLibHelp.exe.

I read his book, it's pretty good, but I never used his library, so I'm not familiar with it.


MusicalMike

QuoteWith some minor modifications, your source code is assembled without any problem :
Just for the the record, my code assembled fine as is on my computer?

creature0077

Oh yeah, I know it assembles fine.  I just don't know for sure if I stored the values in my variables correctly since I can't really figure out how to display them to the screen.

MusicalMike

If you need someone to check your code, feel free to show the code to me, there are also plenty of people around here who are more than willing to help you in any way posible.

Farabi

Class is similiar to a struc on MASM right? Or is it a function?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"