Magic Instruction prior to c function call
Posted: Sun Sep 03, 2023 1:35 pm
Hello,
After assembling and linking the listing4-8 (page 202, "the art of 64 Assembly", vol1), i encounter an issue: the .exe file does not behave as expected.
However, if i change the "magic instructions" in the asmMain procedure code as follow:
after assembling and linking the file with this version of listing4-8 asmMain, it prints correctly the output:
"Calling Listing 4-8:
aString: maxLen: 20, len: 20, string data:'Initial String Data'
Listing 4-8 terminated"
With the book version of asmMain, the output printed is only:
"Calling Listing 4-8:"
My machine is a Windows11 x64 bits laptop, I don't know the reason of this unexpected behaviour, and i encountered it on several listings examples of this book. I would be glad to discuss this problem (I surely missed something which could explain this, if it's the case i apologize for the inconvenience)
thanks in advance,
Olivier
After assembling and linking the listing4-8 (page 202, "the art of 64 Assembly", vol1), i encounter an issue: the .exe file does not behave as expected.
However, if i change the "magic instructions" in the asmMain procedure code as follow:
Code: Select all
asmMain proc
sub rsp, 56; instead of "sub rsp, 48" as in the book
; displays the fields of the string descriptor
lea rcx, fmtStr
mov edx, aString.maxLen ; zero extends!
mov r8d, aString.len; zero extends
mov r9, aString.strPtr
call printf
add rsp, 56; instead of "add rsp, 48" as in the book
ret; returns to caller
asmMain endp
"Calling Listing 4-8:
aString: maxLen: 20, len: 20, string data:'Initial String Data'
Listing 4-8 terminated"
With the book version of asmMain, the output printed is only:
"Calling Listing 4-8:"
My machine is a Windows11 x64 bits laptop, I don't know the reason of this unexpected behaviour, and i encountered it on several listings examples of this book. I would be glad to discuss this problem (I surely missed something which could explain this, if it's the case i apologize for the inconvenience)
thanks in advance,
Olivier