News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Need Help on While Loop - Invalid Operand

Started by Gimena, April 01, 2014, 04:23:12 PM

Previous topic - Next topic

Gimena

Hello im trying to make a simple menu and i got all my code working except for one the triangle i keep getting this invalid instruction operand and i haven't finish my triangle 3D shape. i was wondering how do i do 3D shape and how do i insert code on GOTO X,Y ? i been alot of problems on my 3D shape.

.386
.model flat, stdcall
option casemap :none
.stack 100h


include \masm32\include\windows.inc
include \masm32\macros\macros.asm
include \masm32\include\msvcrt.inc

include \masm32\include\masm32.inc
include \masm32\include\gdi32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc


includelib \masm32\lib\msvcrt.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.code

start:


main proc

Local choice: sdword
INVOKE ClearScreen
print chr$("                         ----------------------"),0Ah
print chr$("                    ----------------------------------"),0Ah
print chr$("                            ENTER YOUR CHOICE:"),0Ah
print chr$("                   -----------------------------------------"),0Ah
print chr$("                           1.Triangle"),0Ah
print chr$("                           2.Calculator"),0Ah
print chr$("                           3.Prime Numbers"),0Ah
print chr$("                           4.ODD AND EVEN"),0Ah,0Ah
print chr$("                           5.EXIT"),0Ah,0Ah
mov choice, sval(input("                   Enter Here: "))
print chr$(" "),0ah,0ah


switch01:
cmp choice,1
          je case1
          cmp choice,2
          je case2
          cmp choice,3
          je case3
          cmp choice,3
           je case3

        cmp choice,4
            je case4
           
         cmp choice,5
        je case5
           
      jmp endswitch01
       

case1:
   
     Call triangle
     jmp endswitch01

case2:
   
     Call calcu
     jmp endswitch01
case3:
    Call prime
     jmp endswitch01

case4:
    Call odd
 
     jmp endswitch01

case5:
       Call xit
   
   endswitch01:
   ret
main endp ;END OF MAIN PROCEDURE




triangle proc
Local choice: sdword
Local a: sdword
Local b: sdword
Local tri: sdword
Local triangle1:sdword

   
 
       mov a,1
      .while a <= tri
         mov eax,tri
         add eax,2
         sub eax,a
         shr eax,1
         mov b,eax
.while b > 0
    print chr$(" ")
            sub b,1
.endw
mov triangle1,1
.while triangle1 <= a
    print chr$("*")
            add triangle1,1
        .endw
print chr$(13,10)
        add a,2
    .endw




mov choice, sval(input("            Press Enter to continue... "))


         
    Call main
   
ret

triangle endp



calcu proc
Local choice: sdword

mov choice, sval(input("            Press Enter to continue... "))


         
    Call main
   
ret

calcu endp

prime proc
Local choice: sdword




mov choice, sval(input("            Press Enter to continue... "))


         
    Call main
   
ret


prime endp

odd proc
Local choice: sdword

mov choice, sval(input("            Press Enter to continue... "))


         
    Call main
   
ret



odd endp




xit proc
exit
xit endp
;exittttttttt
trap proc
;INVOKE ClearScreen
   print chr$("         Please Enter the options  correctly!!!")
   
      Call main
      ret
trap endp
   
end start






jj2007

You need registers to compare against a memory operand ( = a variable).
You can use an equate:

triangle proc
...
  push esi   ; preserve non volatile register
  push edi
  a equ <esi>
  triangle1 equ <edi>
  .While a <= tri
...
  .While triangle1 <= a
...
  pop edi
  pop esi
  ret
triangle endp

Gimena

Is there a function like  C++ GOTO X,Y  in MASM i been trying to figure how to move my triangle in center and give it like 3D effect 

jj2007

#3
Quote from: Gimena on April 01, 2014, 11:14:51 PM
Is there a function like  C++ GOTO X,Y  in MASM

There is Locate(x, y). Otherwise, check SetCursorPos SetConsoleCursorPosition (thanks, Dave :t).

dedndave

#4
SetConsoleCursorPosition
http://msdn.microsoft.com/en-us/library/windows/desktop/ms686025%28v=vs.85%29.aspx

notice that the function is passed a COORD structure
for 32-bit masm, it is easier to work with dwords
so, the function is prototyped with 2 dwords in place of COORD in masm32 windows.inc
in the other library, it is prototyped with a COORD

    INVOKE  SetConsoleCursorPosition,hStdOut,x,y

Gimena

Excuse me sir dedndave how do i  add SetConsoleCursorPosition whenever i add it give me alot of errors and im still got alot to learn about masm32

dedndave

in your original post, you are missing kernel32.inc
but, the whole thing is easier if you just use masm32rt.inc

        INCLUDE     \masm32\include\masm32rt.inc

        .DATA?

hStdOut HANDLE ?

        .CODE

start:
        INVOKE  GetStdHandle,STD_OUTPUT_HANDLE
        mov     hStdOut,eax
        INVOKE  SetConsoleCursorPosition,eax,0A0027h       ;X=39, Y=10
        print   chr$('X')
        INVOKE  SetConsoleCursorPosition,hStdOut,0C0000h   ;X=0, Y=12
        inkey
        exit

        END     start

dedndave

my mistake
i corrected the above code
a COORD structure is 2 words, not 2 dwords
so, you pass the X coordinate in the low word, and the Y coordinate in the high word

Gimena

Sir dedndave when i tried using the code above i just don't know if its in center when i tried to compile it i just on left side on screen. i just wanna ask is possible to use
invoke locate ? i been reading alot of help code lately and kinda found this invoke locate.

dedndave

locate is a function in the masm32 library
as you can see, it calls SetConsoleCursorPosition
locate proc x:DWORD,y:DWORD

    LOCAL hOutPut  :DWORD
    LOCAL xyVar    :DWORD

    invoke GetStdHandle,STD_OUTPUT_HANDLE
    mov hOutPut, eax

  ; -----------------------------------
  ; make both co-ordinates into a DWORD
  ; -----------------------------------
    mov  ecx, x
    mov  eax, y
    shl  eax, 16
    mov  ax, cx

    invoke SetConsoleCursorPosition,hOutPut,eax

    ret

locate endp

dedndave

in my example code above, i placed the coordinates into the correct word locations (constants)
        INVOKE  SetConsoleCursorPosition,eax,0A0027h       ;X=39, Y=10
        INVOKE  SetConsoleCursorPosition,hStdOut,0C0000h   ;X=0, Y=12


if you want to try a loop, something like this.....
        INCLUDE     \masm32\include\masm32rt.inc

        .DATA?

hStdOut HANDLE ?

        .CODE

start:
        INVOKE  GetStdHandle,STD_OUTPUT_HANDLE
        mov     hStdOut,eax

        mov     esi,4Eh                                   ;start at X=78, Y=0
        mov     edi,20                                    ;loop count = 20

loop00:
        INVOKE  SetConsoleCursorPosition,hStdOut,esi
        print   chr$('X')
        add     esi,0FFFEh                                ;add 1 to Y (10000h) and subtract 2 from X, 10000h-2 = 0FFFEh
        dec     edi
        jnz     loop00

        INVOKE  SetConsoleCursorPosition,hStdOut,180000h  ;X=0, Y=24
        inkey
        exit

        END     start

Gunther

You have to know the facts before you can distort them.

Gimena

QuoteSir dedndave when i tried using the code above i just don't know if its in center when i tried to compile it i just on left side on screen. i just wanna ask is possible to use
invoke locate ? i been reading alot of help code lately and kinda found this invoke locate.
Sorry my bad i lost track i was trying to figure out it.

i mean how do i insert it on my print when insert it all my code go to center?  i just want the triangle to be on the center. i mean wear should i put it the code?

dedndave

well, the default size of a console window is 80x25
the X and Y location values are 0-based, so 0 to 79 and 0 to 24 are the values to get there

the user can customize the console window
so, it can be other dimensions, although it's almost always 80 columns wide
if you need to get the dimensions, you can use the GetConsoleScreenBufferInfo function

http://msdn.microsoft.com/en-us/library/windows/desktop/ms683171%28v=vs.85%29.aspx

that function will fill a CONSOLE_SCREEN_BUFFER_INFO structure that has values you want

http://msdn.microsoft.com/en-us/library/windows/desktop/ms682093%28v=vs.85%29.aspx