Website Summary Files Commits Branches @commit @diff @stats
path: root / demo / asm / add_answer.asm
blob: 3bcda83d6db01e66538f7883a73b6e3c34b0b625 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
global  add_answer

section .text
add_answer_2:
    push    rbp
    mov     rbp, rsp
    mov     rax, 42
    add     rax, rcx
    pop     rbp
    ret

add_answer:
    push    rbp
    mov     rbp, rsp
    push    r15
    mov     r15, rsp
    push    r9
    push    r8
    push    rcx
    push    rdx
    push    rsi
; "Handle" Win64 calling convention
;    push    rdi ; used by System V
    push    rcx ; used by Win64
    push    1
    mov     rdi, rsp

    ; Make sure that we commit the stack space we are going to use with the
    ; registers
    sub rsp, 24

    mov [rdi - 8], byte 42

    mov r8, [rdi + 8]
    mov r9, [rdi - 8]

    mov rcx, r8
    add rcx, r9

    mov [rdi - 16], rcx

    mov eax, [rdi - 16]
    mov rsp, r15
    pop r15
    pop rbp
    ret