Hey so I am getting this error when I run this code:
1>------ Build started: Project: Project, Configuration: Debug Win32 ------
1> Assembling [Inputs]...
1>assign2.asm(32): error A2022: instruction operands must be the same size
1>assign2.asm(33): error A2022: instruction operands must be the same size
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations\masm.targets(49,5):
error MSB3721: The command "ml.exe /c /nologo /Zi /Fo"Debug\assign2.obj" /Fl"Project.lst"
/I "c:\Irvine" /W3 /errorReport:prompt /Taassign2.asm" exited with code 1.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Here is the following code, it happens when I try to subtract ml1337skillz from usPop and store that result into Difference. (Keep in mind I am just starting to learn this area :))
TITLE Learning (learning.asm)
INCLUDE Irvine32.inc
secondE = 00000000010001010000000000000000b
.data
myName BYTE "John Smith"
nameLen = ($ - myName)
nationalDebt QWORD 7975482431119.47d
usPop DWORD 313900000d
kindaNegative SDWORD -2147483648d
my1337Sk1LLz WORD 1337h
negUnit SBYTE -1
half BYTE 0.5d
Difference SWORD ?
starField BYTE 2000 DUP("*")
bigLoss SDWORD -50000
.code
main PROC
FillRegs:
mov eax,usPop ;store 3139000000d into eax
sub eax,my1337Sk1LLz ;subtracts 1337h from usPop in eax
mov Difference, eax ;stores eax into Difference
mov edx,bigLoss ;stores -50000 into edx
mov eax,secondE ;store 0E00 into eax
mov ah,'A' ;store string A into ah
mov al,'X' ;store string X into al
mov ebx,secondE ;store 0E00 into ebx
mov bh,'B' ;store string B into bh
mov bl,'X' ;store string X into bl
call DumpRegs ;shows Registers
exit ;exits
main ENDP
END main
These two lines are your problem:
eax
is 32 bits, but bothmy1337Sk1LLz
andDifference
are 16 bits.There are two ways you might get around this:
Changing the size of
my1337Sk1LLz
andDifference
. Right now you have the types asWORD
andSWORD
, respectively. You can change those toDWORD
andSDWORD
to make them 32-bit.Zero-extending and truncating. You'll need another register. I'll use
edx
since you don't seem to be using it there. First, you'll need to sign-extendmy1337Sk1LLz
:Then you can do the subtraction:
Then you can store the low word of
eax
intoDifference
, discarding the high word: