So I am a complete newbie to this. I am a junior java developer but I have never even written a line of c code, less so assembler but I always wanted to learn more about low level programming so here I am.
While I am making my obligatory new member post I might as well throw in a question that is probably really stupid. I have installed masm and set up a simple bat to build my code following a guide I found on youtube on how to do it.
set projectName=helloworld
\masm32\bin\ml /c /Zd /coff %projectName%.asm
\masm32\bin\Link /SUBSYSTEM:CONSOLE %projectName%.obj
%projectName%.exe
I then built a simple hello world program and verified that it worked. So I figured great, now I'll dive into instruction documentation and just play around and try to understand things but I instantly ran into a problem.
I am tinkering with the mov instruction and I wanted to move the contents of a register into a variable and I looked at examples of how to use mov but I get an error when I try to go from register to memory. Here is my code:
.386
.model flat, stdcall
option casemap :none
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
ExitProcess proto,dwExitCode:dword
.data
register db 0
.code
main proc
mov eax, 52
mov register, 52
mov register, eax
invoke StdOut, addr register
call ExitProcess
main endp
end main
It looks to me like I am doing exactly what is listed in examples of MOV, but I get this error:
error A2070: invalid instruction operands on the line where I try to move the contents of eax into my register variable. What am I missing here?
Well I answered my own question already, sort of. I realized the problem was the "db" where I declared register, if I change that to dword it worked fine. The phrasing of the error message made me look in the wrong places.
hello
It should work
.data
register8 db 0 ; <<<<<< byte
register16 dw 0 ; <<<<<< word
register32 dd 0 ; <<<<<< dword
.code
mov register8, 52
mov eax, 52
mov register8, al ; <<<< move byte
mov register16, ax ; <<<<move word
mov register32, eax ; <<<< move dword
Quote from: MrSwede on July 02, 2017, 10:02:04 PM
Well I answered my own question already, sort of. I realized the problem was the "db" where I declared register, if I change that to dword it worked fine. The phrasing of the error message made me look in the wrong places.
Your progress is fast - welcome to the forum :icon14:
Quote from: MrSwede on July 02, 2017, 09:52:22 PM
While I am making my obligatory new member post I might as well throw in a question that is probably really stupid.
Don't worry man, there are no stupid questions in the campus. Welcome to the forum! :icon14: