News:

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

Main Menu

Yet another simple and basic 64 bit console program...

Started by felipe, May 27, 2018, 10:48:05 AM

Previous topic - Next topic

felipe

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:

mineiro

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.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

felipe

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:

Mikl__

¡Hola felipe!
Size of exe-file is 912 bytes, for create file I used link.exe and notepad.exe

felipe

 :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:

Mikl__

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

Windows 10 x64

stdin 0050h
stdout 0054h
stderr 0058h

One reason not to use hard coded numbers... :biggrin:

Mikl__

Hi, sinsi!
Thank you for the information! I supplemented it to the table

felipe

Mikl__ what i found more interesting are the linker options, do you know of a good reference of their options somewhere?  :idea:

Mikl__

¡Hola felipe!
via the command line 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'

felipe

 :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: