Author Topic: problem with macro  (Read 2195 times)


  • Guest
problem with macro
« on: April 30, 2009, 09:02:04 PM »
Hi, i'm from spain, sorry for my english.

I have this code:

cr EQU 13
lf EQU 10

%macro print 1

push ax
   push dx
   lea dx,%1
   mov ah,9
   int 21h   ;linea 10
   pop dx
   pop ax


%macro read 1

push ax
   push dx
   lea dx,%1
   mov ah,10
   int 21h
   pop dx
   pop ax


segment pila stack
resb 128
         ;linea 30
segment dades
   missatge DB 'Entra el texte',cr,lf,'$'
   maxcad DB 30
   lencad DB 0
   cadena resb 30
   girat resb 30
   linia_blanc DB cr,lf,'$'
   missatge2 DB 'Vols sortir?',cr,lf,'$'
   maxcad2 DB 2                    ;longitud máxima.
   lencad2 DB 0                    ;longitud leida.
   cadena2 resb 2                  ;buffer que contendrá el texto introducido.

segment codi

mov ax,dades
mov ds,ax
mov es,ax

   print missatge         ;pide que se introduzca un mensaje y lo guarda en maxcad
   read maxcad
   print linia_blanc      ;imprime lina en blanco
   mov bx,0         ;pone el registro bx a 0

   mov al, [cadena+bx]   ;movemos la cadena introducida a al
   push ax
   inc bl         ;linea 60
   cmp bl, lencad      ;hacemos la comparacion para que el proceso se repita mientras bl no sea 0
   jne pushpila      

mov bx, 0
   pop ax
   mov [girat+bx], al   ;extraemos la cadena del registro ax
   inc bl         ;incrementamos el registro bl para comparar con lencad
   cmp bl,lencad
   jne poppila      ;si el registro bl no es = que el valor de lencad repetimos el proceso

mov byte [girat+bx], '$'
   print girat
   print linia_blanc

print missatge2
   read maxcad2
   print linia_blanc

cmp byte [cadena2+0],'s'
   je salir
   cmp byte [cadena2+0],'S'
   je salir
   jmp inicio

   mov ax,4c00h
   int 21h


When i try to compile - or assemble, i don't know exactly what's the correct term - whit
"nasm -f obj prac3.asm" i get an error on each line i use the macro "print" and "read". The error message is this: "invalid combination of opcode and operands".

Could anyone tell me what's the problem? I've read nasm documentation and I think the macros are well defined so i dont' know what's the problem.

Thank you.


  • Guest
Re: problem with macro
« Reply #1 on: April 30, 2009, 09:44:08 PM »
Well, sorry for my Spanish. (no habla) :)

Thank you for a question I know the answer to! :)

Nasm syntax, without the macro, would be:

mov dx, message


lea dx, [message]

lea wants a "memory reference" as its second operand. So in your macro(s)...

lea dx, [%1]

I think that will solve your problem. (untested) If it doesn't - get back to us... :)



  • Guest
Re: problem with macro
« Reply #2 on: May 01, 2009, 09:49:08 AM »
Thank you very much! You are right. I've to practice more with nasm syntax...
Now it works perfectly.

Thanks again!