Author Topic: Yet another simple and basic 64 bit console program...  (Read 182 times)

felipe

  • Member
  • ****
  • Posts: 824
  • Eagles are just great!
Yet another simple and basic 64 bit console program...
« 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":

Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 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:
Felipe.

mineiro

  • Member
  • ***
  • Posts: 391
Re: Yet another simple and basic 64 bit console program...
« Reply #1 on: May 27, 2018, 11:39:31 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.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

felipe

  • Member
  • ****
  • Posts: 824
  • Eagles are just great!
Re: Yet another simple and basic 64 bit console program...
« Reply #2 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:
Felipe.

Mikl__

  • Member
  • ****
  • Posts: 612
Re: Yet another simple and basic 64 bit console program...
« Reply #3 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

felipe

  • Member
  • ****
  • Posts: 824
  • Eagles are just great!
Re: Yet another simple and basic 64 bit console program...
« Reply #4 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:
Felipe.

Mikl__

  • Member
  • ****
  • Posts: 612
Re: Yet another simple and basic 64 bit console program...
« Reply #5 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
...

sinsi

  • Member
  • *****
  • Posts: 1050
Re: Yet another simple and basic 64 bit console program...
« Reply #6 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:
I can walk on water but stagger on beer.

Mikl__

  • Member
  • ****
  • Posts: 612
Re: Yet another simple and basic 64 bit console program...
« Reply #7 on: May 27, 2018, 07:29:10 PM »
Hi, sinsi!
Thank you for the information! I supplemented it to the table

felipe

  • Member
  • ****
  • Posts: 824
  • Eagles are just great!
Re: Yet another simple and basic 64 bit console program...
« Reply #8 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:
Felipe.

Mikl__

  • Member
  • ****
  • Posts: 612
Re: Yet another simple and basic 64 bit console program...
« Reply #9 on: May 28, 2018, 09:04:50 AM »
¡Hola felipe!
via the command line
Code: [Select]
link.exe /link /? > 1.txt
   
  • For help on Linker, you will type `link /link' or `link'
  • For help on Library Manager, you will type `link /lib' or `lib'
  • For help on Dumper, you will type `link /dump' or `dumpbin'
  • For help on Editor, you will type `link /edit' or `editbin'
  • For help on CvtCIL, you will type `link /cvtcil'
  • For help on PushThunkObj Generator, you will type `link /pushthunkobj'
« Last Edit: May 28, 2018, 10:42:04 PM by Mikl__ »

felipe

  • Member
  • ****
  • Posts: 824
  • Eagles are just great!
Re: Yet another simple and basic 64 bit console program...
« Reply #10 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:
Felipe.