News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Beginner question

Started by geimas5, October 18, 2014, 09:33:10 PM

Previous topic - Next topic

geimas5

Hello,

I am having a problem with calling the pow procedure, and I hope someone can help me out.

The code I have a problem with is below, and it fails with an "Access violation reading location 0x0000000000000000".

Thanks,


main PROC
push rbp
mov rbp, rsp
sub rsp, 0CCh
L0:
MOVSD XMM2, real1931608064
MOVD R10, XMM2
MOV [RBP -8], R10
MOVSD XMM2, real644874237
MOVD R10, XMM2
MOV [RBP -16], R10
MOV R8, [RBP -8]
MOVD XMM0, R8
MOV R8, [RBP -16]
MOVD XMM1, R8
CALL pow
MOVD R10, XMM0
MOV [RBP -24], R10
MOV RCX, [RBP -24]
CALL PrintDouble
L5:
MOV R10, 0
MOV [RBP -32], R10
MOV RAX, [RBP -32]
JMP mainexit
mainexit:
call exit
mov rsp, rbp
pop rbp
ret
main ENDP

Gunther

Hi geimas5,

could you please attach the entire code as a ZIP file? So we can see where's the problem. For now: Please remember the necessary shadow space and the 16-bit aligned stack for the function calls. You can find appropriate examples here. Please use the archive Win64U1.zip. It contains examples for MASM/JWasm and NASM/YAS. I hope that helps. And welcome to the forum.

Gunther
You have to know the facts before you can distort them.

geimas5

Thank you!

With that example I was able to correct my code.

Gunther

Quote from: geimas5 on October 19, 2014, 04:40:06 AM
Thank you!

With that example I was able to correct my code.

You're welome. Don't hesitate to post further questions.

Gunther
You have to know the facts before you can distort them.

geimas5

Looks like I was a little quick in assuming I had fixed the problem.

I have attached the file that fails. I think I might have misunderstood what 16-bit alignment means.

Gunther

Hi geimas5,

I've checked your source code. It is not very structured and hard to read. I think you should load it into an editor for a better formatting. Furthermore, the 16-bit alignment must be safe for every function call:

; print_Cstring
; Purpose:         Print a C string to STDOUT via libc.
; Input:           rdx -> string address
; Output:          String on STDOUT.
print_Cstring proc
        lea        rcx, str_format       ; rcx -> format string
        sub        rsp, 40
        call       printf                ; call libc
        add        rsp, 40
        ret
print_Cstring endp


48 is divisible by 16. So you have to sub 48 from the current RSP. But the CALL needs 8 byte for themselves. Therefore the subtraction of 40, after that the function call and after that the addition of 40. That's the way to go. I hope that helps.

Gunther
You have to know the facts before you can distort them.

geimas5

Thank you Gunther. I managed to get it working again now.

I am sorry about the bad structure of the code. I am currently trying to make a compiler and this is the output from the compiler for one of my test cases. But I will clean it up before posting if I get stuck again.

Gunther

Quote from: geimas5 on October 29, 2014, 02:28:28 AM
Thank you Gunther. I managed to get it working again now.

I am sorry about the bad structure of the code. I am currently trying to make a compiler and this is the output from the compiler for one of my test cases. But I will clean it up before posting if I get stuck again.

Go forward.  :t

Gunther
You have to know the facts before you can distort them.