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

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

Previous topic - Next topic

neo1691

Hey Folks. This is my first post here.

I am very much new to Assembly language and really want to learn it! I have done C language and Assembly has been introduced now in our syllabus (Computer Engineering second year   :bg) In my college our teacher uses TASM to compile the code. But i am using windows 7 and have installed MASM..

We have to write instructions for the 8086 microprocessor and in our college much of the build and link process is done via command prompt. I am figuring out how to do the same in MASM.

Also i am using the book Microprocessors and Interfacing by Douglas V Hall. My first code that i want to run is as shown below.

        ; 8086 PROGRAM

;Abstract   :This program multiplies the two 16 bit words in the memory
            ;The locations are called MULTIPLICAND and MULTIPLIER. The result
            ;is stored in the memory location called PRODUCT
;Registers  :Uses CX, DS, AX, DX
;Ports      :None Used

data_here   segment
            multiplicand dw 204ah       ;first word here
            multiplier   dw 3b2ah       ;second word here
            product      dw 2 dup (0)   ;result of multiplication here
data_here   ends

code_here   segment
            assume cs:code_here, ds:data_here
start:      mov ax, data_here           ;initializes the data register
            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
code_here   ends
            end start


Any links or advice for the same would be really helpful.
Sorry if i made any mistake!! Thanks a lot!!

Cheers!!

mineiro

Welcome neo1691;
if you are using masm v5 or v4, just type in prompt: "masm name.asm", and after "link name.obj".
if you are using masm32 from here, when you go link, use the older linker provided, type "ml /c /omf name.asm" and after "link16 name.obj".
I'm suposing you are debuging the generated program, because your example does not return command back again to ms-dos, or maybe some dyna-86L??(your example comes in that manual).
Tasm and Masm have a very close sintax, maybe 90% of same tapes. I do not have changed one line in your code and assembled fine under masm32 package.

You will receive one "warning" while linking your source, like "no stack segment", but in this specific case, ignore.
Or if you like, include one stack segment in your source code:

stack_here    segment stack
        db      100h    dup(?)
stack_here    ends

to your program return to ms-dos, include the lines below at end of you code,(remove/comment that "int 3" and put in that place the code below).

mov     ax, 4C00h   ;exit do dos
int     21h

Be in peace, and keep walking.

dedndave

welcome to the forum   :U

let me start by saying that 16-bit code isn't what you really want to learn
and - if you have a 64-bit OS, it won't run 16-bit code
i know some instructors are stuck on 16-bit, but see if you can convince him to try 32-bit code
if you succeed, you are sure for an A - lol

that having been said....
there are some shortcuts that may interest you
        .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 register
        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


here is the SymDeb result...
C:\Masm32\Asm16>symdeb mul16.exe
Microsoft (R) Symbolic Debug Utility  Version 4.00
Copyright (C) Microsoft Corp 1984, 1985.  All rights reserved.

Processor is [80286]
-u 10 28
0EBF:0010 B8C10E         MOV    AX,0EC1
0EBF:0013 8ED8           MOV    DS,AX
0EBF:0015 A10A00         MOV    AX,[000A]
0EBF:0018 F7260C00       MUL    Word Ptr [000C]
0EBF:001C A30E00         MOV    [000E],AX
0EBF:001F 89161000       MOV    [0010],DX
0EBF:0023 CC             INT    3
0EBF:0024 B8004C         MOV    AX,4C00
0EBF:0027 CD21           INT    21
-r
AX=0000  BX=0000  CX=002E  DX=0000  SP=0400  BP=0000  SI=0000  DI=0000
DS=0EAF  ES=0EAF  SS=0EC3  CS=0EBF  IP=0010   NV UP EI PL NZ NA PO NC
0EBF:0010 B8C10E         MOV    AX,0EC1
-t
AX=0EC1  BX=0000  CX=002E  DX=0000  SP=0400  BP=0000  SI=0000  DI=0000
DS=0EAF  ES=0EAF  SS=0EC3  CS=0EBF  IP=0013   NV UP EI PL NZ NA PO NC
0EBF:0013 8ED8           MOV    DS,AX
-t
AX=0EC1  BX=0000  CX=002E  DX=0000  SP=0400  BP=0000  SI=0000  DI=0000
DS=0EC1  ES=0EAF  SS=0EC3  CS=0EBF  IP=0015   NV UP EI PL NZ NA PO NC
0EBF: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=0EC1  ES=0EAF  SS=0EC3  CS=0EBF  IP=0018   NV UP EI PL NZ NA PO NC
0EBF: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=0EC1  ES=0EAF  SS=0EC3  CS=0EBF  IP=001C   OV UP EI PL NZ NA PE CY
0EBF:001C A30E00         MOV    [000E],AX                          DS:000E=5A24
-t
AX=5A24  BX=0000  CX=002E  DX=0776  SP=0400  BP=0000  SI=0000  DI=0000
DS=0EC1  ES=0EAF  SS=0EC3  CS=0EBF  IP=001F   OV UP EI PL NZ NA PE CY
0EBF:001F 89161000       MOV    [0010],DX                          DS:0010=0776
-t
AX=5A24  BX=0000  CX=002E  DX=0776  SP=0400  BP=0000  SI=0000  DI=0000
DS=0EC1  ES=0EAF  SS=0EC3  CS=0EBF  IP=0023   OV UP EI PL NZ NA PE CY
0EBF:0023 CC             INT    3
-d ds:a 11
0EC1:0000                                4A 20 2A 3B 24 5A            J *;$Z
0EC1:0010  76 07                                            v.
-


i have attached the program and a copy of SymDeb.exe

SteveAsm

Quote from: dedndave on March 09, 2012, 08:50:36 PM
let me start by saying that 16-bit code isn't what you really want to learn

Dave, I know the Comp-Sci professor at the local college and he too teaches ASM based on TASM 16-bit.
I don't know if he's stuck on it, but, it's what the college has.
It's a licensing issue.

I don't think he would accept Masm code as a replacement.
He wants to be able to take the students code and assemble it on the school computer.

Quote
i know some instructors are stuck on 16-bit, but see if you can convince him to try 32-bit code
if you succeed, you are sure for an A - lol
Again, it's a licensing issue.
The college can only use what they have bought.

Gunner

Horse poo, the teachers are just stuck in their old habits.  There are plenty of free Assemblers without restrictions: FASM, GoASM, JWASM, NASM and others.  I have seen many people turned off of Assembly because of 16 bit.
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

SteveAsm

I couldn't agree more. There is some degree of truth to that.

1) the instructor doesn't want to learn something new,
2) the college can't afford to buy the licenses for the assemblers.

Also, for the same reasons, they are still teaching Visual Basic 6.

MichaelW

I modified the source a bit so it provides some indication of what it is doing, and so it will terminate properly:

; 8086 PROGRAM

;Abstract   :This program multiplies the two 16 bit words in the memory
            ;The locations are called MULTIPLICAND and MULTIPLIER. The result
            ;is stored in the memory location called PRODUCT
;Registers  :Uses CX, DS, AX, DX
;Ports      :None Used

data_here   segment
            multiplicand dw 204ah       ;first word here
            multiplier   dw 3b2ah       ;second word here
            product      dw 2 dup (0)   ;result of multiplication here

            msg          db "done",13,10,"$"

data_here   ends

code_here   segment
            assume cs:code_here, ds:data_here
start:      mov ax, data_here           ;initializes the data register
            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

            mov dx, offset msg
            mov ah, 9
            int 21h
            xor ah,ah
            int 16h
            mov ax, 4c00h
            int 21h

code_here   ends
            end start


I can assemble it with ML 6.15 (no errors or warnings) and link with LINK 5.60.339 (no errors but a no-stack-segment warning) and the resulting 564-byte EXE runs OK. Or I can assemble it with Turbo Assembler 3.1 (no errors or warnings) and link with Turbo Link 5.1 (no errors but a no-stack warning) and the resulting 564-byte EXE runs OK.
eschew obfuscation

dedndave

QuoteAgain, it's a licensing issue.
The college can only use what they have bought.

Steve,
JwAsm - same syntax as Masm - no licensing problems   :U
i also recommend Pelles C - lot's of good stuff - including a linker

neo1691

Thanks a lot for all the replies.

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.

Anyway, i feel that masm32 instructions to link and compile are more confusing to me, i would try to install the other versions of masm as they have very similar linking procedures to tasm..

Again thanks a lot for your replies!!  :U

neo1691

Quote from: mineiro on March 09, 2012, 08:23:18 PM
Welcome neo1691;

if you are using masm32 from here, when you go link, use the older linker provided, type "ml /c /omf name.asm" and after "link16 name.obj".
I'm suposing you are debuging the generated program, because your example does not return command back again to ms-dos, or maybe some dyna-86L??(your example comes in that manual).


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'

and what do you mean by
Quotewhen you go link, use the older linker
..

Thanks

jj2007

Quote from: neo1691 on March 10, 2012, 05:10:41 PM
...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'

Oh dear, and now you are stuck in an infinite loop? ::)

My 50$ advice: Copy the file from F: to C:\Masm32 and try again.

Quote
and what do you mean by
Quotewhen you go link, use the older linker
..

Thanks

Go to C:\Masm32\bin and type dir link*.exe
(hint: take the oldest one; that makes it 100$ :green)

neo1691

Quote from: jj2007 on March 10, 2012, 05:56:44 PM
Quote from: neo1691 on March 10, 2012, 05:10:41 PM
...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'

Oh dear, and now you are stuck in an infinite loop? ::)

My 50$ advice: Copy the file from F: to C:\Masm32 and try again.

Quote
and what do you mean by
Quotewhen you go link, use the older linker
..

Thanks

Go to C:\Masm32\bin and type dir link*.exe
(hint: take the oldest one; that makes it 100$ :green)

here is your $100  :8)


C:\masm32\bin>dir link*.exe
Volume in drive C has no label.
Volume Serial Number is A075-3A80

Directory of C:\masm32\bin

03/19/1998  11:58 AM           462,899 link.exe
01/13/1995  09:40 AM           364,544 link16.exe
               2 File(s)        827,443 bytes
               0 Dir(s)  83,508,326,400 bytes free

C:\masm32\bin>


Thanks for the reply!!  :clap:

jj2007

Quote from: neo1691 on March 10, 2012, 06:04:50 PM
Thanks for the reply!!  :clap:

Welcome to the Forum :thumbu
In case you are really, really determined to stick to 16-bit code, here is a tool that may help to build little apps. It's assembler even if it doesn't look like.

neo1691

Quote from: jj2007 on March 10, 2012, 06:11:23 PM
Quote from: neo1691 on March 10, 2012, 06:04:50 PM
Thanks for the reply!!  :clap:

Welcome to the Forum :thumbu
In case you are really, really determined to stick to 16-bit code, here is a tool that may help to build little apps. It's assembler even if it doesn't look like.
I dont want to stick to 16 bit offcourse, only want to learn 16 bit to get a basic knowledge of assembly!! The i will move on to 32 bit as soon as i get enough knowledge. Also i may build small fun devices using 16 bit, just for fun!! But for that i need an assembler..  :green

I will try the one that you gave!! Thanks again

neo1691

Quote from: jj2007 on March 10, 2012, 05:56:44 PM
Quote from: neo1691 on March 10, 2012, 05:10:41 PM
...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'

Oh dear, and now you are stuck in an infinite loop? ::)

My 50$ advice: 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!! :(