Assembly x64 Intro - Arrays
来源:互联网 发布:陕西和泰单片机 编辑:程序博客网 时间:2024/04/30 21:13
1. all1_64.asm
; call1_64.asm a basic structure for a subroutine to be called from "C"
;
; Parameter: long int *L
; Result: L[0]=L[0]+3 L[1]=L[1]+4
global call1_64 ; linker must know name of subroutine
extern printf ; the C function, to be called for demo
SECTION .data ; Data section, initialized variables
fmt1: db "rdi=%ld, L[0]=%ld", 10, 0 ; The printf format, "\n",'0'
fmt2: db "rdi=%ld, L[1]=%ld", 10, 0 ; The printf format, "\n",'0'
SECTION .bss
a: resq 1 ; temp for printing
SECTION .text ; Code section.
call1_64: ; name must appear as a nasm label
push rbp ; save rbp
mov rbp, rsp ; rbp is callers stack
push rdx ; save registers
push rdi
push rsi
mov rax,rdi ; first, only, in parameter
mov [a],rdi ; save for later use
mov rdi,fmt1 ; format for printf debug, demo
mov rsi,rax ; first parameter for printf
mov rdx,[rax] ; second parameter for printf
mov rax,0 ; no xmm registers
call printf ; Call C function
mov rax,[a] ; first, only, in parameter, demo
mov rdi,fmt2 ; format for printf
mov rsi,rax ; first parameter for printf
mov rdx,[rax+8] ; second parameter for printf
mov rax,0 ; no xmm registers
call printf ; Call C function
mov rax,[a] ; add 3 to L[0]
mov rdx,[rax] ; get L[0]
add rdx,3 ; add
mov [rax],rdx ; store sum for caller
mov rdx,[rax+8] ; get L[1]
add rdx,4 ; add
mov [rax+8],rdx ; store sum for caller
pop rsi ; restore registers
pop rdi ; in reverse order
pop rdx
mov rsp,rbp ; restore callers stack frame
pop rbp
ret ; return
2. call1_64.c
#include <stdio.h>
void call1_64(long int L[]);
int main()
{
long int L[2];
printf("test_call1_64.c using call1_64.asm\n");
L[0]=1;
L[1]=2;
printf("address of L=L[0]=%p, L[1]=%p \n", &L[0], &L[1]);
call1_64(L); // add 3 to L[0], add 4 to L[1]
printf("L[0]=%ld, L[1]=%ld \n", L[0], L[1]);
return 0;
}
3. run
address of L=L[0]=0x7fffec6057f0, L[1]=0x7fffec6057f8
rdi=0x7fffec6057f0, L[0]=1
rdi=0x7fffec6057f0, L[1]=2
L[0]=4, L[1]=6
- Assembly x64 Intro - Arrays
- Assembly x64 Intro - Nasm Example
- Assembly x64 Intro - Nasm Syntax
- Assembly x64 Intro - Arith Operate
- Assembly x64 Intro - Loop Example
- Assembly x64 Intro - Register Usage
- Assembly x64 Intro - Shift Operate
- Assembly x64 Intro - Condition Compare
- Assembly x64 Intro - Logic Operate
- Assembly x64 Intro - SSE2 Copy16Times
- Assembly x64 Intro - SSE2 Copy8Times
- Assembly x64 Intro - XMM ABS
- Assembly x64 Intro - SSE2 DCT
- Assembly x64 Intro - SSE2 IDCT
- Assembly x64 Intro - GAS Assembly Issue
- Assembly x64 Intro - call extern printf
- Assembly x64 Intro - More Types for Printf
- Assembly x64 Intro - Floating Point Operate
- Linux转发性能评估与优化-转发瓶颈分析与解决方案(补遗)
- iOS开发经验
- 架构设计(重业务:后期制作不同业务的sdk)
- UDP和TCP
- String转date sql 数据库日期查询
- Assembly x64 Intro - Arrays
- jsp 导出excel
- 导航
- node.js Buffer常用方法
- 简单分析如何使用aggregate_instance_extra_spec filter
- 跨境电商集体来莞借船出海
- Caffe安装 使用
- 获取搜索Key值
- 内存池的实现(二)