1

ファイルのサイズを取得するために sys_newstat システム コールを使用する nasm でアセンブルされたオブジェクトとリンクする C プログラムを mexify しようとしています。このプログラムは、gcc でコンパイルすると正しいファイル サイズを返しますが、mex 化するとファイル サイズが 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

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);
    }

アセンブリ プログラムをコンパイルするために使用するコマンドは次のとおりです。

    nasm -felf64 -o getSize.o getSize.asm

Cプログラムをmexifyするために使用するコマンドは次のとおりです。

    mex main.c getSize.o

すべてのヘルプは大歓迎です。ありがとうございました

4

1 に答える 1