Well no, that doesn't look quite right. I edited it to put "code tags" around your code. Just the word "code" in square brackets at the top of your code and "/code" in square brackets at the end. We like "code tags" here.
I'm a little confused by MS's description. Our source buffer is replaced by the value? What if that buffer isn't big enough? Seems like a problem! Pad it out to 32k, I suppose...? The destination buffer, they say, is optional. Push zero if we haven't got one, I guess? If we do have a destination buffer, does the source buffer still get replaced? They imply "yes". You may have to experiment to see what really happens. (I'm not running Windows and I'm not about to install it)
Here's my idea of how you might proceed...
; nasm -f win32 myfile.asm
; or
; nasm -f win64 myfile.asm
; and then?
; golink /entry start /console myfile.obj kernel32.dll
; or perhaps "kernel64.dll"?
; inform the linker about our entrypoint
global start
; inform the linker about APIs we'll use
extern ExitProcess ; always need this one!
extern ExpandEnvironmentStringsA
; we want to print results, I suppose...
extern GetStdHandle
extern WriteFile
BUFSIZ equ 8000h ; 32k - MS says this is the maximum
section .data
envname db "%appdata%", 0
padding times BUFSIZ db 0 ; may not need this?
; probably want some error messages, too...
section .bss
envbuf resb BUFSIZ
hstdout resd 1
byteswritten resd 1 ; place for WriteFile to put its result
section .text
start:
; get this out of the way first...
push -11 ; STDOUTPUTHANDLE
call GetStdHandle
mov [hstdout], eax
; now... to business (we hope)
push envname
push envbuf
push BUFSIZ
call ExpandEnvironmentStringsA
; if eax = 0 - something went wrong!
test eax, eax
jz fail
; if eax > BUFSIZ - buffer too small
; shouldn't happen here!
cmp eax, BUFSIZ
ja buf2small
; okay, eax should be length of "value" - print it
push 0
push byteswritten
push eax
push envbuf
push dword [hstdout]
call WriteFile
jmp exit
fail:
; print an error message
buf2small:
; print an error message
exit:
push 0
call ExitProcess
That's untested, and probably has multiple errors, but it may give you a better "framework" than what you've got. I left out your "\xxx.xx" after %appdata% - I doubt if that's going to work (you can try it). Let us know if it works, if you would. Good luck!
Best,
Frank