-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAssignment05_CMP.asm
More file actions
77 lines (58 loc) · 1.62 KB
/
Copy pathAssignment05_CMP.asm
File metadata and controls
77 lines (58 loc) · 1.62 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
; MACROS
%macro IO 4 ; Macro for Input and Output
mov rax , %1
mov rdi , %2
mov rsi , %3
mov rdx , %4
syscall
%endmacro
%macro convert 2 ; Macro for Hex to ASCII Conversion
cmp byte[%1], 9
jbe next%2
add byte[%1], 07H
next%2:
add byte[%1], 30H
%endmacro
; -----------------------------------------------
section .data
; array: dq 0x8023451234121619, 0x0214532459658452, 0x1234587965423157,0x8259631478932516, 0x8452136758963250, 0x1254698736521458, 0x6547893256987452, 0x5478963215489632, 0x3256987456321548, 0x8523697412583690
array: dq -64, -38, 66, 89, -90, 70, 33, -50, 29, 111
pos: db 0
neg: db 0
count: db 10
msg1: db 'Positive numbers:'
len1: equ $ - msg1
msg2: db 10,'Negative numbers:'
len2: equ $ - msg2
; -----------------------------------------------
section .bss
; -----------------------------------------------
section .text
global _start
_start:
mov rsi,array ; Store pointer of array's first index in rsi register
up:
mov rax, qword[rsi] ; Move content at current position of rsi in accumulator
CMP rax, 0
JGE positive ; If number is positive jump to positive label
negative: ; Else negative number
inc byte[neg]
add rsi,8
dec byte[count]
JNZ up
positive:
inc byte[pos] ; Negative Number
add rsi,8
dec byte[count]
JNZ up
jmp HtoA ; When counter hits zero, convert positive and negative counter to ASCII
HtoA:
convert pos,2
convert neg,3
IO 1, 1, msg1, len1
IO 1, 1, pos, 1
IO 1, 1, msg2,len2
IO 1, 1, neg,1
mov rax,60
mov rdi,1
syscall