Author Topic: help with mul  (Read 9735 times)

Offline jalisco

  • Jr. Member
  • *
  • Posts: 6
help with mul
« on: July 07, 2013, 09:30:37 AM »
Hi,

I am having problems with my code. I know what I want to do, just not sure if it's within the specifications.

I am trying to use the mul command which is normally used to multiply a register with the contents of ax.  What I am trying to do is define (or declare) a constant, and then multiply against that.

Here is the code of the procedure.

skip:
        ; calculate bx=bx/10
        push    ax
        xor     dx, dx
        mov     ax, bx
        div     ten     ; ax = dx:ax / 10   (dx=remainder).
        mov     bx, ax
        pop     ax

        jmp     begin_print

it doesn't work, saying invalid combinations of opcode or operands.

I know it's supposed to be with contents of a register, how can I fix this? =)

Thanks in advance,
Jalisco

changed the code line with mul to
mul   byte [ten]

and that compiled, but running into other errors.

have a nice weekend =)
« Last Edit: July 07, 2013, 09:41:16 AM by jalisco »

Offline avcaballero

  • Full Member
  • **
  • Posts: 133
  • Country: es
    • Abre los Ojos al Ensamblador
Re: help with mul
« Reply #1 on: July 08, 2013, 06:54:03 AM »
You can't divide directly with an EQU constant, It should be within a register or a memory location.

Also, keep in mind that
* word divide dword. For example, bx divide dx:ax, quotient in ax, reminder in dx
* byte divide word. For example, bl divide ax, quotient in al, reminder in ah.

Besides, take care that div only deals with non negative numbers. For negative ones you should use idiv.

Regards

Offline jalisco

  • Jr. Member
  • *
  • Posts: 6
Re: help with mul
« Reply #2 on: July 09, 2013, 04:29:51 PM »
Thanks for the reply. Will have to do try that now.