0

I found a cheat sheet on arguments in assembler:

  • rdi - first arg
  • rsi - second arg
  • rdx - third arg
  • rcx - four arg
  • r8-r15 - 5-12 arg
  • and then through the addresses

I wrote such code that calls a method from glfw to create a window, but I get an Assertion failed: title != NULL:

mov     rdi, 640
mov     rsi, 480
mov     rdx, title
mov     rcx, 0
mov     r8, 0
call    glfwCreateWindow

If necessary, here is the title variable:

    section .data
title db "Hi", 0

I asked ChatGPT how to solve this, and it gived me this code:

lea     rdx, [title]

But an error occurs during compilation: src\main.asm:(.text+0x20): relocation truncated to fit: IMAGE_REL_AMD64_ADDR32 against .data'`

I also tried to write:

lea     rdx, [rel title]

And I also get an Assertion error after that.

My os is: Windows x64 Assembly compiler: NASM x86-x64 elf64 Executable compiler: MinGW GCC 13.1.0

ladno
  • 1
  • 1
  • 2
  • 1
    Windows has a different calling convention that UNIX. Follow a tutorial that applies to the right operating system. – fuz Sep 01 '23 at 21:27
  • 3
    "I asked ChatGPT how to solve this": Word of advice: don't waste your time doing so. It's usually wrong. And by extension, there's no need to waste your time (and ours) by telling us what ChatGPT said. Showing research effort is always appreciated, but only when it's research that actually helps. – Nate Eldredge Sep 01 '23 at 21:30
  • The calling convention is a sub-part of a specification call the Application Binary Interface or ABI. An ABI is specific to both processor and operating system, so you have to consult the right documentation for your scenario. – Erik Eidt Sep 01 '23 at 21:51
  • thanks, now I will try to rewrite under windows. The main thing is that I'm going right – ladno Sep 01 '23 at 22:05
  • 1
    *r8-r15 - 5-12 arg* - nope, x86-64 SysV only passes up to 6 integer args in registers. The last two are R8 and R9. So your cheat sheet isn't even correct for the calling convention it's trying to document; it might have other mistakes so I wouldn't trust it. See also [Why does Windows64 use a different calling convention from all other OSes on x86-64?](https://stackoverflow.com/q/4429398) . (And re: LEA, yes, `[rel title]` is what you want. Or use `default rel` so `[title]` is `[rel title]`. [How to load address of function or label into register](https://stackoverflow.com/q/57212012)) – Peter Cordes Sep 01 '23 at 23:49

0 Answers0