initial import
[staff/goc4/2018bti7061.git] / asm-5-programming / examples / bits / bits2.asm
1 ; Executable name : bits2.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 ; bit manipulation methods in assembler
8 ;
9 ; Build using these commands:
10 ; nasm -f elf64 -g bits2.asm
11 ; ld -o bits2 bits2.o
12 ; Or simply
13 ; make bits2
14 ;
15
16 SECTION .data ; Section containing initialised data
17
18 SECTION .bss ; Section containing uninitialized data
19
20 SECTION .text ; Section containing code
21
22 global _start ; Linker needs this to find the entry point!
23
24 _start:
25 nop ; This no-op keeps gdb happy...
26
27 ;; Multiply using bit shifting
28
29 mov al,3
30 shl al,1 ; times 2
31 shl al,1 ; times 2
32 shl al,2 ; times 4
33 ;; Result: AL = 48
34
35 ;; Multiply by 3
36 mov rdx, rax ; copy the number
37 shl rdx, 1 ; multiply by two
38 add rdx, rax ; add x*2 and x
39
40 ;; Multiply by 7
41 mov rdx, rcx
42 shl rdx,2 ; edx multiplied by 4
43 add rdx, rcx ; edx is value times 5
44 add rdx, rcx ; times 6
45 add rdx, rcx ; times 7
46
47 ;; The Code for a clean exit of the program
48 ;; Needed to produce no error when the program is finishing
49 mov rax, 60 ; Code for exit
50 mov rdi, 0 ; Return a code of zero
51 syscall ; Make kernel call
52
53
54