jshapy8
jshapy8

Reputation: 2051

How to compute the product of six numbers on Assembly Language

I am new to assembly and I am trying to create a program that simply multiplies the product 1 * 2 * 3 * 4 * 5 * 6 and stores that result in the AL register. I am told that I can accomplish this in a single statement.

This is what I have so far:

MOV product, 1 * 2 * 3 * 4 * 5 * 6
MOV al, product

However, this produces the message error A2070: inval on the first line. I also tried to do it like this:

IMUL AH, 1, 2
IMUL BH, 3, 4
IMUL BL, 5, 6
IMUL CL, BH, BL
IMUL AL, CL, AH

But every line of that produces an error referring to the size of the arguments being different.

Could someone tell me the best way I can accomplish computing this product?

Upvotes: 0

Views: 410

Answers (1)

Jester
Jester

Reputation: 58762

Note that 1*2*3*4*5*6 = 720 so it won't fit into a 8 bit register so you should use a 16 bit one, such as ax. If you are allowed to use compile time multiply, then of course mov ax, 1*2*3*4*5*6 should work. The assembler simply turns that into mov ax, 720, no surprise there.

As for the second version, IMUL does not accept two immediate operands. If you want to use this approach, you will need something like this:

mov ax, 2
imul ax, ax, 3
imul ax, ax, 4
imul ax, ax, 5
imul ax, ax, 6

Upvotes: 2

Related Questions