forked from Anurag2622002/Codefornewccoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_rax.asm
More file actions
44 lines (36 loc) · 795 Bytes
/
print_rax.asm
File metadata and controls
44 lines (36 loc) · 795 Bytes
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
section .data
codes:
db '0123456789ABCDEF'
section .text
global _start
_start:
; number 1122... in hexadecimal format
mov rax, 0x1122334455667788
mov rdi, 1
mov rdx, 1
mov rcx, 64
; Each 4 bits should be output as one hexadecimal digit
; Use shift and bitwise AND to isolate them
; the result is the offset in 'codes' array
.loop:
push rax
sub rcx, 4
; cl is a register, smallest part of rcx
; rax -- eax -- ax -- ah + al
; rcx -- ecx -- cx -- ch + cl
sar rax, cl
and rax, 0xf
lea rsi, [codes + rax]
mov rax, 1
; syscall leaves rcx and r11 changed
push rcx
syscall
pop rcx
pop rax
; test can be used for the fastest 'is it a zero?' check
; see docs for 'test' command
test rcx, rcx
jnz .loop
mov rax, 60 ; invoke 'exit' system call
xor rdi, rdi
syscall