Why is my multiplication not compiled?

.486 .model flat, stdcall option casemap :none __UNICODE__ equ 1 include C:\masm32\include\windows.inc include C:\masm32\include\masm32.inc include C:\masm32\include\user32.inc include C:\masm32\include\kernel32.inc include C:\masm32\macros\macros.asm includelib C:\masm32\lib\masm32.lib includelib C:\masm32\lib\user32.lib includelib C:\masm32\lib\kernel32.lib Main PROTO .data a dd 4 b dd 5 .code start: invoke Main invoke ExitProcess,0 Main proc mov cx,a mov ax,b mul ax Main endp end start 
 Microsoft (R) Macro Assembler Version 6.14.8444 Copyright (C) Microsoft Corp 1981-1997. All rights reserved. Assembling: number.asm ~~~~~~~~~~~~~ UNICODE Build ~~~~~~~~~~~~~ number.asm(23) : error A2022: instruction operands must be the same size number.asm(24) : error A2022: instruction operands must be the same size Microsoft (R) Incremental Linker Version 5.12.8078 Copyright (C) Microsoft Corp 1992-1998. All rights reserved. LINK : fatal error LNK1181: cannot open input file "number.obj" Для продолжения нажмите любую клавишу . . . 
  • one
    kolasc.net.ru/cdo/programmes/assembler/mul.html mul assumes the second multiplication operand in ax and cannot use ax as the first operand specified in the command. use another register - Mike
  • one
    @Mike, it may very well. screenshot - insolor
  • @Alex_Rudenkiy, what error does it give? - insolor
  • @insolor But in any case, he will then multiply the ax by himself, he will not guess that the second operand in cx is Mike
  • @Mike, I agree. - insolor

2 answers 2

Here are 23, 24 lines:

 mov cx,a mov ax,b 

The error translates as: "Operands instructions must be the same size." Here the problem is that you are trying to put the contents of the variable a and b (which you declared are 32-bit using dd ), and the registers ax , cx (16-bit). It is necessary either to change the size of variables, or to take 32-bit registers. Because Since the program as a whole is 32-bit, then both registers and variables are more efficient to use 32-bit.

Another error: mul ax multiplies ax by itself, and you need to multiply cx by ax . This requires the mul cx command.

  • no, it complained about the fact that I wanted to insert a variable of type DD into a smaller register and that's it) - alex-rudenkiy
  • @Alex_Rudenkiy, in the code given in the question, two problems, I indicated both of them in the answer. You corrected the second one in your code, but didn’t focus on it in your answer. - insolor
  • Well, yes, there is this: D - alex-rudenkiy
  • but how can I move a pair of edx: eax (mov) to the variable "a"? - alex-rudenkiy
  • @Alex_Rudenkiy, a couple of 32-bit values ​​in one 32-bit variable - no way. If edx is not equal to 0, then either assume that you have an arithmetic overflow, and treat it as an error, or save the result in parts into a 64-bit variable. - insolor

In short everything is simple, it was necessary not to push a number in cx, but in eax. Profit :)

  .486 .model flat, stdcall option casemap :none __UNICODE__ equ 1 include C:\masm32\include\windows.inc include C:\masm32\include\masm32.inc include C:\masm32\include\user32.inc include C:\masm32\include\kernel32.inc include C:\masm32\macros\macros.asm includelib C:\masm32\lib\masm32.lib includelib C:\masm32\lib\user32.lib includelib C:\masm32\lib\kernel32.lib Main PROTO .data a dd 4 b dd 5 .code start: invoke Main invoke ExitProcess,0 Main proc mov eax,a mov ebx,b mul ebx Main endp end start 
  • Small nagging: by convention, the stdcall procedure should not, in particular, modify the ebx, edi, esi registers (if it is strongly needed, then save their value at the input, and restore it when the procedure exits). It is better to use the registers eax, ecx, edx. - insolor