Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #comment
- .section .bss
- .section .data
- fstring:
- .asciz "the result is %d\n"
- ##INSERT YOUR CODE HERE
- iarr:
- .int 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
- ##INSERT YOUR CODE HERE END
- .section .text
- ##INSERT YOUR CODE HERE
- #func func
- #descr: Sum via pointer in rax
- #receives: RDI Pointer = int
- #returns: RAX=int
- #fn entry (save old rbp and init new rbp with rsp)
- ##allocate memory on stack(local vars)
- #subq <numbytes>, %rsp
- #actual code
- func:
- jmp WHILE
- LOOP:
- subq $1, %r8 #schleifendurchgänge
- movq (%rdi,%r9,4),%rdx #element + itterator in rdx
- addq %rdx, %rax #ergebnis = ergebnis + element im array
- addq $1, %r9 #itterator++
- WHILE:
- cmp $0, %r8
- jne LOOP
- #fn exit (free stack (local vars), restore rpb)
- ret
- ##INSERT YOUR CODE HERE END
- .globl main #start if using gcc directly
- main: #start if using gcc directly
- ##INSERT YOUR CODE HERE
- movq $0, %rax #ergebnis return (eax)
- movq $0, %rcx #element im array
- movq $0, %r9 #itterator
- movq $10, %r8 #while schleife zähler für 10 elemente im array
- leaq iarr (,%rcx,4), %rdi #pointer auf das array
- #call of func
- call func
- ##hand over parameters via reg (order RDI, RSI, RDX, RCX, R8, R9; XMM0–7)
- ##call
- ##free stack (allocated paramters)
- #addq <numbytes>, %rsp
- ##INSERT YOUR CODE HERE END
- #call of printf
- ##hand over parameters via reg (order RDI, RSI, RDX, RCX, R8, R9; XMM0–7)
- movq %rax, %rsi
- leaq fstring, %rax
- movq %rax, %rdi
- #movq $fstring, %rdi
- movq $0, %rax #%rax holds how many xmm regs to be used in x86-64
- ##call
- call printf
- ##free stack (allocated paramters)
- #addq <numbytes>, %rsp
- #program exit via ret (if using gcc directly)
- movq $0, %rax # return 0 (success)
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement