-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringlength.asm
More file actions
76 lines (60 loc) · 1.01 KB
/
stringlength.asm
File metadata and controls
76 lines (60 loc) · 1.01 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
; nasm -f elf64 stringlength.asm -o stringlength.o
; ld stringlength.o -o stringlength
; ./stringlength
section .data
message db "Hello World",10,0
solution dq 0
section .text
global _start
_start:
mov rax, message
mov rbx, 0
_countLoop:
inc rax
inc rbx
mov cl, [rax]
cmp cl, 0
jne _countLoop
dec rbx
mov [solution], rbx
test: ; pushea en la pila el resultado
xor rcx, rcx
mov r8, 10
mov rcx, [solution]
mov rbx, 0
xor rdx, rdx
division:
mov rax, rcx
cmp rax, r8
jl aux
div r8 ; rdx resudio / rax cociente
inc rbx
push rdx
mov rcx, rax
jmp division
aux:
push rax
inc rbx
loopPrint:
cmp rbx, 0
je final
dec rbx
pop rcx
add rcx, 30H ; (+48) int to char
mov [solution], rcx
mov rax, 1
mov rdi, 1
mov rsi, solution
mov rdx, 1
syscall
jmp loopPrint
mov rax, 1
mov rdi, 1
mov rsi, rbx
mov rdx, 2
syscall
final:
; SYS_EXIT
mov rax, 60
mov rdi, 0
syscall