Using structures in assembly

main.c

#include <stdio.h>

struct S {
  short int x;
  int y;
  double z;
};

void zero_y(struct S *s_p);

int main(int argc, const char *argv[]) {
  struct S s1;
  s1.x = 1;
  s1.y = 2;
  s1.z = 1.2;

  zero_y(&s1);

  printf("S.y: %u\n", s1.y);
  return 0;
}

 

zero_y.asm

%define y_offset 4

segment .data

segment .text
  global zero_y
zero_y:
  enter 0, 0
  mov eax, [ebp+8]
  mov dword [eax+y_offset], 0
  leave 
  ret
 

 gcc -c main.c

 nasm -f elf zero_y.asm

 gcc -o zero main.o zero_y.o

你可能感兴趣的:(C++,c,gcc,F#,C#)