Retrieving the operating system version by reading data from kernel32 :
include GetOSvers64.inc
.data
kernel32 db 'kernel32.dll',0
str1 db 'Major Operating System Version = %u',13,10
db 'Minor Operating System Version = %u',13,10,0
.data?
buffer db 128 dup(?)
.code
start PROC PARMAREA=4*QWORD
invoke GetModuleHandle,ADDR kernel32
test rax,rax
jz @f
xor rcx,rcx
mov ecx,IMAGE_DOS_HEADER.e_lfanew[rax]
add rax,rcx
movzx r8,IMAGE_NT_HEADERS.OptionalHeader.MajorOperatingSystemVersion[rax]
movzx r9,IMAGE_NT_HEADERS.OptionalHeader.MinorOperatingSystemVersion[rax]
invoke wsprintf,ADDR buffer,ADDR str1,r8,r9
invoke StdOut,ADDR buffer
@@:
invoke ExitProcess,0
start ENDP
StdOut PROC uses r14 r15 string:QWORD PARMAREA=5*QWORD
; Function from the Masm64 package
; rcx = text address
LOCAL bwrt:QWORD
mov r14,rcx ; store address in r14
mov rax,r14
sub rax,1
@@:
add rax,1
cmp BYTE PTR [rax],0 ; get the text length
jne @B
sub rax,r14 ; sub original address from RAX
mov r15,rax ; save string length into r15
invoke GetStdHandle,STD_OUTPUT_HANDLE
mov rcx,rax
lea r9,bwrt
xor r10,r10
invoke WriteFile,rcx,r14,r15,r9,r10
mov rax,bwrt ; return value is bytes written
ret
StdOut ENDP
END start