initial import
[staff/goc4/2018bti7061.git] / asm-5-programming / examples / bits / bits.asm
1 ; Executable name : bits.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 bits.asm
11 ; ld -o bits bits.o
12 ; Or simply
13 ; make
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 mov AX, 0B76FH ; Initialize value of AX
28 SHL AX,1 ; Shit one bit the the left
29 ;; AX contains 6EDEh (one bit was forgotten)
30 ;; it remains in Carry Flag
31
32 mov AX, 0FFFFH ; Move a value in AX
33 RCL AX, 1 ; Rotate using Carry
34 RCL AX, 2 ; Rotate twice using Carry
35
36 mov AX, 0FFFFH ; Move a value in AX
37 ROL AX, 1 ; Rotate without Carry
38 ROL AX, 2 ; Rotate twice without Carry
39
40
41 mov RAX, 10 ; Write 0Ah into RAX
42 mov RBX, 10 ; Write 0Ah into RBX
43 mov RCX, 3 ; Write 03h into RCX
44 mov RDX, 7 ; Write 07h into RDX
45
46 mov R8, -1 ; Write a negative value in R8
47 mov R9, -10 ; Write a negative value in R9
48
49 shl RAX, 2 ; Shift two times RAX to the left
50 shl RCX, 1 ; Shift one time RCX to the left
51
52 shr RBX, 2 ; Shift two times RBX to the right
53 shr RDX, 5 ; Shift five times RDX to the right
54
55 shl R8,1 ; Shift R8 one bit to the left
56 shr R9,1 ; Shift R9 one bit to the right
57
58
59
60 ;; The Code for a clean exit of the program
61 ;; Needed to produce no error when the program is finishing
62 mov rax, 60 ; Code for exit
63 mov rdi, 0 ; Return a code of zero
64 syscall ; Make kernel call
65
66
67