Using SHELL.ASM from Art of Assembly (Online Version)

Started by theSuha, August 31, 2009, 08:56:44 PM

Previous topic - Next topic

theSuha

I am reading the online Art of Assembly and I have been wondering why none of the programs I have been attempting to compile finished successfully. I decided to test the SHELL.ASM - the framework - and I get these errors with MASM and I really don't have a clue what to do now.

Assembling: C:\Documents and Settings\...\My Documents\shell.asm
C:\Documents and Settings\...\My Documents\stdlib.a(1) : error A2214: GROUP
directive not allowed with /coff option
consts.a
macros.a
stdout.a
stdin.a
Memory.a
conv.a
strings.a
C:\Documents and Settings\...\My Documents\charsets.a(1) : error A2214: GROU
P directive not allowed with /coff option
C:\Documents and Settings\...\My Documents\fp.a(1) : error A2214: GROUP dire
ctive not allowed with /coff option
C:\Documents and Settings\...\My Documents\fp.a(247) : error A2008: syntax e
rror : macro
C:\Documents and Settings\...\My Documents\fp.a(254) : fatal error A1008: un
matched macro nesting


The source from the book ,Art of Assembly (Online version), is:


.xlist
include stdlib.a
includelib stdlib.lib
.list
dseg segment para public 'data'
; Global variables go here:
dseg ends
cseg segment para public 'code'
assume cs:cseg, ds:dseg
; Variables that wind up being used by the standard library routines.
; The MemInit routine uses "PSP" and "zzzzzzseg" labels. They must be
; present if you intend to use getenv, MemInit, malloc, and free.
public PSP
PSP dw ?
;--------------------------------------------
; Here is a good place to put other routines:
;-----------------------------------------------------------------
; Main is the main program. Program execution always begins here.
Main proc
mov cs:PSP, es ;Save pgm seg prefix
mov ax, seg dseg ;Set up the segment
registers
mov ds, ax
mov es, ax
mov dx, 0
meminit
jnc GoodMemInit
print
db "Error initializing memory
manager",cr,lf,0
jmp Quit
GoodMemInit:
;***************************************************************************
; Put your main program here.
;***************************************************************************
Quit: ExitPgm
Main endp
cseg ends
; Allocate a reasonable amount of space for the stack (2k).
sseg segment para stack 'stack'
stk db 256 dup ("stack ")
sseg ends
; zzzzzzseg must be the last segment that gets loaded into memory!
zzzzzzseg segment para public 'zzzzzz'
LastBytes db 16 dup (?)
zzzzzzseg ends
end Main


Any help is  appreciated.

dedndave

#1
it is 16-bit code and you are trying to assemble and link it as 32-bit code
i don't see any .model directive, although - that may be ok with fasm (i don't use it)
the /coff linker switch is for 32-bit code, however
you may need to grab a different batch file for assembling 16-bit programs

EDIT
not sure, but i think "fasm" stands for "flat assembler" - that would seem to imply it isn't capable of assembling 16-bit code
maybe if you try using MASM and LINK, you will have better luck

MichaelW

I'm not sure exactly what the goal is here, and I know very little about the UCR Standard Library, but under Windows 2000 I can build this source (test.asm):

.xlist

; Includes for the library routines.  For performance reasons you may want
; to replace the "stdlib.a" include with the names of the individual packages
; you actually use.  Doing so will speed up assembly by quite a bit.

include stdlib.a
includelib stdlib.lib

; Note: if you want to use the pattern matching functions in the patterns
; package, uncomment the following line:

; matchfuncs

.list

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

dseg segment para public 'data'

; Global variables go here:

    nn dw 123
    ff REAL4 3.14159265

; Note: If you want to use the STDLIB standard character sets (alpha, digits,
; etc.) uncomment the following line:

; include stdsets.a

dseg ends

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


cseg segment para public 'code'
assume cs:cseg, ds:dseg

;-----------------------------------------------------------------
;
; Here is a good place to put your procedures,
; functions, and other routines:
;
;
;
;
;-----------------------------------------------------------------
;
; Main is the main program.  Program execution always begins here.
;
Main proc
mov ax, dseg
mov ds, ax
mov es, ax

; Start by calling the memory manager initialization routine.  This
; particular call allocates all available memory to the heap.  See
; MEMINIT2 if you want to allocate a fixed heap.
;
; Many library routines use the heap, hence the presence of this call
; in this file.  On the other hand, you may safely remove this call
; if you do not call any library routines which use the heap.

meminit

;***************************************************************************
;
; Put your main program here.
;
;***************************************************************************

    printff
    db "Hello World!\t%i\t%8.5f\n",0
    dd nn, ff

    getc

Quit: ExitPgm ;DOS macro to quit program.
Main endp

cseg            ends

; Allocate a reasonable amount of space for the stack (8k).
; Note: if you use the pattern matching package you should set up a
; somewhat larger stack.

sseg segment para stack 'stack'
stk db 1024 dup ("stack   ")
sseg ends

; zzzzzzseg must be the last segment that gets loaded into memory!
; This is where the heap begins.

zzzzzzseg segment para public 'zzzzzz'
LastBytes db 16 dup (?)
zzzzzzseg ends

end Main


With this batch file:

:
: Adjust the paths as necessary to match your configuration.
:
: The /Fl generates a listing file, and the /map generates a map file.
:
set path=\masm32\bin\;%path%
set include=\downloads\aoa-dos\include
set lib=\downloads\aoa-dos\lib

set file="test"

if exist %file%.obj del %file%.obj
if exist %file%.exe del %file%.exe

ml.exe /Fl /c %file%.asm

pause

link16 /map %file%.obj;

pause

%file%

pause


And everything appears to work OK.

eschew obfuscation

japheth

Quote from: theSuha on August 31, 2009, 08:56:44 PM
I am reading the online Art of Assembly and I have been wondering why none of the programs I have been attempting to compile finished successfully. I decided to test the SHELL.ASM - the framework - and I get these errors with MASM and I really don't have a clue what to do now.

You are probably using Masm v8 or 9. These versions write the object module in coff format if nothing else has been specified. So you'll have to add option -omf to your Masm cmdline if you want to assemble 16-bit code:

ml.exe -c -omf shell.asm

theSuha

I guess I called wolf to early (everything is now working)

I first downloaded
Quotehttp://webster.cs.ucr.edu/AsmTools/MASM/stdlib/stdlib.zip
To my surprise in the example sub-directory there is a SHELL.ASM which serves the same purpose...I modified it to:
.xlist

; Includes for the library routines.  For performance reasons you may want
; to replace the "stdlib.a" include with the names of the individual packages
; you actually use.  Doing so will speed up assembly by quite a bit.

include stdlib\include\stdlib.a
includelib stdlib\lib\stdlib.lib
...

Then I just extracted the zip file to the same directory and modified the MichaelW's batch file as follows and VOILA!

:
: Adjust the paths as necessary to match your configuration.
:
: The /Fl generates a listing file, and the /map generates a map file.
:
set path=\masm32\bin\;%path%
set include=\stdlib\INCLUDE
set lib=\stdlib\LIB

set file="shell"

if exist %file%.obj del %file%.obj
if exist %file%.exe del %file%.exe

ml.exe /Fl /c %file%.asm

pause

link16 /map %file%.obj;

pause

%file%

pause


Thank you all for the help   :U :8)