News:

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

Main Menu

Can Anyone Help Me Bit Confused

Started by ayao, March 11, 2014, 09:55:40 PM

Previous topic - Next topic

ayao

Can anyone help me im kinda stuck or don't know how to do im trying to make 3D star or any shape but professor wants me to use print chr$ which i have no clue what im doing and i don't know how to or where to put coordinate for X,Y on print chr$. And my professor does not want us to use invoke location. or any invoke statement.



.386
.model flat, stdcall
option casemap :none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib


   


.data?

     ; JUST TRYING HARD TO UNDERSTAND AND LEARN  HOW TO CONVERT C++ CODE INTO MASM32 
    a dd ?
    b dd ?
    star dd ?

; Right here is just trial and error and i don't know much and wanted to do 3D diamond or any 3d Shape if could have any sample code. that i could read and understand. That would be a great Help
;TOP
.if a <= 7
    mov a, 1
    cmp a, 7
    inc a, 2

   
.if star <= a
     mov star, 1
     inc star

;BOTTOM
  .if a <= 5
      .if a >= 0
       mov a,-2

    .if b = 10 - a / 2
        .if b > 0
        inc b

.if star <= a
mov star,1
  inc star
   
       
print chr$("*"), ; I DONT KNOW HOW TO USE PRINT CHR$

.code
start:
         


; this the code i follow for my masm32 i hope i did it right or not

int a, b, star;   //integor declaration

//starting point of upper diamond shape loop
for (a = 1; a <=7; a+=2)
{

for (b = (10 - a) /2; b >0; b--)
{
printf (" ");
}
for (star = 1;  star <= a;  star++)
{
printf ("*");
}
printf ("\n");
}
//ending point of upper diamond shape loop



//staring point of bottom diamond shape loop
for (a = 5;  a >= 0;  a -= 2)
{

for (b = (10 - a) /2; b > 0; b--)
{
printf (" ");
}
for (star = 1;  star <= a;  star++)
{
printf("*");
}
printf ("\n");
}
getch ();
}
//ending point of bottom diamond shape loop





qWord

A simple translation of your C code would be:
include \masm32\include\masm32rt.inc
.code
diamond proc dim:SDWORD

    ; use nonvolatile registers with typecast
    a       EQU SDWORD ptr esi
    b       EQU SDWORD ptr edi
    star    EQU SDWORD ptr ebx
   
    .if !(dim & 1)
        add dim,1  ; make odd
    .endif
   
    mov a,1
    .while a <= dim
        mov eax,dim
        add eax,2
        sub eax,a
        shr eax,1
        mov b,eax
        .while b > 0
            print chr$(" ")
            sub b,1
        .endw
        mov star,1
        .while star <= a
            print chr$("*")
            add star,1
        .endw
        print chr$(13,10)
        add a,2
    .endw

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

    ret
   
diamond endp

main proc

    push 7
    call diamond
   
    push 20
    call diamond

    inkey
    exit
main endp
end main

Remarks that the nonvolatile registers ESI, EBX and EDI are used as variables. These registers are not modified by API functions (in contrast to EAX,ECX and EDX).
Now it's your turn...
MREAL macros - when you need floating point arithmetic while assembling!

ayao

escuse me sir  qWord is this how you put location  in print chr$(13,10) ?

dedndave

"print" and "chr$" are macros, part of the masm32 package
if your instructor doesn't want you to use INVOKE, he's probably not going to want you to use those pre-written macros, either

chr$ doesn't use INVOKE, as far as i know
but, print does

you could write your own macros, and include them as part of your program
to see how those macros are written, you can look at the file masm32\macros\macros.asm

INVOKE can be replaced with PUSH/CALL
for example, if you see code like this
    INVOKE  Function,Arg1,Arg2,Arg3
you can re-write it like this
    push    Arg3
    push    Arg2
    push    Arg1
    call    Function

for functions that use the "StdCall" convention, you do not have to POP the values off the stack
the function removes them for you, at exit

ayao

how do i use  go to x,y i cant use invoke locate

dedndave

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

in ASM, that would be
    INVOKE  SetConsoleCursorPosition,hStdOut,dwCoord

well - something like that   :biggrin:
a COORD structure is 2 WORD's
so, you can use a DWORD with the x position in the low word and y position in the hight word
COORD STRUCT
  x  WORD      ?
  y  WORD      ?
COORD ENDS


to get the standard output handle, you can use GetStdHandle
http://msdn.microsoft.com/en-us/library/windows/desktop/ms683231%28v=vs.85%29.aspx
    INVOKE  GetStdHandle,STD_OUTPUT_HANDLE
it returns the standard output handle in EAX

now, let's do it without using INVOKE

    push    STD_OUTPUT_HANDLE   ;STD_OUTPUT_HANDLE = -11
    call    GetStdHandle        ;EAX = standard output handle
    push    150010h             ;X = 10h = 16, Y = 15h = 21
    push    eax
    call    SetConsoleCursorPosition

ayao

excuse sir dedndave was wondering push    150010h  about this is there a chart of some sort to know which locate on x and y ? for example i would like to it to be at the center how do i know im putting the right coordinate

dedndave

generally, the console window is set up with 80 columns, and 25 rows
the columns would then be numbered 0 to 79 (0 to 4Fh)
and the rows would be numbered 0 to 24 (0 to 18h)

however, the user can alter the console window dimensions
so, the best way is to use GetConsoleScreenBufferInfo

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 for you
and, you can get the dimensions from that structure

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

MichaelW

Under Windows XP, at least by default, the screen buffer is 300 lines.
Well Microsoft, here's another nice mess you've gotten us into.

dedndave

the buffer is default 300
but the window is default 25 :)