-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio.asm
83 lines (71 loc) · 1.09 KB
/
io.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
section .data
blocklen equ 16
input times blocklen db 0
output times blocklen db 0
pbyte db 0
section .text
global _start
_start:
xor r10,r10
loopy:
mov [input + r10], r10
inc r10
cmp r10, blocklen
jne loopy
mov rax, input
call printary16
call newline
mov rax, output
call printary16
call newline
mov rax, 60
mov rdi, 0
syscall ; exit(0)
;; print a 16-byte array
;; uses: all regs, [pbyte]
printary16:
mov r12, rax
xor r10, r10
printaryloop:
mov al, [r12 + r10]
call printhex
inc r10
cmp r10, blocklen
jne printaryloop
ret
;; print a single byte in hex.
;; al = byte to print
printhex:
mov r9b, al
shr al, 4
and al, 0x0f
call printhexnib
mov al, r9b
and al, 0x0f
call printhexnib
ret
;; print a single nibble in hex
;; al - nibble to print
printhexnib:
add al, '0'
cmp al, '9'
jbe digit
add al, 7 ; 'A' - '0'
digit:
mov [pbyte], al
call printchar
ret
;; print a single character
;; [pbyte] - byte to print
printchar:
mov rax, 1
mov rdi, 1
mov rsi, pbyte
mov rdx, 1
syscall
ret
;; print a newline
newline:
mov [pbyte], byte 0x0a
call printchar
ret