Answer the question
In order to leave comments, you need to log in
Why can't multiply and divide assembler?
I kind of began to understand that if I assign the value to al, then I assign the value to cl
and write mul cl, then I can assign ax the multiplication of al and cl (ax=al*cl)
But for some reason I get errors: operand size conflict, illegal number of operands when I assign to al the number entered from the keyboard and then multiply it by 5
I need to solve the equation using assembler: X = 5A + 2B * C - B / 4 + 131
Here is my code:
#include <iostream>
using namespace std;
int main()
{
short a, b, c, x;
cout << "a = "; cin >> a;
cout << "b = "; cin >> b;
cout << "c = "; cin >> c;
_asm {
mov al,a
mul al,5
mov bx,ax
mov cl,b
shl cl,1
mov al,c
mul cl
mov cx,b
idiv cx,4
add bx,ax
sub bx,cx
add bx,131
mov x,bx
}
cout <<"x="<< x<<endl;
}
Answer the question
In order to leave comments, you need to log in
short: represents an integer in the range -32768 to 32767. Occupies 2 bytes (16 bits) of memory
short a, b, c, x;
...
_asm {
mov al, a
I think it's the C compiler. sizeof(al) != sizeof(short) hence the error. The second error is that idiv takes only one argument and divides dx:ax by the specified argument.
mul al,5
idiv cx,4
sar cx, 2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question