The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => 16 bit DOS Programming => Topic started by: creature0077 on October 12, 2005, 11:35:27 PM

Title: The Basics
Post by: creature0077 on October 12, 2005, 11:35:27 PM
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.
Title: Re: The Basics
Post by: MusicalMike on October 13, 2005, 12:14:27 AM
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.
Title: Re: The Basics
Post by: creature0077 on October 13, 2005, 03:42:04 AM
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!
Title: Re: The Basics
Post by: creature0077 on October 13, 2005, 04:34:22 AM
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
Title: Re: The Basics
Post by: Vortex on October 13, 2005, 06:30:53 AM
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
Title: Re: The Basics
Post by: hutch-- on October 13, 2005, 11:45:08 AM
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.
Title: Re: The Basics
Post by: creature0077 on October 13, 2005, 02:14:29 PM
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
Title: Re: The Basics
Post by: hutch-- on October 13, 2005, 02:35:58 PM
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(?)
Title: Re: The Basics
Post by: gusto on October 13, 2005, 03:25:01 PM
sounds similar to my class... im just as lost  :dance:
Title: Re: The Basics
Post by: creature0077 on October 13, 2005, 03:44:41 PM
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.
Title: Re: The Basics
Post by: GregL on October 13, 2005, 05:11:31 PM
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.

Title: Re: The Basics
Post by: MusicalMike on October 13, 2005, 05:55:52 PM
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?
Title: Re: The Basics
Post by: creature0077 on October 13, 2005, 05:58:44 PM
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.
Title: Re: The Basics
Post by: MusicalMike on October 13, 2005, 08:30:15 PM
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.
Title: Re: The Basics
Post by: Farabi on October 15, 2005, 02:50:55 AM
Class is similiar to a struc on MASM right? Or is it a function?
Title: Re: The Basics
Post by: MusicalMike on October 15, 2005, 04:40:44 PM
A struct is sort of like a template for a compositedatastructure. Basicly, struct is short for data structure. In order to understand a class, you really need to learn a hybrid language like c++ or a pure oop language like c#. (Please stay away from java). A class is similar to a data structure, but unlike datastructures, they are more like actual types like int or char (again, its something thats easier to grasp if you are familior with c++). Neither of them are anything like a function. A function is simply a subroutine that takes arguments, makes computations based on those arguments, and returns a result.
Title: Re: The Basics
Post by: creature0077 on October 17, 2005, 04:13:52 AM
ok, I'm good on my 32-bit version of the program now.  making it into a 16-bit is a little bit confusing for me.  I'm not clear on how to fix what errors I get. 
;--------------------------------------------------------------------
; Assignment 1 for CSE 2312.001
; Using different Address modes in 16-bit
;
; author: Ben Williams
;--------------------------------------------------------------------

.model small, stdcall
.stack 4096

.data
B WORD 2, 4, 6, 8

.data?
A WORD ?
D WORD 6 DUP(?)

.code

Start:
mov ax, @data
mov ds, ax

mov A, 15h ;immediate mode, 15h into vari A
mov bx, 50h
mov [A], bx ;indirect mode, 50h into vari A
mov cx, [B+0Ch] ;indexed mode, move 4th element to register
mov bp, 02h
mov cl, [B+bp+06h]      ;based indexed mode, move 3rd to register
mov [D+08h], cl ;move register from B to D using indexed mode


mov ax, 4c00h
int 21h

End Start
Title: Re: The Basics
Post by: ninjarider on October 19, 2005, 02:20:21 PM
the only error i get when assembly your above code is your last line before u setup the exit, mov [D+08h], cl.

mov A, 15h
mov bx, 50h
mov [A], bx
mov cx, [B+0Ch]      <-- clue
mov bp, 02h
mov cl, [B+bp+06h]  <-- problem
mov [D+08h], cl       <-- problem