Author Topic: New member and super newbie question  (Read 140 times)

MrSwede

  • Regular Member
  • *
  • Posts: 2
New member and super newbie question
« on: July 02, 2017, 09:52:22 PM »
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.

Code: [Select]
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:

Code: [Select]
.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?

MrSwede

  • Regular Member
  • *
  • Posts: 2
Re: New member and super newbie question
« Reply #1 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.

RuiLoureiro

  • Member
  • ****
  • Posts: 671
Re: New member and super newbie question
« Reply #2 on: July 02, 2017, 10:26:34 PM »
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

jj2007

  • Member
  • *****
  • Posts: 7542
  • Assembler is fun ;-)
    • MasmBasic
Re: New member and super newbie question
« Reply #3 on: July 02, 2017, 11:43:24 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:

felipe

  • Member
  • ***
  • Posts: 279
  • I love assembly language programming.
Re: New member and super newbie question
« Reply #4 on: July 03, 2017, 02:24:26 AM »
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:

Felipe.