Question

I'm trying to do a for loop in assembly. I'm using TASM and TLINK. I also have a library that my professor gave to me, but I'm trying to do all the things on my own, and to my surprise, it's not working. So, I just copy pasted my profesor's code and I receive the same error. The error is as follows.

I can compile with TASM, even i create the .exe, I run it, and after running it, insted of doing what it supposed to do, it just says "Syntax error".

Here's my code:

MODEL small
.stack 100h
    N   equ 20
.DATA
    mensaje     db "Hola mundo",10,13,"$"
    mensajefin  db  "Finalizo el for, presiona cualquier tecla para terminar$"
    i           db  (?)
.code
imprimefor  PROC
            mov ax,@data
            mov ds,ax
            mov ah,03h
            int 10h
            mov [i],0
@@for_cmp:  cmp [i],N
            ja @@for_end
            mov dx,offset mensaje
            mov ah,09h
            int 21h
            inc [i]
            jmp @@for_cmp
@@for_end:  mov dx,offset mensajefin
            mov ah,09h
            int 21h
            mov ah,01h
            int 21h
            mov ax,4c00h
            int 21
            ENDP
    END

Here's my professor's:

MODEL small
   .STACK 100h

   ;----- Insert INCLUDE "filename" directives here
   ;----- Insert EQU and = equates here
 INCLUDE procs.inc

       LOCALS

      N     equ 20
      CR    EQU 13
      LF    EQU 10

   .DATA
      mens       db  'Hola Mundo',CR,LF,0
        i        db (?)


   .CODE
    ;-----   Insert program, subrutine call, etc., here

    Principal   PROC
                mov ax,@data    
                mov ds,ax       

                call clrscr

                ; i=0
                mov [i],0

                ; i<n
     @@cmp_for: cmp [i],N
                ja @@fin_for

                mov al,[i]
                inc al
                add al,30h    ; convierte a ASCII

                call putchar

                mov ax,'-'
                call putchar                

                mov  dx,offset mens
                call puts

                ; i++
                inc [i]
                jmp @@cmp_for

     @@fin_for: call getch

                mov ah,04ch      ; fin de programa
                mov al,0             ;
                int 21h              ; 

                ENDP
         END

I looked in a lot of places but I haven't been able to find anything that helps. Any suggestions? Also my professor has a broken leg, so he's not teaching classes to us, so we're kinda screwed.

Was it helpful?

Solution

I wouldn't call your executable for.exe, that's just asking for trouble.

FOR is actually a DOS/Windows internal command so, if you type in for at the command prompt, it will complain bitterly:

c:\Users\Pax> for
The syntax of the command is incorrect.

You can get around this by using a full path specification, as you can see in the following transcript:

c:\Users\Pax> type for.cmd
@echo off
echo hello

c:\Users\Pax> for
The syntax of the command is incorrect.

c:\Users\Pax> .\for
hello

You can see that, although cmd.exe treats for as the internal command, the filespec .\for is treated as an external executable (a batch file in this case, but an exe file in yours).

OTHER TIPS

For instructions for to write an immediate value to a memory location we need to specify how many bytes we want to access, only one byte, a word, or a dword.

mov byte ptr [i],0 ; MASM
mov byte [i],0    ; NASM

Dirk

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top