NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: HD1920.1 on May 07, 2014, 05:52:03 PM
-
Hello guys, I have just another problem. When I try to get the current cursor position with GetCursorPos and display the result with printf, only the x coordinate is shown. The y coordinate is zero. Where is my mistake? Code:
struc POINT
.x_coord: resq 1
.y_coord: resq 1
.limit:
endstruc
extern GetCursorPos
extern printf
extern exit
global Start
section .text
Start:
sub rsp, 0x28
mov rcx, Cursor
call GetCursorPos
mov rcx, format
mov rdx, [Cursor + POINT.x_coord]
mov r8, [Cursor + POINT.y_coord]
call printf
xor rcx, rcx
call exit
add rsp, 0x28
ret
section .data
Cursor: istruc POINT
iend
format: db "Cursor is at (%u, %u)", 10, 0
-
Look at the definition of POINT:
typedef struct tagPOINT {
LONG x;
LONG y;
} POINT, *PPOINT;
A LONG is 32 bits in size, a LONG LONG is 64 bits in size, you are declaring your structure improperly.
You create your structure with qwords:
struc POINT
.x_coord: resq 1
.y_coord: resq 1
.limit:
endstruc
Instead, it should be with DWORDS:
struc POINT
.x_coord: resd 1
.y_coord: resd 1
.limit:
endstruc
-
Thank you very much, now it works. I thought that I have to use qwords because I'm programing in 64 bits.
-
Thank you very much, now it works. I thought that I have to use qwords because I'm programing in 64 bits.
Nope. You'll find many structure definitions for 64-bit operating systems contain 32/16/8 bit sized members. BUT ( there's always a but ) YOU need to ensure the proper alignment of the data members when defining the structure itself.