-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArrayBitWise.asm
More file actions
103 lines (83 loc) · 2.04 KB
/
ArrayBitWise.asm
File metadata and controls
103 lines (83 loc) · 2.04 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
%macro print 2
mov rax, 1
mov rdi, 1
mov rsi, %1
mov rdx, %2
syscall
%endmacro
%macro exit 0
mov rax, 60
mov rdi, 0
syscall
%endmacro
section .data
msg: db "Array Elments: "
len: equ $-msg
space: db " "
newLine: db 10
arr: db 9,7,3,9,2,4
n: equ 6
section .bss
digit: resb 1
digitSpace resb 100
digitSpacePos resb 8
section .text
global _start
_start:
print msg,len
mov rsi,arr ;# esi holding the base Address of Array
mov rcx,n ;# edi holding count af Array Elments
;# Beginning of the Loop
begin:
;mov rax,0
mov al,byte[rsi]
push rsi
push rcx
call _printRAX
print space,1
pop rcx
pop rsi
update:
add rsi,1 ;# inc esi by 4bytes to point to next array element (arr is of type doubleword-dd)
dec rcx ;# decrement count;
jnz begin ;# id count!=0 goto 'begin'
;# End of the Loop
print newLine,1
mov rax,60
mov rdi,00
syscall
_printRAX:
mov rcx, digitSpace
mov rbx, 0
mov [rcx], rbx
inc rcx
mov [digitSpacePos], rcx
_printRAXLoop:
mov rdx, 0
mov rbx, 10
div rbx
push rax
add rdx, 48
mov rcx, [digitSpacePos]
mov [rcx], dl
inc rcx
mov [digitSpacePos], rcx
pop rax
cmp rax, 0
jne _printRAXLoop
_printRAXLoop2:
mov rcx, [digitSpacePos]
mov rax, 1
mov rdi, 1
mov rsi, rcx
mov rdx, 1
syscall
mov rcx, [digitSpacePos]
dec rcx
mov [digitSpacePos], rcx
cmp rcx, digitSpace
jge _printRAXLoop2
ret
; Note:
; Use esi and edi registers to traverse array,
; because eax and ebx registers are updated during system calls.