-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseven.asm
146 lines (113 loc) · 2.86 KB
/
seven.asm
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
; Write X86/64 ALP to perform non-overlapped block transfer without string-specific instructions. The block containing data can be defined in the data segment.
%macro IO 4
mov rax, %1
mov rdi, %2
mov rsi, %3
mov rdx, %4
syscall
%endmacro
section .data
sourceBlock db 12h,45h,87h,24h,97h
count equ 05
space db " "
spacelen equ $ - space
msgSource db 10,"The source block contains the elements : ",10
msgSource_len equ $ - msgSource
msgDest db 10,"The destination block contains the elements : ",10
msgDest_len equ $ - msgDest
bef db 10, "Before Block Transfer : ",10
beflen equ $ - bef
aft db 10,10 ,"After Block Transfer : ",10
aftlen equ $ - aft
newLine db " ",10
nl equ $ - newLine
section .bss
destBlock resb 5
result resb 4
section .text
global _start
_start:
IO 1, 1, bef, beflen
IO 1, 1, msgSource, msgSource_len
mov rsi, sourceBlock
call printBlock
IO 1, 1, msgDest, msgDest_len
mov rsi, destBlock
call printBlock
mov rsi, sourceBlock
mov rdi, destBlock
call withStringInstruction ; change this to switch between different modes
IO 1, 1, aft, aftlen
IO 1, 1, msgSource, msgSource_len
mov rsi, sourceBlock
call printBlock
IO 1, 1, msgDest, msgDest_len
mov rsi, destBlock
call printBlock
IO 1, 1, newLine, nl
call exit
ret
withStringInstruction:
mov rcx, count
cld
rep movsb
ret
withoutString:
mov rcx, 05
again:
mov al, [rsi]
mov [rdi], al
inc rsi
inc rdi
loop again
ret
exit:
mov rax, 60
mov rdi, 0
syscall
ret
printBlock:
mov rbp, count
next:
mov al, [rsi]
push rsi
call print
pop rsi
inc rsi
dec rbp
jnz next
ret
print:
mov bl, al
mov rdi, result
mov cx, 02
repeat:
rol bl, 04
mov al, bl
and al, 0fh
cmp al, 09h
jg add37
add al, 30h
jmp skip
add37:
add al, 37h
skip:
mov [rdi], al
inc rdi
dec cx
jnz repeat
IO 1, 1, result, 4
IO 1, 1, space, spacelen
ret
; Output
; --------------------------------
; Before Block Transfer :
; The source block contains the elements :
; 12 45 87 24 97
; The destination block contains the elements :
; 00 00 00 00 00
; After Block Transfer :
; The source block contains the elements :
; 12 45 87 24 97
; The destination block contains the elements :
; 12 45 87 24 97