I am trying to mexify a C program which links with an object assembled with nasm which uses the sys_newstat system call to get the size of a file. The program returns the correct file size when compiled with gcc, but only returns a file size of 0 when mexified.
Here is the assembly program:
default rel
global getSize
sys_newstat equ 106
struc STAT
.st_dev: resd 1
.st_ino: resd 1
.st_mode: resw 1
.st_nlink: resw 1
.st_uid: resw 1
.st_gid: resw 1
.st_rdev: resd 1
.st_size: resd 1
.st_blksize: resd 1
.st_blocks: resd 1
.st_atime: resd 1
.st_atime_nsec: resd 1
.st_mtime: resd 1
.st_mtime_nsec: resd 1
.st_ctime: resd 1
.st_ctime_nsec: resd 1
.unused4: resd 1
.unused5: resd 1
endstruc
%define sizeof(x) x %+ _size
section .data
fileName: db "input.xml",0
section .bss
stat: resb sizeof(STAT)
section .text
getSize:
;; Get the size of the file
mov rbx, fileName
mov rcx, stat
mov rax, sys_newstat
int 80H
mov rax, [stat + STAT.st_size]
ret
Here is the C program:
#include <stdio.h>
#include "mex.h"
extern int getSize();
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
int size = getSize();
printf("%d \n", size);
}
Here is the command I use to compile the assembly program:
nasm -felf64 -o getSize.o getSize.asm
Here is the command I use to mexify my C program:
mex main.c getSize.o
All help will be greatly appreciated. Thank You