The MASM Forum

General => The Workshop => Topic started by: felipe on May 27, 2018, 10:48:05 AM

Title: Yet another simple and basic 64 bit console program...
Post by: felipe on May 27, 2018, 10:48:05 AM
I'm very pleased, i have understand what i have read so far...(i think so  ;)). Here is the source code of this little "demo":


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This file was started by Felipe at 2018-05-26.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;----------------------------------------------
option  casemap:none
include \masm32\include64\win64.inc
include \masm32\include64\kernel32.inc
includelib  \masm32\lib64\kernel32.lib
;----------------------------------------------

_data SEGMENT PARA 'DATA'
the_msg  byte  "HEY, THIS I VERY COOL!",0ah,0ah,0dh,\
               "PRESS ENTER TO FINISH THE PROGRAM",0
inbuff   byte  256 dup(" ")
chrswrit dword ?
chrsread dword ?
_data ENDS

_text SEGMENT PARA 'CODE'
start proc
      sub   rsp,28h         

      call  AllocConsole     

      mov   rcx,STD_OUTPUT_HANDLE
      call  GetStdHandle

      mov   r15,rax           ; stdout.

      mov   rcx,STD_INPUT_HANDLE
      call  GetStdHandle

      mov   r14,rax           ; stdin.

      mov   rcx,r15           ; stdout.
      lea   rdx,the_msg
      mov   r8,sizeof the_msg
      lea   r9,chrswrit 
      mov   dword ptr[rsp+20h],NULL
      call  WriteConsole

      mov   rcx,r14           ; stdin.
      lea   rdx,inbuff
      mov   r8,sizeof inbuff
      lea   r9,chrsread
      mov   dword ptr[rsp+20h],NULL
      call  ReadConsole

      call  FreeConsole
     
      xor   rcx,rcx
      call  ExitProcess
start endp
_text ENDS
      END


The .exe is attached.
Hutch is great be able to see all that 64 bit source code in the m64lib. Thank you very much!
Keep writing more... :redface:

:biggrin:  :greensml:

Btw, as regard to the SEGMENT directive: i thought since i can't use a label as the entry point (as this= "start:"), why not to use the "old format" from the masm 5.0?  :badgrin:
Title: Re: Yet another simple and basic 64 bit console program...
Post by: mineiro on May 27, 2018, 11:39:31 AM
Quote from: felipe on May 27, 2018, 10:48:05 AM
i thought since i can't use a label as the entry point (as this= "start:")
Hello;
Try one of these, if you are linking to console or graphical, insert one of below.
ALIAS <mainCRTStartup>=<start>         ;;console mode CUI
ALIAS <WinMainCRTStartup>=<start>      ;;graphical mode GUI

Now try 'start:' or another name instead of using procedure; you can also forget about "/ENTRY:some_name" while linking.
Title: Re: Yet another simple and basic 64 bit console program...
Post by: felipe on May 27, 2018, 01:27:31 PM
Nice tip mineiro, thanks.  :icon14:

A different topic: I want to stay with link.exe. I don't have nothing against polink.exe, but i don't like the optimization that it does. I'm not saying that is bad, is just i don't like to use that feature. What do you think? Btw, changing in qeditor (from the masm64 sdk package) the build file to use link.exe instead of polink.exe is easy.  :icon14:
Title: Re: Yet another simple and basic 64 bit console program...
Post by: Mikl__ on May 27, 2018, 04:24:51 PM
¡Hola felipe!
Size of exe-file is 912 bytes, for create file I used link.exe and notepad.exe (https://wasm.in/styles/smiles_s/mosking.gif)
Title: Re: Yet another simple and basic 64 bit console program...
Post by: felipe on May 27, 2018, 04:52:58 PM
 :biggrin: That's good Mikl__. Using the equates for the stdin and stdout (not calling GetStdHandle twice!) and maybe the and instruction was shorter than the mov?...Nice little demo. You killed me with this  :bgrin:.

:icon14: Now i go to sleep see you all tomorrow (maybe?...)  :idea:
Title: Re: Yet another simple and basic 64 bit console program...
Post by: Mikl__ on May 27, 2018, 05:17:17 PM
felipe,
carefully consider the bat-file, it automatically allows you to create gui-/console-/dll-files. The bat-file analyzes the first line of the asm-file and creates the required gui-/console-/dll-file with or without resources, depending on the contents of the first line of the asm-file.
; CONSOLE #
include win64a.inc
stdout equ 7
stdin  equ 3
.code
WinMain proc
...
Title: Re: Yet another simple and basic 64 bit console program...
Post by: sinsi on May 27, 2018, 06:17:13 PM
Windows 10 x64

stdin 0050h
stdout 0054h
stderr 0058h

One reason not to use hard coded numbers... :biggrin:
Title: Re: Yet another simple and basic 64 bit console program...
Post by: Mikl__ on May 27, 2018, 07:29:10 PM
Hi, sinsi!
Thank you for the information! I supplemented it to the table (http://masm32.com/board/index.php?topic=7167.msg77468#msg77468)
Title: Re: Yet another simple and basic 64 bit console program...
Post by: felipe on May 28, 2018, 04:24:18 AM
Mikl__ what i found more interesting are the linker options, do you know of a good reference of their options somewhere?  :idea:
Title: Re: Yet another simple and basic 64 bit console program...
Post by: Mikl__ on May 28, 2018, 09:04:50 AM
¡Hola felipe!
via the command line link.exe /link /? > 1.txt
   (https://wasm.in/styles/smiles_s/mosking.gif)
Title: Re: Yet another simple and basic 64 bit console program...
Post by: felipe on May 28, 2018, 09:12:53 AM
 :biggrin: I have saw this before but it didn't seem to be much explanatory...If you know a different kind of documentation about link, please let me know.  :idea: