The MASM Forum

Miscellaneous => 16 bit DOS Programming => Topic started by: n0noper on October 20, 2015, 01:04:38 AM

Title: HELP: I am a newbie - About call
Post by: n0noper on October 20, 2015, 01:04:38 AM
Hello, everyone.
I am a newbie, and my English is ... sorry, you got it!

code ↓
push 0
push offset szCap
push offset szText
push 0
call dword ptr [offset MessageBox]

disassembly:
...
push 0
push cs     ;Here, WHY???
call <Jmp.MessageBoxA>

;--------------------------
Why the "push cs"???
Thanks!!!
Title: Re: HELP: I am a newbie - About call
Post by: dedndave on October 20, 2015, 02:39:26 AM
that's in there because you didn't use the ASSUME directive
it thinks the only segment with the string in it is the code segment
if you tell it to assume, it won't insert that push
        ASSUME  DS:_DATA
(use the correct name for your data segment, of course)
Title: Re: HELP: I am a newbie - About call
Post by: dedndave on October 20, 2015, 02:43:38 AM
MessageBox is not supported under DOS

here's a 32-bit program that uses MessageBox
;###############################################################################################

        INCLUDE    \Masm32\Include\Masm32rt.inc

;###############################################################################################

        .DATA

szCaption db 'Hello',0
szMessage db 'World',0

;***********************************************************************************************

     ;   .DATA?

;###############################################################################################

        .CODE

;***********************************************************************************************

main    PROC

        INVOKE  MessageBox,NULL,offset szMessage,offset szCaption,MB_OK
        INVOKE  ExitProcess,0

main    ENDP

;###############################################################################################

        END     main


assemble it as a windows app if you don't want to see a console window
Title: Re: HELP: I am a newbie - About call
Post by: n0noper on October 21, 2015, 01:00:54 AM
ah... that's masm32 (32-bit) program. and the "assume ds:data" is necessary? follow ;
.data
...
.code

above, the ".data"  is declare a segment?or not?

Thanks for your reply. :biggrin:
Title: Re: HELP: I am a newbie - About call
Post by: dedndave on October 21, 2015, 01:20:42 AM
if you use the .DATA (etc) shortcuts, you don't have to use ASSUME - it's taken care of

but, if you use SEGMENT and ENDS to open and close segments, you may have to
along with that is the GROUP directive, that tells the assembler how to combine segments
normally, the data segments are all combined as DGROUP, and....
        ASSUME  DS:DGROUP

for 16-bit code, you can get DGROUP with @data (if you use the shortcuts)
        mov     ax,@data
        mov     ds,ax
Title: Re: HELP: I am a newbie - About call
Post by: n0noper on October 23, 2015, 02:43:47 AM
Thanks!!!