;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This file was created by Felipe at 2018-05-24.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
option casemap:none
include \masm32\include64\win64.inc
include \masm32\include64\kernel32.inc
includelib \masm32\lib64\kernel32.lib
.data
inbuff byte 256 dup(" ")
.data?
chrsread dword ?
.code
start proc
sub rsp,40 ; Shadow space + stack alignment.
call AllocConsole
mov rcx,STD_INPUT_HANDLE
call GetStdHandle
add rsp,40 ; Restores the stack.
push NULL ; Reserved.
sub rsp,40 ; Shadow space + stack alignment.
mov rcx,rax ; stdin.
lea rdx,inbuff
mov r8,256 ; Chars to read.
lea r9,chrsread
call ReadConsole
add rsp,8
call FreeConsole
xor rcx,rcx
call ExitProcess
add rsp,40 ; Restores the stack.
start endp
end
option casemap:none
include \masm32\include64\win64.inc
include \masm32\include64\kernel32.inc
includelib \masm32\lib64\kernel32.lib
.data
inbuff byte 256 dup(" ")
.data?
chrsread dword ?
.code
start proc
sub rsp,40 ; Shadow space + stack alignment + STACK VARIABLES SPACE FOR THE WHOLE PROCEDURE.
call AllocConsole
mov rcx,STD_INPUT_HANDLE
call GetStdHandle
;add rsp,40 ; WRONG
;push NULL ; Reserved. DON't DO PUSHES
;sub rsp,40 ; Shadow space + stack alignment. NO
mov qword ptr [RSP+32], NULL ; LIKE THIS
mov rcx,rax ; stdin.
lea rdx,inbuff
mov r8,256 ; Chars to read.
lea r9,chrsread
call ReadConsole
;add rsp,8 ; WRONG
call FreeConsole
xor rcx,rcx
call ExitProcess
;add rsp,40 ; WRONG. YOU WILL NOT COME HERE
start endp
end
option casemap:none
include \masm32\include64\win64.inc
include \masm32\include64\kernel32.inc
includelib \masm32\lib64\kernel32.lib
.data
inbuff byte 256 dup(" ")
.data?
chrsread dword ?
.code
start proc
sub rsp,40 ; Shadow space + stack alignment + STACK VARIABLES SPACE FOR THE WHOLE PROCEDURE. Ok i think i understand
; this. The extra parameters go "above" the shadow space.
call AllocConsole
mov rcx,STD_INPUT_HANDLE
call GetStdHandle
;add rsp,40 ; WRONG I did this based in "the caller is responsible of cleaning the stack". So i thought this must be done until
; call to a procedure that needs more stack space. Seems like in this simple program case windows clean all for us
; when the process is done?
;push NULL ; Reserved. DON't DO PUSHES. So we can only do pushes when we are using a stack frame?
;sub rsp,40 ; Shadow space + stack alignment. NO
mov qword ptr [RSP+32], NULL ; LIKE THIS.
mov rcx,rax ; stdin.
lea rdx,inbuff
mov r8,256 ; Chars to read.
lea r9,chrsread
call ReadConsole
;add rsp,8 ; WRONG
call FreeConsole
xor rcx,rcx
call ExitProcess
;add rsp,40 ; WRONG. YOU WILL NOT COME HERE. I know, but i thought it would be good coding practice (not too efficient
; really).
start endp
end
QuoteYou can do but you should not do, if a procedure calls 1000 times other procedures you will spend a lot of time reserving and clearing stack. So, all should be done in the beginning of the procedure reserving space for the procedure that will use the most stack and keeping in mind that all procedures will be called with the stack aligned.
;I did this based in "the caller is responsible of cleaning the stack". So i thought this must be done until
; call to a procedure that needs more stack space. Seems like in this simple program case windows clean all for us
; when the process is done?
QuoteThe problem with the pushes is that they change the alignment.
So we can only do pushes when we are using a stack frame?
|Windows |10 x64 | |Windows |Seven x64 | |Windows |XP 32-bits | |Windows | 98 | | UNIX |and DOS | |
hInput | |50h=101.0000b | | 3 =00.11b | | 3 | | 8 =0.1.0.00b | |0=00b - standart input device |
hOutput | |54h=101.0100b | | 7 =01.11b | | 7 | |0Ch=0.1.1.00b | |1=01b - standart output device |
hError | |58h=101.1000b | |0Bh=10.11b | |0Bh | |10h=1.0.0.00b | |2=10b - standart error device |
Quote from: Mikl__ on May 25, 2018, 03:48:52 PM
Maybe it is worth using the fixed values, but not to cause every time the GetStdHandle function?
Quote from: hutch-- on May 25, 2018, 01:05:24 PM
Now you know why I bothered to write an adjustable stackframe macro for procedure entry and exit.
Quote from: felipe on May 26, 2018, 04:15:23 AMYes sir, you take the point.
Maybe you are using this terms to denote 16 byte aligned and not 16 byte aligned? :idea:
Quote from: felipe on May 26, 2018, 04:15:23 AMnice attempt,but as all assembly demos usually exit with esc key I had to force it to Close,first run,before I read you checked for enter key insteadQuote from: Mikl__ on May 25, 2018, 03:48:52 PM
Maybe it is worth using the fixed values, but not to cause every time the GetStdHandle function?
Sounds ok, but maybe a little risky? :idea:Quote from: hutch-- on May 25, 2018, 01:05:24 PM
Now you know why I bothered to write an adjustable stackframe macro for procedure entry and exit.
I know is complicated now, even with a lot of help it will take me some time to handle this... :biggrin:
@mineiro: I liked your explanations. But i'm a little confused with how you are using the terms even and odd, there. I don't know how would be possible you get the rsp with an odd value, if is always decremented by 8 and it starts with a multiple of 8. Maybe you are using this terms to denote 16 byte aligned and not 16 byte aligned? :idea:
Thanks to all. :icon14:
Quote from: mineiro on May 26, 2018, 05:35:24 AM
Yes sir, you take the point.
Quote from: felipeSounds ok, but maybe a little risky?Hi, felipe!
Quote from: Mikl__ on May 25, 2018, 03:48:52 PMMaybe it is worth using the fixed values, but not to cause every time the GetStdHandle function?