Coming from TASM.. How to make it work in MASM?

Started by neo1691, March 09, 2012, 04:53:13 PM

Previous topic - Next topic

dedndave

neo - try this...
c:\masm32\bin\ml /c multiply.asm
c:\masm32\bin\Link16 multiply.obj


        .MODEL  Small
        .DOSSEG                      ;DOS segment order
        .STACK  1024
        OPTION  CaseMap:None         ;case sensitive

;##########################################################################

        .DATA

multiplicand dw 204Ah       ;first word here
multiplier   dw 3B2Ah       ;second word here

;**************************************************************************

        .DATA?

product      dw 2 dup (?)   ;result of multiplication here

;##########################################################################

        .CODE

;**************************************************************************

_main   PROC    FAR

        ASSUME  DS:DGROUP

        mov     ax, @data               ;initializes the data segment
        mov     ds, ax

        mov     ax, multiplicand        ;get one word
        mul     multiplier              ;multiply by second word
        mov     product, ax             ;store low word of the result
        mov     product+2, dx           ;store high word of the result
        int     3                       ;wait for command from user

;------------------------------------------

;terminate program

        mov     ax,4C00h                ;terminate, return = 0
        int     21h                     ;DOS function call

_main   ENDP

;##########################################################################

        END     _main

SteveAsm

Quote from: dedndave on March 10, 2012, 03:30:23 AM
JwAsm - same syntax as Masm - no licensing problems   :U
i also recommend Pelles C - lot's of good stuff - including a linker

Yes, but neither Jwasm nor Pelles C have a printed manual/book that can be used as the class textbook.
I forgot to mention that.
They use one of the Turbo Asm books as the class textbook. (required reading).

Quote from: neo1691 on March 10, 2012, 04:18:09 AM
I cannot ask my tutor to go to 32 bit microprocessor as our syllabus contains 16 bit 8086 interfacing (exam will be on 8086) so i have to learn it!!
Our education system lags in such things, for C language we are still forced to use the turbo C compiler.

Yeh, out here they not only teach using VB-6, they also still teach C++ using VC++ 6.
Both with Wrox Press books as textbooks.
I wonder what Randall Hyde thinks on this matter. Isn't he associated with the University of California, at Riverside ?

dedndave

well, Steve...
hate to belabor the point, but JwAsm uses the same syntax as Masm
that means that a book written for Masm will work if used with JwAsm

if you can get the intructor to install the masm32 package
then put JwAsm in there
then show him a simple windows GUI program
and perhaps even point him at Iczelion's tutorials so he sees that it isn't difficult

the idea isn't so much to make him switch to 32-bit mid-term - understandable if he doesn't want to do that
but, to make him consider the possibility for future classes
and start him looking for books that teach 32-bit code   :U

as time goes on, more and more students are going to be using a 64-bit version of windows
they aren't going to be able to work with 16-bit code without a lot of messing around

mineiro

Quote from: neo1691 on March 10, 2012, 05:10:41 PM
Did not get any link to masm v5 or v6. Anyways i had masm32 installed on my system. Its installed in C drive and the multiply.asm file is in other drive. I open the command prompt window in that drive (F:/) and type the command you gave, it gives error, 'ml is not recognised as an internal or external command'
Masm32 instalation, by default, put executables in "c:\masm32\bin", in this folder, have ml.exe, link.exe, link16.exe, ... . So you can copy your source code to that place that will work.

Or, if you like to work in your F: drive, in a separated folder, type "path=%path%;c:\masm32\bin"
Now, if you are inside drive F:\, or H:\, or Z:\, and type "ml" will work. This command append one more path to be searched by command prompt (environment) when you type something.
A bit offtopic, but type only "path" and hit <enter>. You will see many folders listed, separated by ";". You can see "c:\windows" listed? If yes, you can type "notepad" and hit <enter>. The environment know about notepad.exe because have searched inside all that folders and have found it.

F:\>ml
ml is not recognised as an internal or external command ...
F:\>path=%path%;c:\masm32\bin
F:\>ml
Microsoft (R) Macro Assembler Version 6.15.8803
Copyright (C) Microsoft Corp 1981-2000.  All rights reserved.
usage: ML [ options ] filelist [ /link linkoptions]
Run "ML /help" or "ML /?" for more info
F:\>

You can append many folders in one time, like this:
path=%path%;c:\masm32\bin;C:\masm32;C:\masm32\include;C:\masm32\lib;;F:\util;G:\editors

neo1691

Thanks a lot for all your replies. I will try that and report soon!!

neo1691

Quote from: dedndave on March 10, 2012, 11:59:41 PM
neo - try this...
c:\masm32\bin\ml /c multiply.asm
c:\masm32\bin\Link16 multiply.obj


This is what i tried

C:\masm32\bin> ml /c multiply.asm
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: multiply.asm

C:\masm32\bin> Link16 multiply.asm

Microsoft (R) Segmented Executable Linker  Version 5.60.339 Dec  5 1994
Copyright (C) Microsoft Corp 1984-1993.  All rights reserved.

Run File [multiply.exe]: Y
List File [nul.map]: Y
Libraries [.lib]: Y
Definitions File [nul.def]: Y
LINK : fatal error L1092: cannot open module-definition file - Y.def

C:\masm32\bin>


What should i do when it prompts for Run File [multiply.exe]:

(sorry if i am being silly  :red  )

jj2007

Quote from: neo1691 on March 10, 2012, 10:56:48 PM
> Copy the file from F: to C:\Masm32 and try again.
Tried this too.. It gives the same error again!! And i have not been able to run Masmbasic because there is no richmasm directory in it!! :(

DosBasic does not require a RichMasm directory. I added a makeit.bat to DosBasic, for use with qEditor. The sample file assembles, links and executes fine.

Study that makeit.bat file - it contains everything you need for simple 16-bit apps.

MichaelW

Quote from: neo1691 on March 11, 2012, 07:11:45 AM
What should i do when it prompts for Run File

With the 16-bit linker, if you terminate the command line with a semicolon the linker will use the defaults for the remaining fields. So you can use this:

Link16 multiply.obj;
eschew obfuscation

dedndave

#23
Quote from: neo1691 on March 11, 2012, 07:11:45 AM
Quote from: dedndave on March 10, 2012, 11:59:41 PM
neo - try this...
c:\masm32\bin\ml /c multiply.asm
c:\masm32\bin\Link16 multiply.obj


This is what i tried

C:\masm32\bin> ml /c multiply.asm
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: multiply.asm

C:\masm32\bin> Link16 multiply.asm

Microsoft (R) Segmented Executable Linker  Version 5.60.339 Dec  5 1994
Copyright (C) Microsoft Corp 1984-1993.  All rights reserved.

Run File [multiply.exe]: Y
List File [nul.map]: Y
Libraries [.lib]: Y
Definitions File [nul.def]: Y
LINK : fatal error L1092: cannot open module-definition file - Y.def

C:\masm32\bin>


What should i do when it prompts for Run File [multiply.exe]:

(sorry if i am being silly  :red  )

you tried to link an ASM file   :P

C:\masm32\bin> Link16 multiply.asm
C:\masm32\bin> Link16 multiply.obj

make a TXT file - once you have saved it, rename it to a BAT file...
@echo off
if "x%1"=="x" goto a16usage
if exist %1.asm goto a16asm
:a16usage
echo Usage: a16 asm16file
echo "asm16file" = asm16file.asm
goto batchexit
:a16asm
if exist %1.obj del %1.obj
c:\masm32\bin\ml /c %1.asm >c:\masm32\bin\asmbl.txt
if errorlevel 1 goto showtxt
if exist %1.exe del %1.exe
c:\masm32\bin\Link16 %1.obj; >>c:\masm32\bin\asmbl.txt
:showtxt
if exist %1.obj del %1.obj
type c:\masm32\bin\asmbl.txt
:batchexit
dir %1.* /o-d


i name mine "a16.bat" and locate it in the c:\masm32\bin folder
i also place that folder in the PATH environment variable
see this link for instructions...
http://www.masm32.com/board/index.php?topic=14154.msg112459#msg112459

then, all you need to do is this...

a16 multiply

neo1691

Quote from: dedndave on March 11, 2012, 11:11:22 AM
Quote from: neo1691 on March 11, 2012, 07:11:45 AM
Quote from: dedndave on March 10, 2012, 11:59:41 PM
then, all you need to do is this...

a16 multiply

I did that!! Here is the output


C:\masm32\bin>a16 multiply
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: multiply.asm

Microsoft (R) Segmented Executable Linker  Version 5.60.339 Dec  5 1994
Copyright (C) Microsoft Corp 1984-1993.  All rights reserved.

Volume in drive C has no label.
Volume Serial Number is A075-3A80

Directory of C:\masm32\bin

03/12/2012  07:58 PM               558 multiply.exe
03/11/2012  12:37 PM             1,470 multiply.asm
               2 File(s)          2,028 bytes
               0 Dir(s)  83,456,884,736 bytes free

C:\masm32\bin>a16 multiply
Quote

dedndave

 :U

now, all you need to do is learn how to use Debug or SymDeb   :P
the program has no output, so it is the most practical way of seeing what has happened
i prefer to use SymDeb, so....
SymDeb multiply.exe
once you have opened the executable in SymDeb, there are several commands (the SymDeb prompt is a hyphen)
the first command you want to learn is "?" - it gives you a list of all the commands   :P
the most commonly used commands are "u", "t", "g", "r", "q", and the variations of "d" ("d", "db", "dw", "dq")
in this case, the "t" is a good choice - you can single step (trace) through and watch the registers change as each instruction is executed

C:\Masm32\Asm16>SymDeb multiply.exe
Microsoft (R) Symbolic Debug Utility  Version 4.00
Copyright (C) Microsoft Corp 1984, 1985.  All rights reserved.

Processor is [80286]
-?
A [<address>] - assemble              M <range> <address> - move
BC[<bp>] - clear breakpoint(s)        N <filename> [<filename>...] - name
BD[<bp>] - disable breakpoint(s)      O <value> <byte> - output to port
BE[<bp>] - enable breakpoint(s)       P [=<address>] [<value>] - program step
BL[<bp>] - list breakpoint(s)         Q - quit
BP [bp] <address> - set breakpoint    R [<reg>] [[=] <value>] - register
C <range> <address> - compare         S <range> <list> - search
D[type][<range>] - dump memory        S {-|&|+} - source level debugging
E[type] <address> [<list>] - enter    T [=<address>] [<value>] - trace
F <range> <list> - fill               U [<range>] - unassemble
G [=<address> [<address>...]] - go    V [<range>] - view source lines
H <value> <value> - hexadd            W [<address> [<drive><rec><rec>]] - write
I <value> - input from port           X [?] <symbol> - examine symbols(s)
K [<value>] - stack trace             XO<symbol> - open map/segment
L [<addr> [<drive><rec><rec>]] - load Z <symbol> <value>

? <expr> - display expression         > } <device/file> - Redirect output
! [dos command] - shell escape        < { <device/file> - Redirect input
. - display current source line       = ~ <device/file> - Redirect both
\ - screen flip                       * <string> - comment

<expr> ops: + - * / : not seg off by wo dw poi port wport mod and xor or
<type> : Byte, Word, Doubleword, Asciz, Shortreal, Longreal, Tenbytereal
-t
AX=0EC5  BX=0000  CX=002E  DX=0000  SP=0400  BP=0000  SI=0000  DI=0000
DS=0EB3  ES=0EB3  SS=0EC7  CS=0EC3  IP=0013   NV UP EI PL NZ NA PO NC
0EC3:0013 8ED8           MOV    DS,AX
-t
AX=0EC5  BX=0000  CX=002E  DX=0000  SP=0400  BP=0000  SI=0000  DI=0000
DS=0EC5  ES=0EB3  SS=0EC7  CS=0EC3  IP=0015   NV UP EI PL NZ NA PO NC
0EC3:0015 A10A00         MOV    AX,[000A]                          DS:000A=204A
-t
AX=204A  BX=0000  CX=002E  DX=0000  SP=0400  BP=0000  SI=0000  DI=0000
DS=0EC5  ES=0EB3  SS=0EC7  CS=0EC3  IP=0018   NV UP EI PL NZ NA PO NC
0EC3:0018 F7260C00       MUL    Word Ptr [000C]                    DS:000C=3B2A
-t
AX=5A24  BX=0000  CX=002E  DX=0776  SP=0400  BP=0000  SI=0000  DI=0000
DS=0EC5  ES=0EB3  SS=0EC7  CS=0EC3  IP=001C   OV UP EI PL NZ NA PE CY
0EC3:001C A30E00         MOV    [000E],AX                          DS:000E=676F
-t
AX=5A24  BX=0000  CX=002E  DX=0776  SP=0400  BP=0000  SI=0000  DI=0000
DS=0EC5  ES=0EB3  SS=0EC7  CS=0EC3  IP=001F   OV UP EI PL NZ NA PE CY
0EC3:001F 89161000       MOV    [0010],DX                          DS:0010=6172
-t
AX=5A24  BX=0000  CX=002E  DX=0776  SP=0400  BP=0000  SI=0000  DI=0000
DS=0EC5  ES=0EB3  SS=0EC7  CS=0EC3  IP=0023   OV UP EI PL NZ NA PE CY
0EC3:0023 CC             INT    3
-q

C:\Masm32\Asm16>

neo1691

Quote from: dedndave on March 12, 2012, 02:46:18 PM
:U

now, all you need to do is learn how to use Debug or SymDeb   :P
the program has no output, so it is the most practical way of seeing what has happened
i prefer to use SymDeb, so....
SymDeb multiply.exe
once you have opened the executable in SymDeb, there are several commands (the SymDeb prompt is a hyphen)
the first command you want to learn is "?" - it gives you a list of all the commands   :P
the most commonly used commands are "u", "t", "g", "r", "q", and the variations of "d" ("d", "db", "dw", "dq")
in this case, the "t" is a good choice - you can single step (trace) through and watch the registers change as each instruction is executed

C:\Masm32\Asm16>SymDeb multiply.exe
Microsoft (R) Symbolic Debug Utility  Version 4.00
Copyright (C) Microsoft Corp 1984, 1985.  All rights reserved.

Processor is [80286]
-?
A [<address>] - assemble              M <range> <address> - move
BC[<bp>] - clear breakpoint(s)        N <filename> [<filename>...] - name
BD[<bp>] - disable breakpoint(s)      O <value> <byte> - output to port
BE[<bp>] - enable breakpoint(s)       P [=<address>] [<value>] - program step
BL[<bp>] - list breakpoint(s)         Q - quit
BP [bp] <address> - set breakpoint    R [<reg>] [[=] <value>] - register
C <range> <address> - compare         S <range> <list> - search
D[type][<range>] - dump memory        S {-|&|+} - source level debugging
E[type] <address> [<list>] - enter    T [=<address>] [<value>] - trace
F <range> <list> - fill               U [<range>] - unassemble
G [=<address> [<address>...]] - go    V [<range>] - view source lines
H <value> <value> - hexadd            W [<address> [<drive><rec><rec>]] - write
I <value> - input from port           X [?] <symbol> - examine symbols(s)
K [<value>] - stack trace             XO<symbol> - open map/segment
L [<addr> [<drive><rec><rec>]] - load Z <symbol> <value>

? <expr> - display expression         > } <device/file> - Redirect output
! [dos command] - shell escape        < { <device/file> - Redirect input
. - display current source line       = ~ <device/file> - Redirect both
\ - screen flip                       * <string> - comment

<expr> ops: + - * / : not seg off by wo dw poi port wport mod and xor or
<type> : Byte, Word, Doubleword, Asciz, Shortreal, Longreal, Tenbytereal
-t
AX=0EC5  BX=0000  CX=002E  DX=0000  SP=0400  BP=0000  SI=0000  DI=0000
DS=0EB3  ES=0EB3  SS=0EC7  CS=0EC3  IP=0013   NV UP EI PL NZ NA PO NC
0EC3:0013 8ED8           MOV    DS,AX
-t
AX=0EC5  BX=0000  CX=002E  DX=0000  SP=0400  BP=0000  SI=0000  DI=0000
DS=0EC5  ES=0EB3  SS=0EC7  CS=0EC3  IP=0015   NV UP EI PL NZ NA PO NC
0EC3:0015 A10A00         MOV    AX,[000A]                          DS:000A=204A
-t
AX=204A  BX=0000  CX=002E  DX=0000  SP=0400  BP=0000  SI=0000  DI=0000
DS=0EC5  ES=0EB3  SS=0EC7  CS=0EC3  IP=0018   NV UP EI PL NZ NA PO NC
0EC3:0018 F7260C00       MUL    Word Ptr [000C]                    DS:000C=3B2A
-t
AX=5A24  BX=0000  CX=002E  DX=0776  SP=0400  BP=0000  SI=0000  DI=0000
DS=0EC5  ES=0EB3  SS=0EC7  CS=0EC3  IP=001C   OV UP EI PL NZ NA PE CY
0EC3:001C A30E00         MOV    [000E],AX                          DS:000E=676F
-t
AX=5A24  BX=0000  CX=002E  DX=0776  SP=0400  BP=0000  SI=0000  DI=0000
DS=0EC5  ES=0EB3  SS=0EC7  CS=0EC3  IP=001F   OV UP EI PL NZ NA PE CY
0EC3:001F 89161000       MOV    [0010],DX                          DS:0010=6172
-t
AX=5A24  BX=0000  CX=002E  DX=0776  SP=0400  BP=0000  SI=0000  DI=0000
DS=0EC5  ES=0EB3  SS=0EC7  CS=0EC3  IP=0023   OV UP EI PL NZ NA PE CY
0EC3:0023 CC             INT    3
-q

C:\Masm32\Asm16>




Got it!! Thank you very much!!

neo1691

 :dazzled:
Damn still bad luck


C:\masm32\bin>Symdeb multiply.exe
'Symdeb' is not recognized as an internal or external command,
operable program or batch file.

C:\masm32\bin>

dedndave

at the bottom of this post is an attachment...
http://www.masm32.com/board/index.php?topic=18481.msg156179#msg156179

extract the SymDeb.exe file and place it in the masm32\bin folder, then try again   :U

neo1691

Quote from: dedndave on March 13, 2012, 02:45:53 PM
at the bottom of this post is an attachment...
http://www.masm32.com/board/index.php?topic=18481.msg156179#msg156179

extract the SymDeb.exe file and place it in the masm32\bin folder, then try again   :U

Got it.. I hope thats right..


C:\masm32\bin>SymDeb multiply.exe
Microsoft (R) Symbolic Debug Utility  Version 4.00
Copyright (C) Microsoft Corp 1984, 1985.  All rights reserved.

Processor is [80286]
-t
AX=1756  BX=0000  CX=002E  DX=0000  SP=0400  BP=0000  SI=0000  DI=0000
DS=1744  ES=1744  SS=1758  CS=1754  IP=0013   NV UP EI PL NZ NA PO NC
1754:0013 8ED8           MOV    DS,AX
-


Although its quite different from the tasm debugger!!

but still thanks everyone for the great support. I think i have come the right place to learn the assembly language!!

Cheers!!