From: iamsumesh on
Hi,

I am sumesh. new to assembly programming. i am using masm 6.15. i need
to help in getting tutorial for assembly programming in dos using
masm. and can i get some sample asm source code to start coding at
beginning level.

Sumesh.
From: Benjamin David Lunt on

"iamsumesh" <iamsumesh(a)gmail.com> wrote in message
news:72244112-2d55-4792-8a98-de43c706f660(a)11g2000yqr.googlegroups.com...
> Hi,
>
> I am sumesh. new to assembly programming. i am using masm 6.15. i need
> to help in getting tutorial for assembly programming in dos using
> masm. and can i get some sample asm source code to start coding at
> beginning level.
>
> Sumesh.

Hi Sumesh,

MASM 6.15 is not necessarily able to create DOS programs. It is
a little difficult to do so, especially for a beginner.

Might I suggest NBASM at
http://www.fysnet.net/newbasic.htm

It is an easy to learn DOS assembler and includes a few example
programs. It now includes a WinXP IDE.

Once you have a good grasp on assembly and want to move to Windows
programming, then go back to MASM 6.15, or many of the other available
assemblers.

Enjoy,
Ben

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Forever Young Software
http://www.fysnet.net/index.htm
http://www.fysnet.net/collections.htm
To reply by email, please remove the zzzzzz's

Batteries not included, some assembly required.


From: James Harris on
On 17 Apr, 11:50, iamsumesh <iamsum...(a)gmail.com> wrote:
> Hi,
>
> I am sumesh. new to assembly programming. i am using masm 6.15. i need
> to help in getting tutorial for assembly programming in dos using
> masm. and can i get some sample asm source code to start coding at
> beginning level.

I can't help much. I normally use Nasm which can generate 16-bit DOS
executables (as well as 32-bit and 64-bit executables) but if you want
to use Masm there is a newsgroup

microsoft.public.masm

Folks there may be of more help.

James
From: Herbert Kleebauer on
iamsumesh wrote:

> I am sumesh. new to assembly programming. i am using masm 6.15. i need
> to help in getting tutorial for assembly programming in dos using
> masm. and can i get some sample asm source code to start coding at
> beginning level.

For a start it is sufficient to use only three OS dependent
functions:

getc() : read a character from stdin
putc() : write a character to stdout
exit() : terminate program

This way, the only documentation you need is the processor
manuals (which you can download from Intel's web server).

But even if you are programming 16 bit DOS code, you
always should use 32 bit instructions and 32 addressing
modes, because then the code can be executed without
modification also in Linux and Windows.

Because I don't use MASM, here a simple NASM example
for a program which converts all upper case letters
in the input file to lower case letters in the output
file. usage: test <infile >outfile

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; nasm -O99 -o test.com test.asm

%include "mac.inc" ; ftp://137.193.64.130/pub/assembler/xlinux.zip

org $100

lop: bsr.l getc ; get char from stdin
cmp.l -1,r0 ; EOF
bne.b .10 ; branch if not
andq.l 0,r0
bsr.l exit

.10: cmp.b 'A',r0
blo.b .20
cmp.b 'Z',r0
bhi.b .20
add.b 'a'-'A',r0
.20: bsr.l putc ; write char to stdout
br.b lop ; go on


getc: eor.l r0,r0
movem.l r0-r7,-[sp]
move.w $3f00,r0
lea.l [r7+28],r1
move.w 1,r2
eor.w r3,r3
trap $21
bcs.b .20
cmp.w r0,r2
movem.l [sp]+,r0-r7
beq.b .10
move.l -1,r0
.10: rts.l
.20: move.b -1,r0
br.b exit

putc: movem.l r0-r7,-[sp]
move.w $4000,r0
lea.l [r7+28],r1
move.w 1,r2
move.w r2,r3
trap $21
bcs.b .20
cmp.w r0,r2
bne.b .20
movem.l [sp]+,r0-r7
rts.l
.20: move.b -1,r0
br.b exit

exit: move.b $4c,m0
trap $21

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

If you replace the OS dependent functions getc(), putc(), exit()
by a Linux version, the same main code will also work in Linux:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; nasm -O99 -o test test.asm

%include "mac.inc" ; ftp://137.193.64.130/pub/assembler/xlinux.zip

;===========================================================================
seg 32
orig equ $08048000
code_addr equ orig
code_offset equ 0
section .text vstart=code_addr

;--------------------------- ELF header -----------------------------------

dc.l $464c457f,$00010101,0,0,$00030002,1,main,$34,0,0,$00200034,2,0
dc.l 1,code_offset,code_addr,code_addr,code_filez,code_memsz,5,4096
dc.l 1,data_offset,data_addr,data_addr,data_filez,data_memsz,6,4096

;--------------------------- code ------------------------------------------
main:


lop: bsr.l getc ; get char from stdin
cmp.l -1,r0 ; EOF
bne.b .10 ; branch if not
andq.l 0,r0
bsr.l exit

.10: cmp.b 'A',r0
blo.b .20
cmp.b 'Z',r0
bhi.b .20
add.b 'a'-'A',r0
.20: bsr.l putc ; write char to stdout
br.b lop ; go on




getc: eor.l r0,r0
movem.l r0-r7,-[sp]
move.l 0,r3 ; stdin
lea.l [r7+28],r2
move.l 1,r1 ; 1 byte
move.l 3,r0 ; read
trap $80
tst.l r0,r0
bmi.b .10
movem.l [sp]+,r0-r7
bne.b .20
orq.l -1,r0
.20: rts.l
.10: orq.l -1,r0 ; return code
br.b exit


putc: movem.l r0-r7,-[sp]
move.l 1,r3 ; stdout
lea.l [r7+28],r2
move.l 1,r1 ; 1 byte
move.l 4,r0 ; write
trap $80
cmpq.l 1,r0
bne.b .10
movem.l [sp]+,r0-r7
rts.l
.10: orq.l -1,r0 ; return code
br.b exit


exit: move.l r0,r3 ; return code
move.l 1,r0 ; exit
trap $80


;--------------------------- constant data ---------------------------------
;some_constant: dc.l 3
;---------------------------------------------------------------------------

align 4, db 0
code_memsz equ $-$$
code_filez equ code_memsz
data_addr equ (orig+code_memsz+4095)/4096*4096 + (code_filez % 4096)
data_offset equ code_filez
section .data vstart=data_addr

;--------------------------- initialized data ------------------------------
;some_initialized_data: dc.l 3
;---------------------------------------------------------------------------


idat_memsz equ $-$$
bss_addr equ data_addr+ ($-$$)
section .bss vstart=bss_addr

;--------------------------- uninitialized data ----------------------------
;some_uninitialized_data: blk.b 20
;---------------------------------------------------------------------------

udat_memsz equ $-$$
data_memsz equ idat_memsz + udat_memsz
data_filez equ idat_memsz

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

And if you use the Windows version of getc(), putc(), exit(),
the code also works in Windows. But this is not a NASM version:

getc: eor.l r0,r0
movem.l r0-r7,-(sp)
lea.l 28.b(r7),r1
move.l r0,-(sp)
move.l r7,r2

add.l _handle,r0
bne.b _10
moveq.l #-10,-(sp)
jsr.l (GetStdHandle)
move.l r0,_handle

_10: moveq.l #0,-(sp)
move.l r2,-(sp)
moveq.l #1,-(sp)
move.l r1,-(sp)
move.l r0,-(sp)
jsr.l (ReadFile)
move.l (sp)+,r1
or.l r0,r0
bne.b _20
orq.l #-1,r0
br.b exit
_20: cmp.l #1,r1
movem.l (sp)+,r0-r7
beq.b _30
move.l #-1,r0
_30: rts.l

even4
_handle:dc.l 0


putc: movem.l r0-r7,-(sp)
lea.l 28.b(r7),r1
move.l r0,-(sp)
move.l r7,r2

eor.l r0,r0
add.l _handle,r0
bne.b _10
moveq.l #-11,-(sp)
jsr.l (GetStdHandle)
move.l r0,_handle

_10: moveq.l #0,-(sp)
move.l r2,-(sp)
moveq.l #1,-(sp)
move.l r1,-(sp)
move.l r0,-(sp)
jsr.l (WriteFile)
move.l (sp)+,r1
or.l r0,r0
bne.b _20
_30: orq.l #-1,r0
br.b exit
_20: cmp.l #1,r1
bne.b _30
movem.l (sp)+,r0-r7
rts.l

even4
_handle:dc.l 0


exit: move.l r0,-(sp)
jsr.l (ExitProcess) ; exit program
From: Frank Kotler on
Herbert Kleebauer wrote:

....
> here a simple NASM example...

....
> lop: bsr.l getc ; get char from stdin
> cmp.l -1,r0 ; EOF
> bne.b .10 ; branch if not
> andq.l 0,r0
> bsr.l exit

Just for the record, Sumesh, this is *not* the usual Nasm syntax.

If you're determined to use Masm... for dos... The old, obsolete, 16-bit
"Art of Assembly" may interest you:

<http://homepage.mac.com/randyhyde/webster.cs.ucr.edu/www.artofasm.com/DOS/index.html>

If you're willing to consider something a little more "modern"... and
"flexible"... Dr. Paul Carter's tutorial covers 32-bit programming for
dos (DJGPP - Thanks, D.J.!), Windows, Linux... etc.

http://www.drpaulcarter.com/pcasm

Good luck with your studies!

Best,
Frank