Hi
My name is Giorgio , I'm a first-year student(high School).
nice to "meet" you
I'm learning assembly and I'm trying to figure out how to make subroutines. I've modified the hello world example.
but I don't understand this push
Push 0, Addr RCKEEP ;RCKEEP receives output from API
Data Section
;
RCKEEP DD 0 ;temporary place to keep things
toConsole DD 0 ; HANDLE WINAPI GetStdHandle(
; _In_ DWORD nStdHandle
; )
STD_OUTPUT_HANDLE Equ -11D ; 11 The standard output device.Initially, this is the active console screen buffer.
Code Section
;
START:
/* Initialize the console */
Push STD_OUTPUT_HANDLE ;STD_OUTPUT_HANDLE
Call GetStdHandle ;get, in eax, handle to active screen buffer
Mov [toConsole], Eax
Call HELLO1
Call HELLO2
Call EXIT
HELLO1:
Push 0, Addr RCKEEP ;RCKEEP receives output from API
Push 24D, 'Hello World (from GoAsm)' ;24=length of string
Push [toConsole] ;handle to active screen buffer
CALL WriteFile
Ret
HELLO2:
Push 0, Addr RCKEEP ;RCKEEP receives output from API
Push 24D, 'Hello World again (from GoAsm)' ;24=length of string
Push [toConsole] ;handle to active screen buffer
CALL WriteFile
Ret
EXIT:
Xor Eax, Eax ;return zero
Ret
What it means when it says "receives output" ? Why Does it "receive"?
Thanks friends
EDIT: updated question
Hi Giorgio,
The 4th parameter of the WriteFile function (https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-writefile) is a memory address where the function will put the number of actually written bytes. If you don't need it, you can push 0 instead of the address.
Thanks I reread the goAsm manual and the winapi Doc.
but I still have a bug to be solved
Data Section
;
RCKEEP DD 0 ;temporary place to keep things
toConsole DD 0 ; HANDLE WINAPI GetStdHandle(
; _In_ DWORD nStdHandle
; )
String1 DB 'Hello friend', 0
String2 DB 'Hello FRIEND', 0
STD_OUTPUT_HANDLE Equ -11D ; 11 The standard output device.Initially, this is the active console screen buffer.
Code Section
;
START:
/* Initialize the console */
Push STD_OUTPUT_HANDLE ;STD_OUTPUT_HANDLE
Call GetStdHandle ;get, in eax, handle to active screen buffer
Mov [toConsole], Eax
Call HELLO1
Call HELLO2
Call EXIT
HELLO1:
Push 0, Addr RCKEEP ;RCKEEP receives output from API
Mov Esi, Addr String1 ;gets pointer to
Push 13D, Esi ;13=length of string1
Push [toConsole] ;handle to active screen buffer
CALL WriteFile
Ret
HELLO2:
Push 0, Addr RCKEEP ;RCKEEP receives output from API
Mov Esi, Addr String2 ;gets pointer to
Push 13D, Esi ;13=length of string2
Push [toConsole] ;handle to active screen buffer
CALL WriteFile
Ret
EXIT:
Xor Eax, Eax ;return zero
Ret
It repeats 3 time "hello friend" .It should prints only two messages
maybe the EXIT code is the issue
You need one more 'ret' — at the end of the START routine. Without it, execution goes through HELLO1, up to its 'ret'.
Call HELLO1
Call HELLO2
Call EXIT
ret ; <—— here.