News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Need help with this

Started by is2hard4yu, January 06, 2012, 05:40:15 PM

Previous topic - Next topic

is2hard4yu

So I am trying to learn and understand assembly. Today I found an example of a code that is supposed to read from a .txt file [or at least that's what i understood]. I copied the given code, saved it as an .asm file and tried to compile it with MASM. The problem is that I have 2 errors. And I really can't figure out how to solve them.
First one would be : A2081 missing operand after unary operator
Second: A1008 unmatched macro nesting

So please, can anyone help me correct the errors?

.model small
.stack
.data

  uMaxLength db 255
  uActualLength db ?
  szFileName db 255 dup (?)
  buffer db 100 dup (?), '$'
 
  OpenFileErrorMessage db 'No such file.','$'
  ReadErrorMessage db 'Cannot read from file.','$'
  InputMessage db 'Write a filename and the program will display it:', '$'

.code

main   proc

  mov ax, seg uMaxLength
  mov ds, ax

  mov ah, 09h
  lea dx, InputMessage ;write input message on the screen
  int 21h


  mov ah, 0ah
  lea dx, uMaxLength ;read file name
  int 21h

  mov al, uActualLength
  xor ah, ah
  mov si, ax
  mov szFileName[si], 0 ;make sz see 0A function

  mov ah, 3dh
  xor al, al
  lea dx, szFileName
  int 21h ;open the file

  jc openError ;if error

  mov bx, ax

  repeat:

    mov ah, 3fh
    lea dx, buffer
    mov cx, 100
    int 21h

    jc readError; if error

    mov si, ax
    mov buffer[si], '$'

    mov ah, 09h
    int 21h ;print on screen



    cmp si, 100
    je repeat
 
    jmp stop;jump to end


  openError:

    mov ah, 09h
    lea dx, OpenFileErrorMessage
    int 21h
    jmp stop


  readError:

   mov ah, 09h
   lea dx, ReadErrorMessage
   int 21h

  stop:

    mov ax, 4c00h
    int 21h

main   endp
end main

dedndave

when you show us these errors, be sure to include the numbers in parentheses - they are the line numbers   :U

the problem you are having is because of the label named "repeat"
"repeat" is a reserved word in MASM, used for repetition macros
just change it to something like "repeat1" and try again

is2hard4yu

Quote from: dedndave on January 06, 2012, 06:13:13 PM
when you show us these errors, be sure to include the numbers in parentheses - they are the line numbers   :U

the problem you are having is because of the label named "repeat"
"repeat" is a reserved word in MASM, used for repetition macros
just change it to something like "repeat1" and try again

Thanks for the answer. I did as you said and it is worse.  :(

After replacing repeat with repeat1 I get the following errors:


Here is the code I have now:
.model small
.stack
.data

  uMaxLength db 255
  uActualLength db ?
  szFileName db 255 dup (?)
  buffer db 100 dup (?), '$'
 
  OpenFileErrorMessage db 'No such file.','$'
  ReadErrorMessage db 'Cannot read from file.','$'
  InputMessage db 'Write a filename and the program will display it:', '$'

.code

main   proc

  mov ax, seg uMaxLength
  mov ds, ax

  mov ah, 09h
  lea dx, InputMessage ;write input message on the screen
  int 21h


  mov ah, 0ah
  lea dx, uMaxLength ;read file name
  int 21h

  mov al, uActualLength
  xor ah, ah
  mov si, ax
  mov szFileName[si], 0 ;make sz see 0A function

  mov ah, 3dh
  xor al, al
  lea dx, szFileName
  int 21h ;open the file

  jc openError ;if error

  mov bx, ax

  repeat1:

    mov ah, 3fh
    lea dx, buffer
    mov cx, 100
    int 21h

    jc readError; if error

    mov si, ax
    mov buffer[si], '$'

    mov ah, 09h
    int 21h ;print on screen



    cmp si, 100
    je repeat1
 
    jmp stop;jump to end


  openError:

    mov ah, 09h
    lea dx, OpenFileErrorMessage
    int 21h
    jmp stop


  readError:

   mov ah, 09h
   lea dx, ReadErrorMessage
   int 21h

  stop:

    mov ax, 4c00h
    int 21h

main   endp
end main

MichaelW

#3
With ML.exe, ML.err, and Link16.exe in the same directory as the source file, I can assemble, link, and run it with this batch file:

set file="easy"
ml /W3 /Fl /Sa /c %file%.asm
pause
link16 /MAP %file%;
pause
%file%.exe
pause


And I get no error messages, and the EXE appears to run OK.
eschew obfuscation

jj2007

Assembles fine here but you need the right switches.
use the /omf switch for ml 6.15 or higher
use the /c switch for ml version 6.14 (supplied with Masm32)

linker: link16


dedndave

yup - as JJ said, it builds and works fine here, too

for 16-bit code, you need a 16-bit linker
this is a self-extracting EXE...
http://website.masm32.com/microsoft/Lnk563.exe
once you have extracted it, we usually rename Link to Link16 to avoid confusion with the 32-bit linker

is2hard4yu


MichaelW

Quote from: jj2007 on January 06, 2012, 06:58:00 PM
Assembles fine here but you need the right switches.
use the /omf switch for ml 6.15 or higher
use the /c switch for ml version 6.14 (supplied with Masm32)

In my test I was using ML 6.15, and it worked without the /omf switch.
eschew obfuscation

jj2007

Quote from: MichaelW on January 06, 2012, 08:10:02 PM
Quote from: jj2007 on January 06, 2012, 06:58:00 PM
Assembles fine here but you need the right switches.
use the /omf switch for ml 6.15 or higher
use the /c switch for ml version 6.14 (supplied with Masm32)

In my test I was using ML 6.15, and it worked without the /omf switch.

I stand corrected. Only ML 8.0 and higher need the /omf switch. 6.15 works with the switch, 6.14 chokes with /omf