News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

so many questions, so many troubles

Started by Sam, November 04, 2013, 02:24:21 PM

Previous topic - Next topic

Sam

Greetings feom Syria, how is everything going you guys???
so I'm taking Assemblry language this semester, and am tottaly clueless with the IDE, I have some questions, hope you could help me:
am using win7, 32 bit so:
1- are the instructions used in MASM 6.11 work on MASM32 v11??? you know the one we could download from this site, the Qeditor?? in exactly the same syntax???
2- I still can't figure out what's wrong with this simple example:
.MODEL SMALL
.DATA
var1 db 33h
var2 dw 0101h
var3 dd 0aaaa5555h
include io.mac
.code
.386
mov ax,0
mov al,0ah
mov [bx],al
mov [bx+1],al
mov eax,12345678h
.exit
end

when I try to console Assemble and link this, the error A1000: cannot open file io.mac keeps appearing????
we have studied this in class and it worked just fine on WinXp 32 bit masm 6.11???? I mean any include I make (loke windows.inc and so) gives the same error???
3- when I delete this io.mac thing, a linking error appears:LNK2001, unresolved external symbol mainCRTstartup???? what in the world is that???
4- is there any courses I can follow??? you know that starts with me from the very beginning?
5- is debugging, tracing  registers and memory locatons available in Qeditor???
thank you guys, LOVE YOU ALL

hutch--

Sam,

The code you have posted is 16 bit DOS code and there are two problems, it most probably will not run on Win7 unless you use an XP emulator of some type and it will not directly build using MASM32 which is primarily for 32 bit Windows code. Find out what you university course work requires as 16 bit code is not much use any longer unless you run an old operating system version. MASM32 is for building 32 bit code and it comes with a reasonable amount of example code and help files.

jj2007

Hi Sam,

Your code runs fine on Win7-32 if
a) you add the start: label,
b) you add end start
c) you use the 16-bit linker in \masm32\bin\link16.exe (Hutch will explain to you how to do that from qEditor - I use my own editor).

Greetings to Syria,
JJ

.MODEL SMALL
.DATA
var1 db 33h
var2 dw 0101h
var3 dd 0aaaa5555h
; include io.mac
.code
.386
start:
mov ax,0
mov al,0ah
mov [bx],al
mov [bx+1],al
mov eax,12345678h
.exit
end start


hutch--

You expect me to remember a 16 bit OMF linker command line ?  :biggrin:

Gunther

Sam,

greetings to Syria and welcome to the forum.

Gunther
You have to know the facts before you can distort them.

jj2007

Quote from: hutch-- on November 04, 2013, 05:28:49 PM
You expect me to remember a 16 bit OMF linker command line ?  :biggrin:
That is the simple part, Hutch: \masm32\bin\link16 myfile

The less simple part is to do that from qEditor's menu, therefore I counted on you ;-)

hutch--

Mutter, I have not played with 16 bit dos since 1994.

SAM.ASM


.386
.MODEL SMALL
.DATA
  var1 db 33h
  var2 dw 0101h
  var3 dd 0aaaa5555h

;;; include io.mac      ; you have to supply the file IO.MAC

.code

start:                  ; the start label

  mov ax, 0
  mov al, 0ah
  mov [bx], al
  mov [bx+1], al
  mov eax, 12345678h

end start


Builds with the following batch file in the same directory,


@echo off
\masm32\bin\ml.exe /omf sam.asm
\masm32\bin\link16.exe sam.obj,sam.exe ,,, /nod /noe /packc /stack:4096
dir sam.exe
pause

dedndave

on the link16 command line, you can place the switches before the file list
then provide the asm and exe names, seperated by commas
then, use a semicolon to tell the linker to use default responses for the rest of the required fields

if you recall, the old linker would prompt for inputs if the command line didn't provide them   :P
the semicolon turns that off - useful in batch files

you are running 32-bit windows 7, so you should be able to run the program
the problem is - why is the instructor teaching 16-bit code ? - lol

the io.mac file is a macro file that you had on a previous exercise
perhaps provided by the instructor
make sure it is in the same folder as the asm file - or set the include path to where it does exist
i suspect you are going to want it, at some point

as for any courses to follow - i take it you mean tutorials
i am sure they exist - just don't know of too many for 16-bit, offhand
if you google around a little, you might find an old copy of Randall Hyde's Art Of Assembly online
not really a tutorial - it's a book that is presented in html form
http://cs.smith.edu/~thiebaut/ArtOfAssembly/artofasm.html

for old 16-bit code, you can use DEBUG or SYMDEB
again, google is your friend

hutch--

What the EXE is missing is a program termination, vaguely it was int 21h function 4Ch but I don't think I have 16 bit reference material floating around and don't want it anyway.

This seems to be it.


    mov ah, 4Ch
    int 21h

dedndave

.EXIT takes care of that, although i never use it
QuoteWhen the program terminates, you can return an exit code to the operating
system. Applications that check exit codes usually assume that an exit code of 0
means no problem occurred, and that an exit code of 1 means an error
terminated the program. The .EXIT directive accepts a 1-byte exit code as its
optional argument:
.EXIT 1 ; Return exit code 1
.EXIT generates the following code that returns control to MS-DOS, thus
terminating the program. The return value, which can be a constant, memory
reference, or 1-byte register, goes into AL:
mov al, value
mov ah, 04Ch
int 21h
If your program does not specify a return value, .EXIT returns whatever value
happens to be in AL.

it is, however, missing .STARTUP
again, i never use the macro
for a small model program, it will set the DS register to the @data segment, which is actually DGROUP

as shown, the current code does not access the data segment, so it's ok
but as soon as he tries to access one of the variables, he'll be wondering why it isn't right or crashes

hutch--

Here is a small test piece that uses the simplified segment directives. Build it with the same batch file as above.


; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    .model small
    .dosseg
    .stack 1024

  ; -----------------
  ; terminate the app
  ; -----------------
    bye_bye MACRO
      mov ah, 4Ch
      int 21h
    ENDM

  .data
    txt db "Howdy Sam, this is a",13,10, \
    "small memory model DOS exe file$"    ; the "$" terminates the string for DOS function 09h

  .code
  .startup

  ; ----------------------
  ; display a text message
  ; ----------------------
    mov ah, 09h
    mov dx, OFFSET txt
    int 21h

    bye_bye

  ;; .exit 0

  end

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

dedndave

#11
this is what i use as a SMALL model template...
        .MODEL  Small
        .STACK  4096
        .DOSSEG
        .386
        OPTION  CaseMap:None

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

        .DATA

s$Msg   db 'Hello World !',0Dh,0Ah,24h

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

        .DATA?

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

        .CODE

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

_main   PROC    FAR

        mov     dx,@data
        mov     ds,dx

        mov     dx,offset s$Msg
        mov     ah,9
        int     21h

        mov     ax,4C00h
        int     21h

_main   ENDP

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

        END     _main

Gunther

Here's another template, using the handle based I/O functions:

stdin   equ     0                        ; Standard Input Handle
stdout  equ     1                        ; Standard Output Handle
stderr  equ     2                        ; Standard Error Handle
cr      equ     0dh                      ; ASCII Carriage Return
lf      equ     0ah                      ; ASCII Line Feed

DGROUP  group   _DATA,STAK               ; declaration automatic data group

_TEXT   segment word public 'CODE'
        assume  cs:_TEXT,ds:DGROUP,ss:STAK

main    proc    far                      ; main procedure
        mov     ax, DGROUP               ; make data segment addressable
        mov     ds, ax
        mov     ah, 40h                  ; write via handle
        mov     bx, stdout               ; bx = Standard Output Handle
        mov     cx, msglen               ; cx = string length
        mov     dx, offset msg           ; ds:dx -> String
        int     21h                      ; transfer to DOS
        mov     ax, 4c00h                ; terminate
        int     21h
main    endp

_TEXT   ends

_DATA   segment word public 'DATA'

msg     db      cr,lf                    ; string to print
        db      'Hallo Assembly Language World!'
        db      cr,lf
msglen  equ     $-msg                    ; string length

_DATA   ends

STAK    segment para stack 'STAK'

        db      64 dup (?)               ; 64 Byte Stack

STAK    ends
        end     main           



Gunther
You have to know the facts before you can distort them.

K_F

What is the default setting for BX on DOS startup.. I cannot remember  :biggrin:

Curious about these 3 lines
mov al,0ah
mov [bx],al
mov [bx+1],al

8)
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

dedndave

i think ES:BX points to the environment table - i forget
AL and AH are FCB indicators 0 if empty, FF if filled (AL for first FCB, AH for second)
DS has the PSP segment

but, you're right, Van - he probably meant to initialize BX to point to the vars
meaning that DS must also be initialized