How to build machine code With ML(dos & win *.asm) & linker (*.obj)

Started by xman_1365_x, December 19, 2010, 10:30:30 AM

Previous topic - Next topic

xman_1365_x

Hi
how to get machine code of
assembly file (DOS and Windows) and object file by ML and linker?
Thanks

dedndave

you need to use Link16.exe - not Link.exe
if you do not find Link16.exe in the \masm32\bin folder, you may d/l it here
http://website.masm32.com/microsoft/Lnk563.exe
that is a self-extracting archive - the first time you run it, it will over-write itself with the linker

once it has been extracted, it is probably easiest to rename it from link563.exe to Link16.exe and place it in the bin folder

also - download the attached batch file and place it in the same folder
then, use.....
a16 MyFile
the .asm extension is assumed

xman_1365_x

I want to take the machine code no executable file!
Because of this work(dos),I use other assemblers like Fasm,Masm611,tasm & etc
& win32 Ml
in emu8086 this use fasm to get machin code in "noname.exe.list" (what switch?)
now ml & linker,switch for this job?
(plz say for dos & win)
for example this output:


dedndave

you can make a tiny model program
i guess you are trying to make ROM-able code
let me look at your file, and i can give better suggestions...

MichaelW

If you are asking how to create a listing file, this batch file shows how to do that, and also how to generate a linker map file.

set file="filename_without_extension"

set path=d:\masm32\bin;%PATH%

if exist %file%.obj del %file%.obj
if exist %file%.exe del %file%.exe
ml /Fl /Sa /c %file%.asm
pause
rem This syntax for a tiny memory model:
rem Link16 /TINY %file%.obj,%file%.com;
rem Link16 %file%.obj;
Link16 /MAP %file%.obj;
pause
eschew obfuscation

dedndave

yes - i think that's what he wants - a listing   :P

you can get a list of switches...

ml /?
ml /help

link16 /?
link16 /help

clive

ML -c  -Fl  foo.asm

-c Compile Only
-Fl Listing File

The linker is not required, MASM will generate the listing.

Microsoft (R) Macro Assembler Version 6.14.8444     12/19/10 09:29:13
noname.asm      Page 1 - 1


.MODEL SMALL
; multi-segment executable file template.

.STACK 128

0000 .DATA

; add your data here!
0000 70 72 65 73 73 20 pkey db "press any key...$"
       61 6E 79 20 6B 65
       79 2E 2E 2E 24

0011 70 61 73 73 77 6F pkey1 db "password dorost ast$"
       72 64 20 64 6F 72
       6F 73 74 20 61 73
       74 24

0000 .CODE
0000 start:
; set segment registers:
0000  B8 ---- R mov ax, @data
0003  8E D8 mov ds, ax
0005  8E C0 mov es, ax

; add your code here
0007  B3 01 mov bl,1

0009  B4 01 mov ah,01
000B  CD 21 int 21h


000D  2C 30 sub al,48

000F  38 D8 cmp al,bl
0011  75 0A jne l1  ;exit



0013  8D 16 0011 R lea dx, pkey1
0017  B4 09 mov ah, 9
0019  CD 21 int 21h
001B  EB 08 jmp l2

;end my code


001D  8D 16 0000 R l1: lea dx, pkey
0021  B4 09 mov ah, 9
0023  CD 21 int 21h        ; output string at ds:dx

; wait for any key....
0025  B4 01 l2:    mov ah, 1
0027  CD 21 int 21h

0029  B8 4C00 mov ax, 4c00h ; exit to operating system.
002C  CD 21 int 21h

end start ; set entry point and stop the assembler.
Microsoft (R) Macro Assembler Version 6.14.8444     12/19/10 09:29:13
noname.asm      Symbols 2 - 1




Segments and Groups:

                N a m e                 Size     Length   Align   Combine Class

DGROUP . . . . . . . . . . . . . GROUP
_DATA  . . . . . . . . . . . . . 16 Bit 0025   Word   Public  'DATA'
STACK  . . . . . . . . . . . . . 16 Bit 0080   Para   Stack   'STACK'
_TEXT  . . . . . . . . . . . . . 16 Bit 002E   Word   Public  'CODE'


Symbols:

                N a m e                 Type     Value    Attr

@CodeSize  . . . . . . . . . . . Number 0000h
@DataSize  . . . . . . . . . . . Number 0000h
@Interface . . . . . . . . . . . Number 0000h
@Model . . . . . . . . . . . . . Number 0002h
@code  . . . . . . . . . . . . . Text    _TEXT
@data  . . . . . . . . . . . . . Text    DGROUP
@fardata?  . . . . . . . . . . . Text    FAR_BSS
@fardata . . . . . . . . . . . . Text    FAR_DATA
@stack . . . . . . . . . . . . . Text    DGROUP
l1 . . . . . . . . . . . . . . . L Near 001D   _TEXT
l2 . . . . . . . . . . . . . . . L Near 0025   _TEXT
pkey1  . . . . . . . . . . . . . Byte 0011   _DATA
pkey . . . . . . . . . . . . . . Byte 0000   _DATA
start  . . . . . . . . . . . . . L Near 0000   _TEXT

   0 Warnings
   0 Errors
It could be a random act of randomness. Those happen a lot as well.

xman_1365_x

Thank you very much
clive,dedndave and MichaelW

i need this switch /Fl :) for file list to show machine code

but in ml /? or help
I do not understand the purpose of your switch
Description was too general because

clive

It only generates a .LST file if you use the -Fl option, otherwise it just generates machine code into .OBJ file. You want to "see" the opcode encodings, so you need to generate a listing.

/Fl[file] Generate listing

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


        ML [ /options ] filelist [ /link linkoptions ]

/AT Enable tiny model (.COM file)         /nologo Suppress copyright message
/Bl<linker> Use alternate linker          /Sa Maximize source listing
/c Assemble without linking               /Sc Generate timings in listing
/Cp Preserve case of user identifiers     /Sf Generate first pass listing
/Cu Map all identifiers to upper case     /Sl<width> Set line width
/Cx Preserve case in publics, externs     /Sn Suppress symbol-table listing
/coff generate COFF format object file    /Sp<length> Set page length
/D<name>[=text] Define text macro         /Ss<string> Set subtitle
/EP Output preprocessed listing to stdout /St<string> Set title
/F <hex> Set stack size (bytes)           /Sx List false conditionals
/Fe<file> Name executable                 /Ta<file> Assemble non-.ASM file
/Fl[file] Generate listing                /w Same as /W0 /WX
/Fm[file] Generate map                    /WX Treat warnings as errors
/Fo<file> Name object file                /W<number> Set warning level
/FPi Generate 80x87 emulator encoding     /X Ignore INCLUDE environment path
/Fr[file] Generate limited browser info   /Zd Add line number debug info
/FR[file] Generate full browser info      /Zf Make all symbols public
/G<c|d|z> Use Pascal, C, or Stdcall calls /Zi Add symbolic debug info
/H<number> Set max external name length   /Zm Enable MASM 5.10 compatibility
/I<name> Add include path                 /Zp[n] Set structure alignment
/link <linker options and libraries>      /Zs Perform syntax check only
It could be a random act of randomness. Those happen a lot as well.

dedndave

different version of ML...
C:\Documents and Settings\Dave>ml /?
Microsoft (R) Macro Assembler Version 6.15.8804
Copyright (C) Microsoft Corp 1981-2000.  All rights reserved.

        ML [ /options ] filelist [ /link linkoptions ]

/AT Enable tiny model (.COM file)         /omf generate OMF format object file
/Bl<linker> Use alternate linker          /Sa Maximize source listing
/c Assemble without linking               /Sc Generate timings in listing
/Cp Preserve case of user identifiers     /Sf Generate first pass listing
/Cu Map all identifiers to upper case     /Sl<width> Set line width
/Cx Preserve case in publics, externs     /Sn Suppress symbol-table listing
/coff generate COFF format object file    /Sp<length> Set page length
/D<name>[=text] Define text macro         /Ss<string> Set subtitle
/EP Output preprocessed listing to stdout /St<string> Set title
/F <hex> Set stack size (bytes)           /Sx List false conditionals
/Fe<file> Name executable                 /Ta<file> Assemble non-.ASM file
/Fl[file] Generate listing                /w Same as /W0 /WX
/Fm[file] Generate map                    /WX Treat warnings as errors
/Fo<file> Name object file                /W<number> Set warning level
/FPi Generate 80x87 emulator encoding     /X Ignore INCLUDE environment path
/Fr[file] Generate limited browser info   /Zd Add line number debug info
/FR[file] Generate full browser info      /Zf Make all symbols public
/G<c|d|z> Use Pascal, C, or Stdcall calls /Zi Add symbolic debug info
/H<number> Set max external name length   /Zm Enable MASM 5.10 compatibility
/I<name> Add include path                 /Zp[n] Set structure alignment
/link <linker options and libraries>      /Zs Perform syntax check only
/nologo Suppress copyright message


Link16...
C:\Documents and Settings\Dave>link16 /?

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

Usage:

LINK
LINK @<response file>
LINK <objs>,<exefile>,<mapfile>,<libs>,<deffile>

Valid options are:
  /?                             /ALIGNMENT
  /BATCH                         /CODEVIEW
  /CPARMAXALLOC                  /DOSSEG
  /DSALLOCATE                    /DYNAMIC
  /EXEPACK                       /FARCALLTRANSLATION
  /HELP                          /HIGH
  /INFORMATION                   /LINENUMBERS
  /MAP                           /NODEFAULTLIBRARYSEARCH
  /NOEXTDICTIONARY               /NOFARCALLTRANSLATION
  /NOGROUPASSOCIATION            /NOIGNORECASE
  /NOLOGO                        /NONULLSDOSSEG
  /NOPACKCODE                    /NOPACKFUNCTIONS
  /NOFREEMEM                     /OLDOVERLAY
  /ONERROR                       /OVERLAYINTERRUPT
  /PACKCODE                      /PACKDATA
  /PACKFUNCTIONS                 /PAUSE
  /PCODE                         /PMTYPE
  /QUICKLIBRARY                  /SEGMENTS
  /STACK                         /TINY
  /WARNFIXUP


32-bit link.exe...

C:\Documents and Settings\Dave>link /?
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

usage: LINK [options] [files] [@commandfile]

   options:

      /ALIGN:#
      /BASE:{address|@filename,key}
      /COMMENT:comment
      /DEBUG
      /DEBUGTYPE:{CV|COFF}
      /DEF:filename
      /DEFAULTLIB:library
      /DLL
      /DRIVER[:{UPONLY|WDM}]
      /ENTRY:symbol
      /EXETYPE:DYNAMIC
      /EXPORT:symbol
      /FIXED[:NO]
      /FORCE[:{MULTIPLE|UNRESOLVED}]
      /GPSIZE:#
      /HEAP:reserve[,commit]
      /IMPLIB:filename
      /INCLUDE:symbol
      /INCREMENTAL:{YES|NO}
      /LARGEADDRESSAWARE[:NO]
      /LIBPATH:dir
      /MACHINE:{ALPHA|ARM|IX86|MIPS|MIPS16|MIPSR41XX|PPC|SH3|SH4}
      /MAP[:filename]
      /MAPINFO:{EXPORTS|FIXUPS|LINES}
      /MERGE:from=to
      /NODEFAULTLIB[:library]
      /NOENTRY
      /NOLOGO
      /OPT:{ICF[,iterations]|NOICF|NOREF|NOWIN98|REF|WIN98}
      /ORDER:@filename
      /OUT:filename
      /PDB:{filename|NONE}
      /PDBTYPE:{CON[SOLIDATE]|SEPT[YPES]}
      /PROFILE
      /RELEASE
      /SECTION:name,[E][R][W][S][D][K][L][P][X]
      /STACK:reserve[,commit]
      /STUB:filename
      /SUBSYSTEM:{NATIVE|WINDOWS|CONSOLE|WINDOWSCE|POSIX}[,#[.##]]
      /SWAPRUN:{CD|NET}
      /VERBOSE[:LIB]
      /VERSION:#[.#]
      /VXD
      /WARN[:warninglevel]
      /WINDOWSCE:{CONVERT|EMULATION}
      /WS:AGGRESSIVE


xman_1365_x

thanks clive for say different opcode encodings & machine code in ml
i think since opcode encodings equal to machine codes :D
my problem Same different & little comment in help ml & linker & msdn in this links:
ML32: http://msdn.microsoft.com/en-us/library/s0ksfwcf%28v=vs.71%29.aspx
ML64: http://msdn.microsoft.com/en-us/library/s0ksfwcf.aspx
Linker: http://msdn.microsoft.com/en-us/library/y0zzbyt4%28v=VS.80%29.aspx
1-now exist sample in book or website special  for all switch command  in ml & linker ?
--
& thanks dedndave for say different ml version
---
in continuance:
2-say about linker own this switch ?(Generate listing for "opcode")

clive

Ok, the linker doesn't display the code, at least the 16-bit linker. The 32-bit linker has a -dump / DUMPBIN function which will disassemble, but that has less utility than the listing file in this context. I guess it depends a lot on exactly what you want to achieve. I'm not sure the Microsoft tools are ideal for creating ROMs, but it could be done. Binary and HEX formats are better for that, than EXE or COM files.

Opcode Encoding (ie Opcode Mnemonic + Operand(s) converted to hex), is equivalent to Machine Code, I would use the terms interchangably. MASM is producing relocatable object files, so you have to keep that in mind.
It could be a random act of randomness. Those happen a lot as well.