News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Where i can get tutor for 'clear' asm

Started by Yola, July 28, 2011, 07:52:54 PM

Previous topic - Next topic

Yola

I mean without INVOKE. For example i want to print string into console without masm extension, i think its may be done with using of interrupt. I think i need to start from scratch to better understand assembler. Thanks.

dedndave

INTerrupts were for 16-bit code - more or less obsolete
if you want a 32-bit program you have to use the windows API, instead

still, it can be done without INVOKE

32-bit code, using INVOKE...
        INCLUDE \masm32\include\masm32rt.inc

        .DATA

Hello   db 'Hello World!'

        .DATA?

ByteCnt dd ?

        .CODE

_main   PROC

        INVOKE  GetStdHandle,STD_OUTPUT_HANDLE
        INVOKE  WriteFile,eax,offset Hello,sizeof Hello,offset ByteCnt,NULL
        INVOKE  ExitProcess,0

_main   ENDP

        END     _main


32-bit code, not using INVOKE...
        INCLUDE \masm32\include\masm32rt.inc

        .DATA

Hello   db 'Hello World!'

        .DATA?

ByteCnt dd ?

        .CODE

_main   PROC

        push    STD_OUTPUT_HANDLE
        CALL    GetStdHandle
        push    NULL
        push    offset ByteCnt
        push    sizeof Hello
        push    offset Hello
        push    eax
        CALL    WriteFile
        push    0
        CALL    ExitProcess

_main   ENDP

        END     _main


16-bit code, using INT...
        .MODEL  Small
        .STACK  4096

        .DATA

Hello   db      'Hello World!',24h

        .CODE
        ASSUME  DS:DGROUP

_main   PROC    FAR

        mov     ax,@DATA
        mov     ds,ax

        mov     dx,offset Hello
        mov     ah,9
        int     21h

        mov     ax,4C00h
        int     21h

_main   ENDP

        END     _main


NOTE: you must use a 16-bit linker for 16-bit programs and a 32-bit linker for 32-bit programs


dedndave

the first two generate the exact same program   :bg

raymond

Quotethe first two generate the exact same program

which he may think they are not working if he tries them because he may not be able to see the message being displayed.  :eek
I think ExitProcess would close the console window immediately unless some "wait" instruction is inserted.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

dedndave

hi Ray - good to see you
that is true, if you run the program by clicking on it in explorer   :P
however, if you run it from a console (command prompt), everything is fine
i was trying not to over-complicate the code by adding the inkey function
it is pretty simple in 16-bit, but the 32-bit version is a bit involved

jj2007

Quote from: dedndave on July 29, 2011, 03:06:37 AM
i was trying not to over-complicate the code by adding the inkey function
it is pretty simple in 16-bit, but the 32-bit version is a bit involved
call ret_key
(no invoke, so it is "clear")

dedndave

yah - i was trying to stick with API only   :P

hutch--

Yola,

Just be careful here, with Win32 assembler you re writing two different types of code, API code is high level code where algorithms can be written purely in assembler instructions. To write an application in Win32 you must be able to do both as you need the Windows API functions to interact with the operating system and this is from memory allocation to disk IO to hardware access and so on. There is no pure assembler applications in Win32 as you need operating system functions to make an application.

Most of the older programmers here learnt how to write lower level code where you use PUSH / CALL notation to call functions but it complicates your code and in OS defined areas you do a lot of work with low reliability for little gain by writing code that way. With high level API based code the "invoke" notation is much faster to develop, a lot more reliable with its argument checking and far more capable when writing complex code. Where you need real speed pure mnemonic code is the way to go but it is a different animal to calling Windows API functions.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php