我试图弄清楚如何为 SPARC 程序集中的结构分配内存。
这是我正在使用的代码的 C 版本(可以正常工作和编译):
#include <stdio.h>
#include <stdlib.h>
#include "test.h"
int main(int argc, char *argv[])
{
struct tester test;
....other code inbetween
testfn(&test);
testfn2(&test);
}
现在在汇编中我想我必须调用这样的函数......
mov struct tester, %o0 ! Move struct tester into %o0
call sizeof ! Get size of struct tester
nop
set %o0, %l1 ! Store size
nop
mov 1, %o0 ! Prepare for calloc call
mov %l1, %o1 ! Prepare for calloc call
call calloc, 2
nop
mov %o0, %l2 ! The pointer returned to the allocated space
mov %l2, %o0
call testfn
nop
mov %l2, %o0
call testfn2
nop
我现在坚持的主要部分是如何将初始结构测试器测试传递给程序集。我是在某个地方定义它还是它是如何工作的?
以防万一,我的结构测试器看起来像这样......
#define SIZE 100
struct tester2 {
char abcd[SIZE];
char efgh[SIZE];
};
struct tester {
struct tester2 *somePTR;
int an_Int;
};