-
Notifications
You must be signed in to change notification settings - Fork 0
/
bin_to_hex.asm~
94 lines (83 loc) · 1.74 KB
/
bin_to_hex.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
%include "io.mac"
section .bss
length: resd 1
hexa_length: resd 1
section .data
hexa db '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
section .text
global bin_to_hex
extern printf
bin_to_hex:
;; DO NOT MODIFY
push ebp
mov ebp, esp
pusha
mov edx, [ebp + 8] ; hexa_value
mov esi, [ebp + 12] ; bin_sequence
mov ecx, [ebp + 16] ; length
;; DO NOT MODIFY
;; TODO: Implement bin to hex
start_bin_to_hex:
mov [length], ecx
xor eax, eax
xor ebx, ebx
mov ax, word[length]
mov cl, 4
div cl
mov bl, al
cmp ah, 0
je actualizare_ebx
back:
mov [hexa_length], ebx
mov ecx, [length]
xor eax, eax
loop_bintohex: ;; se extrag cate 4 biti si sunt convertiti la hexa
;; contor pentru a numara cei 4 biti
xor edi, edi
mov al, byte[esi + ecx - 1]
sub al, '0'
add edi, eax
dec ecx
cmp ecx, 0
je adaugare_ultim_caracter
mov al, byte[esi + ecx - 1]
sub al, '0'
shl al, 1
add edi, eax
dec ecx
cmp ecx, 0
je adaugare_ultim_caracter
mov al, byte[esi + ecx - 1]
sub al, '0'
shl al, 2
add edi, eax
dec ecx
cmp ecx, 0
je adaugare_ultim_caracter
mov al, byte[esi + ecx - 1]
sub al, '0'
shl al, 3
add edi, eax
dec ecx
mov al, byte[hexa + edi]
mov byte[edx + ebx], al
dec ebx
cmp ecx, 0
jg loop_bintohex
jmp end
;; END bin to hex
;; DO NOT MODIFY
adaugare_ultim_caracter:
mov al, byte[hexa + edi]
mov byte[edx + ebx], al
end:
mov ebx, [hexa_length]
inc ebx
mov byte[edx + ebx], 0x0A
popa
leave
ret
;; DO NOT MODIFY
actualizare_ebx:
dec ebx
jmp back