initial import
[staff/goc4/2018bti7061.git] / asm-5-programming / examples / jumps / jumps.asm
1 ; Executable name : jumps.asm
2 ; Version : 1.0
3 ; Created date : September 6, 2016
4 ; Last update : Sptember 6, 2016
5 ; Author : Emmanuel Benoist
6 ; Description : A simple program in assembly for demonstrating the
7 ; way jumps work
8 ;
9 ; Build using these commands:
10 ; nasm -f elf64 -g jumps.asm
11 ; ld -o jumps jumps.o
12 ; Or simply
13 ; make jumps
14 ;
15
16 SECTION .data ; Section containing initialised data
17
18
19 SECTION .bss ; Section containing uninitialized data
20 Runningsum: resq 1 ; Reserve one quadword (8bytes) for the variable
21
22 SECTION .text ; Section containing code
23
24 global _start ; Linker needs this to find the entry point!
25
26 _start:
27 nop ; This no-op keeps gdb happy...
28 mov word [Runningsum],0 ; Clear the running total
29 mov rcx, 17 ; We will loop 17 times
30 WorkLookup:
31 add word [Runningsum],3 ; Add 3 to the running total
32 dec rcx ; substract one to the counter
33 jz SomewereElse ; If the counter is zero, we are done!
34 jmp WorkLookup ; We loop otherwise
35 SomewereElse: ; End of the loop
36
37
38
39
40 ;; The Code for a clean exit of the program
41 ;; Needed to produce no error when the program is finishing
42 mov rax, 60 ; Code for exit
43 mov rdi, 0 ; Return a code of zero
44 syscall ; Make kernel call
45
46
47