`
yaojingguo
  • 浏览: 208153 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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

分享到:
评论

相关推荐

    Visual C++ .NET Optimization with Assembly Code

    Chapter 3 - Developing and Using Procedures in Assembly Language Chapter 4 - Optimizing C++ Logical Structures with Assembly Language Chapter 5 - Assembly Module Interface to C++ Programs ...

    Introduction to 64Bit Windows Assembly

    Highlights of the book include doing input/output programming using Windows API functions and the C library, implementing data structures in assembly language and high performance assembly language ...

    The Art of Assembly Language Programming

    Allocating Storage for Multidimensional Arrays 5.6.2.4 - Accessing Multidimensional Array Elements in Assembly Language 5.6.3 - Structures 5.6.4 - Arrays of Structures and Arrays/Structures ...

    C Programming

    - **How Structures Work**: Explanation of how to define and use structures in C programs. - **Pointers to Structures**: How to use pointers to access and manipulate the fields of structures. - **...

    计算机组成教学课件:Chapter2 Machine Instruction.ppt

    Stacks are data structures that follow the Last-In-First-Out (LIFO) principle, useful for managing function calls and temporary data storage. Subroutines are reusable blocks of code that perform a ...

    Itanium Architecture For Programmers

    Logging in Logging out Security Text editing Uploading files Learning about commands Learning about your environment Inspecting an HP-UX or Linux file References Exercises ...

    Packt.Mastering.Csharp.and.NET.Programming

    - **Data Structures, Algorithms, and Complexity**: Introduces key concepts in algorithm design, such as complexity analysis using Big O Notation. - **Performance Approach in Common Sorting ...

    skein加密解密C源码

    Below is a list of Skein files included on the NIST submission CD, along with a very brief description of each file.... significantly using calls, at some cost in performance. skein_perf_core2.txt ...

    Essential Linux Device Drivers

    Hardware Monitoring Using LM-Sensors The Serial Peripheral Interface Bus The 1-Wire Bus Debugging Looking at the Sources Chapter 9. PCMCIA and Compact Flash What's PCMCIA/CF? Linux-PCMCIA ...

    一个win32下的ARM开源编译器

    especially important in macros and structures where register numbers may be unknown until instantiated. Both syntaxes support triple and double register operands: "add r0,r0,r1" can be shortened to ...

    OpenGL ES 3.0 Programming Guide, 2nd Edition

    OpenGL ES Shading Language: variables, types, constructors, structures, arrays, attributes, uniform blocks, I/O variables, precision qualifiers, and invariance Geometry, vertices, and primitives: ...

    CLR via C# 第4版 英文PDF

    Changing Fields in a Boxed Value Type by Using Interfaces and Why You Shouldnt Do This) 136 Object Equality and Identity 139 Object hash Codes .142 The dynamic Primitive Type ......144 Chapter 6 Type ...

    ANSYS SpaceClaim 2016 User Guide

    - **Transparency**: Makes objects partially transparent, useful for inspecting internal structures. - **Line Styles**: Modifies line styles, thickness, and colors to improve readability and aesthetics...

    二级减速器课程设计说明书reducer design specification.doc

    it can also cooperate with the requirements of the technological process in the production process of various industrial enterprises to form a rhythmic assembly line. Belt conveyor is widely used in ...

    Printed Circuits Handbook

    22.3 HDI Structures / 22.7 22.4 Design / 22.11 22.5 Dielectric Materials and Coating Methods / 22.13 22.6 HDI Manufacturing Processes / 22.26 References / 22.34 Bibliography-Additional Reading / 22.35...

Global site tag (gtag.js) - Google Analytics