Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
sys_newstat不';t使用MATLAB和mex_Matlab_Assembly_Nasm_System Calls_Mex - Fatal编程技术网

sys_newstat不';t使用MATLAB和mex

sys_newstat不';t使用MATLAB和mex,matlab,assembly,nasm,system-calls,mex,Matlab,Assembly,Nasm,System Calls,Mex,我正在尝试mexify一个C程序,它与一个用nasm组装的对象链接,该对象使用sys_newstat系统调用来获取文件的大小。当使用gcc编译时,该程序返回正确的文件大小,但在mexified时仅返回0的文件大小 以下是组装程序: default rel global getSize sys_newstat equ 106 struc STAT .st_dev: resd 1 .st_ino:

我正在尝试mexify一个C程序,它与一个用nasm组装的对象链接,该对象使用sys_newstat系统调用来获取文件的大小。当使用gcc编译时,该程序返回正确的文件大小,但在mexified时仅返回0的文件大小

以下是组装程序:

    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
    nasm -felf64 -o getSize.o getSize.asm
下面是C程序:

    #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);
    }
    mex main.c getSize.o
下面是我用来编辑我的C程序的命令:

    #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);
    }
    mex main.c getSize.o
我们将非常感谢您的帮助。
谢谢

我想出来了。这就是我所做的

    default rel
    global getSize
    sys_newstat     equ 4

    struc STAT
        .st_dev:        resq 1
        .st_ino:        resq 1
        .st_nlink:      resq 1
        .st_mode:       resd 1
        .st_uid:        resd 1
        .st_gid:        resd 1
        .pad0:          resd 1
        .st_rdev:       resq 1
        .st_size:       resq 1
        .st_blksize:    resq 1
        .st_blocks:     resq 1
        .st_atime:      resq 1
        .st_atime_nsec: resq 1
        .st_mtime:      resq 1
        .st_mtime_nsec: resd 1
        .st_ctime:      resq 1
        .st_ctime_nsec: resq 1
        .unused:        resq 3
    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 rax, sys_newstat
            mov rdi, fileName
            mov rsi, stat
            syscall
            mov rax, [stat + STAT.st_size]
        ret
其他一切都一样


我从/usr/include/asm/unistd_64.h获得了系统调用信息。我从/usr/include/asm/stat.h获得了结构统计信息

我明白了。这就是我所做的

    default rel
    global getSize
    sys_newstat     equ 4

    struc STAT
        .st_dev:        resq 1
        .st_ino:        resq 1
        .st_nlink:      resq 1
        .st_mode:       resd 1
        .st_uid:        resd 1
        .st_gid:        resd 1
        .pad0:          resd 1
        .st_rdev:       resq 1
        .st_size:       resq 1
        .st_blksize:    resq 1
        .st_blocks:     resq 1
        .st_atime:      resq 1
        .st_atime_nsec: resq 1
        .st_mtime:      resq 1
        .st_mtime_nsec: resd 1
        .st_ctime:      resq 1
        .st_ctime_nsec: resq 1
        .unused:        resq 3
    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 rax, sys_newstat
            mov rdi, fileName
            mov rsi, stat
            syscall
            mov rax, [stat + STAT.st_size]
        ret
其他一切都一样


我从/usr/include/asm/unistd_64.h获得了系统调用信息。我从/usr/include/asm/stat.h获得了结构统计信息

通过谷歌搜索驻留在
中的结构,字段的大小似乎取决于平台。所以在64位Linux上,它们可能是2字节和4字节,而不是上面定义的1字节和2字节。。也许这就是问题所在?不过它在gcc中工作得很好。在64位Linux下,系统调用通常使用“syscall”指令而不是“int80h”来完成。在这种情况下,寄存器的含义不同。如果使用GCC编译程序,所有地址通常低于2GB,但在MEX文件中,地址可能高于2GB。“int 80h”可能仅适用于2GB以下的地址。要测试此行为,您应该创建一个包含汇编程序代码的动态库(.so)和一个使用此动态库的测试C程序。以下是有关在各种平台上进行系统调用的相关问题:。这个问题讨论的是
stat
struct布局:谢谢。如果没有您的帮助,我可能无法计算出来。通过谷歌搜索
中的结构,似乎字段的大小取决于平台。所以在64位Linux上,它们可能是2字节和4字节,而不是上面定义的1字节和2字节。。也许这就是问题所在?不过它在gcc中工作得很好。在64位Linux下,系统调用通常使用“syscall”指令而不是“int80h”来完成。在这种情况下,寄存器的含义不同。如果使用GCC编译程序,所有地址通常低于2GB,但在MEX文件中,地址可能高于2GB。“int 80h”可能仅适用于2GB以下的地址。要测试此行为,您应该创建一个包含汇编程序代码的动态库(.so)和一个使用此动态库的测试C程序。以下是有关在各种平台上进行系统调用的相关问题:。这个问题讨论的是
stat
struct布局:谢谢。如果没有你的帮助,我可能不会明白。