Assembly: how to store data into variable -


i wrote simple program in assembly code (open console , loop input until user enters 5). want store each input in variable input (new input overwrite old). code:

format pe console entry start  include 'win32a.inc'  ;====================================== section '.data' data readable writeable ;======================================  input      db "", 0  ;======================================= section '.code' code readable executable ;=======================================  start:         ccall   [getchar] ; wait input         cmp     eax, "5"  ; compare input string         je      exit      ; if equal, exit         jne     start     ; if not, wait input again exit:         stdcall [exitprocess], 0  ;==================================== section '.idata' import data readable ;====================================  library kernel,'kernel32.dll',\         msvcrt,'msvcrt.dll'  import  kernel,\         exitprocess,'exitprocess'  import  msvcrt,\         printf,'printf',\         getchar,'_fgetchar' 

i tried to write

    ccall   [getchar] ; wait inout     cmp     eax, "5"  ; compare input string      mov     [input], eax ; line added      je      exit      ; if equal, exit     jne     start     ; if not, wait input again 

but got error operand sizes not match.. have searched error, didn't find useful.

the eax register 32-bit (4 byte) register, data type of input byte.

you need doubleword data store 32-bit value:

input      dd 0 

note: data in eax not string. when compare "5", value "5" converted 32-bit value, i.e. 0x00000005. declaring input zero-length string not made wrong type, small hold 4 byte value 1 byte large (the string terminator).


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -